Skip to content

Commit

Permalink
feat: lbac 2368: anonymisation des rdvs (#1406)
Browse files Browse the repository at this point in the history
* feat: lbac 2368: anonymisation des rdvs

* fix: renommage fichier
  • Loading branch information
remy-auricoste authored Aug 8, 2024
1 parent c571e29 commit 14c7ac3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Filter } from "mongodb"
import { IAppointment } from "shared/models"

import { logger } from "../../common/logger"
import { getDbCollection } from "../../common/utils/mongodbUtils"
import { notifyToSlack } from "../../common/utils/slackUtils"

const anonymizeAppointments = async () => {
export const anonymizeAppointments = async (filter: Filter<IAppointment>) => {
logger.info(`Début anonymisation`)

const lastYear = new Date()
lastYear.setFullYear(lastYear.getFullYear() - 1)

await getDbCollection("appointments")
.aggregate([
{
$match: { created_at: { $lte: lastYear } },
$match: filter,
},
{
$project: {
Expand All @@ -32,7 +32,7 @@ const anonymizeAppointments = async () => {
])
.toArray()

const res = await getDbCollection("appointments").deleteMany({ created_at: { $lte: lastYear } })
const res = await getDbCollection("appointments").deleteMany(filter)

return res.deletedCount
}
Expand All @@ -41,7 +41,9 @@ export const anonymizeOldAppointments = async function () {
try {
logger.info(" -- Anonymisation des appointments de plus de un (1) an -- ")

const anonymizedAppointmentCount = await anonymizeAppointments()
const lastYear = new Date()
lastYear.setFullYear(lastYear.getFullYear() - 1)
const anonymizedAppointmentCount = await anonymizeAppointments({ created_at: { $lte: lastYear } })

logger.info(`Fin traitement ${anonymizedAppointmentCount}`)

Expand Down
8 changes: 7 additions & 1 deletion server/src/jobs/anonymization/anonymizeIndividual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getDbCollection } from "@/common/utils/mongodbUtils"

import { logger } from "../../common/logger"

import { anonymizeAppointments } from "./anonymizeAppointments"

const anonimizeUserWithAccount = (_id: ObjectId) =>
getDbCollection("userswithaccounts")
.aggregate([
Expand Down Expand Up @@ -137,8 +139,12 @@ export async function anonymizeIndividual({ collection, id }: { collection: stri
await anonymizeUserWithAccountAndRecruiter(id)
break
}
default:
case "appointments": {
await anonymizeAppointments({ _id: id })
break
}
default:
throw new Error(`collection ${collection} unsupported`)
}
}
export default anonymizeIndividual
2 changes: 1 addition & 1 deletion server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { create as createMigration, status as statusMigration, up as upMigration

import { getLoggerWithContext } from "../common/logger"

import anonymizeOldAppointments from "./anonymization/anonumizeAppointments"
import anonymizeOldAppointments from "./anonymization/anonymizeAppointments"
import anonymizeIndividual from "./anonymization/anonymizeIndividual"
import anonymizeOldApplications from "./anonymization/anonymizeOldApplications"
import { anonimizeUsers } from "./anonymization/anonymizeUserRecruteurs"
Expand Down

0 comments on commit 14c7ac3

Please sign in to comment.