Skip to content

Commit

Permalink
fix: remove migration on obs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Jan 10, 2024
1 parent e1088e3 commit ac92226
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions dashboard/src/components/DataMigrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,43 @@ export default function useDataMigrator() {
}
// End of example of migration.
*/
if (!organisation.migrations?.includes('reformat-observedAt-observations')) {
// some observedAt are timestamp, some are date
// it messes up the filtering by date in stats
setLoadingText(LOADING_TEXT);
const observationsRes = await API.get({
path: '/territory-observation',
query: { organisation: organisationId, after: 0, withDeleted: false },
}).then((res) => res.decryptedData || []);
// if (!organisation.migrations?.includes('reformat-observedAt-observations')) {
// // some observedAt are timestamp, some are date
// // it messes up the filtering by date in stats
// setLoadingText(LOADING_TEXT);
// const observationsRes = await API.get({
// path: '/territory-observation',
// query: { organisation: organisationId, after: 0, withDeleted: false },
// }).then((res) => res.decryptedData || []);

const newObservations = observationsRes.map((obs) => {
const observedAt = !isNaN(Number(obs.observedAt)) // i.e. is timestamp
? dayjsInstance(Number(obs.observedAt)).toISOString()
: dayjsInstance(obs.observedAt ?? obs.createdAt).toISOString();
return {
...obs,
user: obs.user ?? user._id, // in case of old observations missing user
observedAt,
};
});
// const newObservations = observationsRes.map((obs) => {
// const observedAt = !isNaN(Number(obs.observedAt)) // i.e. is timestamp
// ? dayjsInstance(Number(obs.observedAt)).toISOString()
// : dayjsInstance(obs.observedAt ?? obs.createdAt).toISOString();
// return {
// ...obs,
// user: obs.user ?? user._id, // in case of old observations missing user
// observedAt,
// };
// });

const observationIdsToDelete = newObservations.filter((obs) => !obs.territory || !obs.team).map((obs) => obs._id);
const observationsWithFullData = newObservations.filter((obs) => !!obs.territory && !!obs.team);
// const observationIdsToDelete = newObservations.filter((obs) => !obs.territory || !obs.team).map((obs) => obs._id);
// const observationsWithFullData = newObservations.filter((obs) => !!obs.territory && !!obs.team);

const encryptedObservations = await Promise.all(observationsWithFullData.map(prepareObsForEncryption(customFieldsObs)).map(encryptItem));
// const encryptedObservations = await Promise.all(observationsWithFullData.map(prepareObsForEncryption(customFieldsObs)).map(encryptItem));

const response = await API.put({
path: `/migration/reformat-observedAt-observations`,
body: { encryptedObservations, observationIdsToDelete },
query: { migrationLastUpdateAt },
});
if (response.ok) {
setOrganisation(response.organisation);
migrationLastUpdateAt = response.organisation.migrationLastUpdateAt;
} else {
return false;
}
}
// const response = await API.put({
// path: `/migration/reformat-observedAt-observations`,
// body: { encryptedObservations, observationIdsToDelete },
// query: { migrationLastUpdateAt },
// });
// if (response.ok) {
// setOrganisation(response.organisation);
// migrationLastUpdateAt = response.organisation.migrationLastUpdateAt;
// } else {
// return false;
// }
// }
return true;
},
};
Expand Down

0 comments on commit ac92226

Please sign in to comment.