-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: validate models * fix: appointment route & user update * fix: model * feat: recovery script * fix: remove comment * feat: add comment to siret
- Loading branch information
Showing
16 changed files
with
116 additions
and
35 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
4 changes: 2 additions & 2 deletions
4
server/src/common/model/schema/emailBlacklist/emailBlacklist.schema.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
7 changes: 0 additions & 7 deletions
7
server/src/common/model/schema/emailBlacklist/emailBlacklist.types.ts
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import dayjs from "shared/helpers/dayjs" | ||
|
||
import { EmailBlacklist, Etablissement } from "../../../common/model" | ||
|
||
// SIRET number that does not comply with LUHN algorythm in etablissements collection | ||
const SIRET_TO_REMOVE_FROM_ETABLISSEMENT = [ | ||
"13002799900132", | ||
"99999999999920", | ||
"78144401300000", | ||
"33778063900000", | ||
"78151651300000", | ||
"19331424200000", | ||
"19330028200000", | ||
"19470020900017", | ||
"52407208900175", | ||
] | ||
|
||
const DATE = dayjs().toDate() | ||
|
||
const removeObsoleteEtablissement = async () => await Etablissement.deleteMany({ formateur_siret: { $in: SIRET_TO_REMOVE_FROM_ETABLISSEMENT } }) | ||
const addMissingDateFieldToEmailBlacklist = async () => await EmailBlacklist.updateMany({ created_at: { $exists: false } }, { $set: { created_at: DATE } }) | ||
|
||
export const fixRDVACollections = async () => { | ||
await removeObsoleteEtablissement() | ||
await addMissingDateFieldToEmailBlacklist() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IUser } from "shared" | ||
|
||
import { logger } from "../../../common/logger" | ||
import { Appointment, User } from "../../../common/model" | ||
|
||
const findDuplicates = (users) => { | ||
const emailMap: { [key: string]: IUser[] } = {} | ||
|
||
users.forEach((user) => { | ||
const { email } = user | ||
|
||
if (!emailMap[email]) { | ||
emailMap[email] = [user] | ||
} else { | ||
emailMap[email].push(user) | ||
} | ||
}) | ||
|
||
const duplicateGroups = Object.values(emailMap) | ||
.filter((group) => group.length > 1) | ||
.map((group) => group.sort((a, b) => new Date(b.last_action_date).getTime() - new Date(a.last_action_date).getTime())) | ||
|
||
return duplicateGroups | ||
} | ||
|
||
export const fixDuplicateUsers = async () => { | ||
logger.info(`Start user deduplication`) | ||
const users = await User.find({}).lean() | ||
const duplicates: Iterable<IUser[]> = findDuplicates(users) | ||
|
||
for await (const groupOfUsers of duplicates) { | ||
const userToKeep = groupOfUsers.shift() | ||
for await (const group of groupOfUsers) { | ||
await Appointment.updateMany({ applicant_id: group._id.toString() }, { $set: { applicant_id: userToKeep?._id.toString() } }) | ||
await User.findByIdAndDelete(group._id) | ||
} | ||
} | ||
logger.info(`End user deduplication`) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Jsonify } from "type-fest" | ||
|
||
import { z } from "../helpers/zodWithOpenApi" | ||
|
||
import { zObjectId } from "./common" | ||
|
||
export const ZEmailBlacklist = z | ||
.object({ | ||
_id: zObjectId, | ||
email: z.string(), | ||
blacklisting_origin: z.string(), | ||
created_at: z.coerce.date(), | ||
}) | ||
.strict() | ||
|
||
export type IEmailBlacklist = z.output<typeof ZEmailBlacklist> | ||
export type IEmailBlacklistJson = Jsonify<z.input<typeof ZEmailBlacklist>> |
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