-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/keep stats but remove user (#105)
* delete only treatments sumary * set treatmentsumary to [] * fix * delete only agent name on purge --------- Co-authored-by: Antoine Jeanneney <antoine.jeanneney@justice.fr>
- Loading branch information
1 parent
fc8db0d
commit 5ac69f1
Showing
12 changed files
with
147 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/generic/backend/src/modules/statistic/service/deleteTreatmentsSummaryBefore.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { dateBuilder, statisticModule } from '@label/core'; | ||
import { buildStatisticRepository } from '../repository'; | ||
import { deleteTreatmentsSummaryBefore } from './deleteTreatmentsSummaryBefore'; | ||
|
||
describe('deleteTreatmentsSummaryBefore', () => { | ||
const statisticRepository = buildStatisticRepository(); | ||
|
||
it('should delete all the treatments summary from statistics before the given time', async () => { | ||
const statistics = [ | ||
{ | ||
treatmentDate: dateBuilder.monthsAgo(3), | ||
}, | ||
{ | ||
treatmentDate: dateBuilder.monthsAgo(1), | ||
}, | ||
{ | ||
treatmentDate: dateBuilder.monthsAgo(2), | ||
}, | ||
].map(statisticModule.generator.generate); | ||
await Promise.all(statistics.map(statisticRepository.insert)); | ||
|
||
await deleteTreatmentsSummaryBefore({ since: 2, unit: 'MONTHS' }); | ||
|
||
const statisticsAfterDeletion = await statisticRepository.findAll(); | ||
|
||
expect(statisticsAfterDeletion[0].treatmentsSummary).toEqual([]); | ||
expect(statisticsAfterDeletion[1].treatmentsSummary).toEqual( | ||
statistics[1].treatmentsSummary, | ||
); | ||
expect(statisticsAfterDeletion[2].treatmentsSummary).toEqual([]); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/generic/backend/src/modules/statistic/service/deleteTreatmentsSummaryBefore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { dateBuilder } from '@label/core'; | ||
import { logger } from '../../../utils'; | ||
import { buildStatisticRepository } from '../repository'; | ||
|
||
export { deleteTreatmentsSummaryBefore }; | ||
|
||
async function deleteTreatmentsSummaryBefore({ | ||
since, | ||
unit, | ||
}: { | ||
since: number; | ||
unit: 'MONTHS'; | ||
}) { | ||
const statisticRepository = buildStatisticRepository(); | ||
|
||
const statisticsExpirationDate = computeExpirationDate(); | ||
const treatmentsSummaryToDeleteIds = await statisticRepository.findAllIdsBefore( | ||
statisticsExpirationDate, | ||
); | ||
|
||
const count = await statisticRepository.deleteTreatmentsSummaryByIds( | ||
treatmentsSummaryToDeleteIds, | ||
); | ||
|
||
logger.log({ | ||
operationName: 'deleteTreatmentsSummaryBefore', | ||
msg: `START: ${since} ${unit}: ${count} treatments sumary deleted`, | ||
}); | ||
|
||
function computeExpirationDate() { | ||
switch (unit) { | ||
case 'MONTHS': | ||
return dateBuilder.monthsAgo(since); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters