Skip to content

Commit

Permalink
fix(dashboard): évalue le nombre de commentaires qui sont en fait un …
Browse files Browse the repository at this point in the history
…historique de personne suivie
  • Loading branch information
Arnaud AMBROSELLI committed Oct 2, 2023
1 parent 7d970cc commit ac8ba79
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dashboard/src/components/DataMigrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { loadingTextState } from './DataLoader';
import { looseUuidRegex } from '../utils';
import { prepareCommentForEncryption } from '../recoil/comments';
import { prepareGroupForEncryption } from '../recoil/groups';
import { capture } from '../services/sentry';

const LOADING_TEXT = 'Mise à jour des données de votre organisation…';

Expand Down Expand Up @@ -460,6 +461,49 @@ export default function useDataMigrator() {
migrationLastUpdateAt = response.organisation.migrationLastUpdateAt;
}
}

if (!organisation.migrations?.includes('evaluate-comments-in-persons-history')) {
setLoadingText(LOADING_TEXT);
const comments = await API.get({
path: '/comment',
query: { organisation: organisationId, after: 0, withDeleted: false },
}).then((res) => res.decryptedData || []);

const persons = await API.get({
path: '/person',
query: { organisation: organisationId, after: 0, withDeleted: false },
}).then((res) => res.decryptedData || []);

const personHistoryComments = comments.filter((c) => {
if (!c.comment.includes('Changement de')) return false;
if (!c.comment.includes('Avant:')) return false;
if (!c.comment.includes('Désormais:')) return false;
return true;
});

capture(
`Evaluate comments in persons history: ${organisation.name} - ${comments.length} coms - ${personHistoryComments.length} hist - ${persons.length} persons`,
{
extra: {
organisationId,
'total-comments': comments.length,
'total-history-comments': personHistoryComments.length,
'total-persons': persons.length,
'earliest-comment': personHistoryComments[personHistoryComments.length - 1]?.createdAt,
'latest-comment': personHistoryComments[0]?.createdAt,
},
}
);

const response = await API.put({
path: `/migration/evaluate-comments-in-persons-history`,
query: { migrationLastUpdateAt },
});
if (response.ok) {
setOrganisation(response.organisation);
migrationLastUpdateAt = response.organisation.migrationLastUpdateAt;
}
}
},
};
}

0 comments on commit ac8ba79

Please sign in to comment.