Skip to content

Commit

Permalink
fix: clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Oct 6, 2023
1 parent 341c3ed commit 20e9ba0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
22 changes: 10 additions & 12 deletions api/src/controllers/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ router.get(
passport.authenticate("user", { session: false }),
validateUser(["superadmin", "admin", "normal", "restricted-access"]),
catchErrors(async (req, res, next) => {
const startLoadingDate = Date.now();

try {
z.object({
organisation: z.string().regex(looseUuidRegex),
Expand Down Expand Up @@ -77,28 +75,28 @@ router.get(
// Medical data is never saved in cache so we always have to download all at every page reload.
// In other words "after" param is intentionnaly ignored for consultations, treatments and medical files.
const medicalDataQuery =
withAllMedicalData !== "true" ? query : { where: { organisation: req.query.organisation }, paranoid: withDeleted === "true" };
withAllMedicalData !== "true" ? query : { where: { organisation: req.query.organisation }, paranoid: withDeleted === "true" ? false : true };
const consultations = await Consultation.count(medicalDataQuery);
const medicalFiles = await MedicalFile.count(medicalDataQuery);
const treatments = await Treatment.count(medicalDataQuery);

return res.status(200).send({
ok: true,
data: {
actions,
consultations,
treatments,
comments,
passages,
rencontres,
medicalFiles,
persons,
groups,
reports,
passages,
rencontres,
actions,
territories,
places,
relsPersonPlace,
territories,
territoryObservations,
reports,
comments,
consultations,
treatments,
medicalFiles,
},
});
})
Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/components/DataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export default function DataLoader() {
const progress = useRecoilValue(progressState);
const total = useRecoilValue(totalState);

console.log(loadingText, 'progress', progress, 'total', total, '%', progress / total);

if (!isLoading) return <RandomPicturePreloader />;
if (!total && !fullScreen) return null;

Expand Down Expand Up @@ -158,7 +156,7 @@ export function useDataLoader(options = { refreshOnMount: false }) {
setOrganisation(latestOrganisation);
setUser(latestUser);
if (isStartingInitialLoad) {
await migrateData();
await migrateData(latestOrganisation);
}

const statsResponse = await API.get({
Expand Down
9 changes: 4 additions & 5 deletions dashboard/src/components/DataMigrator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { mappedIdsToLabels, prepareActionForEncryption } from '../recoil/actions';
import { organisationState, userState } from '../recoil/auth';
import { usePreparePersonForEncryption } from '../recoil/persons';
Expand All @@ -17,16 +17,15 @@ const LOADING_TEXT = 'Mise à jour des données de votre organisation…';
export default function useDataMigrator() {
const setLoadingText = useSetRecoilState(loadingTextState);
const user = useRecoilValue(userState);
const [organisation, setOrganisation] = useRecoilState(organisationState);

const organisationId = organisation?._id;
const setOrganisation = useSetRecoilState(organisationState);

const preparePersonForEncryption = usePreparePersonForEncryption();

return {
// One "if" for each migration.
// `migrationLastUpdateAt` should be set after each migration and send in every PUT/POST/PATCH request to server.
migrateData: async () => {
migrateData: async (organisation) => {
const organisationId = organisation?._id;
let migrationLastUpdateAt = organisation.migrationLastUpdateAt;
/*
// Example of migration:
Expand Down

0 comments on commit 20e9ba0

Please sign in to comment.