Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi compte v2 #746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IAppointment } from "shared"
import { AppointmentUserType } from "shared/constants/appointment"

import { model, Schema } from "../../../mongodb"
import { mongoosePagination, Pagination } from "../_shared/mongoose-paginate"
Expand Down Expand Up @@ -152,6 +153,12 @@ export const appointmentSchema = new Schema<IAppointment>(
default: false,
description: "Si l'enregistrement est anonymisé",
},
applicant_user_type: {
type: String,
enum: [...Object.values(AppointmentUserType), null],
default: null,
description: "Role du demandeur : parent ou etudiant",
},
},
{
versionKey: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mongoose, { Schema } from "mongoose"

import { mongoosePagination, Pagination } from "../_shared/mongoose-paginate"

const { model } = mongoose

export const buildMongooseModel = <T>(schema: Schema<T>, tableName: string) => {
schema.plugin(mongoosePagination)

return model<T, Pagination<T>>(tableName, schema)
}
46 changes: 46 additions & 0 deletions server/src/common/model/schema/multiCompte/cfa.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ICFA } from "shared/models/cfa.model.js"

import { Schema } from "../../../mongodb.js"

import { buildMongooseModel } from "./buildMongooseModel.js"

const cfaSchema = new Schema<ICFA>(
{
establishment_siret: {
type: String,
description: "Siret de l'établissement",
},
establishment_raison_sociale: {
type: String,
description: "Raison social de l'établissement",
},
establishment_enseigne: {
type: String,
default: null,
description: "Enseigne de l'établissement",
},
address_detail: {
type: Object,
description: "Detail de l'adresse de l'établissement",
},
address: {
type: String,
description: "Adresse de l'établissement",
},
geo_coordinates: {
type: String,
default: null,
description: "Latitude/Longitude de l'adresse de l'entreprise",
},
origin: {
type: String,
description: "Origine de la creation (ex: Campagne mail, lien web, etc...) pour suivi",
},
},
{
timestamps: true,
versionKey: false,
}
)

export const cfaRepository = buildMongooseModel(cfaSchema, "cfa")
58 changes: 58 additions & 0 deletions server/src/common/model/schema/multiCompte/entreprise.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { IEntreprise } from "shared/models/entreprise.model.js"

import { Schema } from "../../../mongodb.js"

import { buildMongooseModel } from "./buildMongooseModel.js"

const entrepriseSchema = new Schema<IEntreprise>(
{
establishment_siret: {
type: String,
description: "Siret de l'établissement",
},
opco: {
type: String,
default: null,
description: "Information sur l'opco de l'entreprise",
},
idcc: {
type: String,
description: "Identifiant convention collective de l'entreprise",
},
establishment_raison_sociale: {
type: String,
description: "Raison social de l'établissement",
},
establishment_enseigne: {
type: String,
default: null,
description: "Enseigne de l'établissement",
},
address_detail: {
type: Object,
description: "Detail de l'adresse de l'établissement",
},
address: {
type: String,
description: "Adresse de l'établissement",
},
geo_coordinates: {
type: String,
default: null,
description: "Latitude/Longitude de l'adresse de l'entreprise",
},
establishment_id: {
type: String,
description: "Si l'utilisateur est une entreprise, l'objet doit contenir un identifiant de formulaire unique",
},
origin: {
type: String,
description: "Origine de la creation de l'utilisateur (ex: Campagne mail, lien web, etc...) pour suivi",
},
},
{
timestamps: true,
}
)

export const entrepriseRepository = buildMongooseModel(entrepriseSchema, "entreprise")
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { AccessEntityType, AccessStatus, IRoleManagement, IRoleManagementEvent } from "shared/models/roleManagement.model.js"

import { VALIDATION_UTILISATEUR } from "../../../../services/constant.service.js"
import { Schema } from "../../../mongodb.js"

import { buildMongooseModel } from "./buildMongooseModel.js"

const roleManagementEventSchema = new Schema<IRoleManagementEvent>(
{
validation_type: {
type: String,
enum: Object.values(VALIDATION_UTILISATEUR),
description: "Indique si l'action est ordonnée par un utilisateur ou le serveur",
},
status: {
type: String,
enum: Object.values(AccessStatus),
description: "Statut de l'utilisateur",
},
reason: {
type: String,
description: "Raison du changement de statut",
},
granted_by: {
type: String,
default: null,
description: "Utilisateur à l'origine du changement",
},
date: {
type: Date,
default: () => new Date(),
description: "Date de l'évènement",
},
},
{ _id: false }
)

const roleManagementSchema = new Schema<IRoleManagement>(
{
accessor_id: {
type: String,
description: "ID de l'entité ayant accès",
},
accessor_type: {
type: String,
enum: Object.values(AccessEntityType),
description: "Type de l'entité ayant accès",
},
accessed_id: {
type: String,
description: "ID de l'entité sur laquelle l'accès est exercé",
},
accessed_type: {
type: String,
enum: Object.values(AccessEntityType),
description: "Type de l'entité sur laquelle l'accès est exercé",
},
history: {
type: [roleManagementEventSchema],
description: "Evénements liés au cycle de vie de l'accès",
},
origin: {
type: String,
description: "Origine de la creation",
},
},
{
timestamps: true,
}
)

export const roleManagementRepository = buildMongooseModel(roleManagementSchema, "roleManagement")
84 changes: 84 additions & 0 deletions server/src/common/model/schema/multiCompte/user2.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { IUser2, IUserStatusEvent, UserEventType } from "shared/models/user2.model.js"

import { VALIDATION_UTILISATEUR } from "../../../../services/constant.service.js"
import { Schema } from "../../../mongodb.js"

import { buildMongooseModel } from "./buildMongooseModel.js"

const userStatusEventSchema = new Schema<IUserStatusEvent>(
{
validation_type: {
type: String,
enum: Object.values(VALIDATION_UTILISATEUR),
description: "Indique si l'action est ordonnée par un utilisateur ou le serveur",
},
status: {
type: String,
enum: Object.values(UserEventType),
description: "Statut de l'utilisateur",
},
reason: {
type: String,
description: "Raison du changement de statut",
},
granted_by: {
type: String,
default: null,
description: "Utilisateur à l'origine du changement",
},
date: {
type: Date,
default: () => new Date(),
description: "Date de l'évènement",
},
},
{ _id: false }
)

const User2Schema = new Schema<IUser2>(
{
firstname: {
type: String,
default: null,
description: "Le prénom",
},
lastname: {
type: String,
default: null,
description: "Le nom",
},
phone: {
type: String,
default: null,
description: "Le numéro de téléphone",
},
email: {
type: String,
default: null,
description: "L'email",
},
last_connection: {
type: Date,
default: null,
description: "Date de dernière connexion",
},
is_anonymized: {
type: Boolean,
default: false,
description: "Si l'enregistrement est anonymisé",
},
history: {
type: [userStatusEventSchema],
description: "Evénements liés au cycle de vie de l'utilisateur",
},
origin: {
type: String,
description: "Origine de la creation de l'utilisateur (ex: Campagne mail, lien web, etc...) pour suivi",
},
},
{
timestamps: true,
}
)

export const user2Repository = buildMongooseModel(User2Schema, "user2")
2 changes: 1 addition & 1 deletion server/src/common/model/schema/user/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const userSchema = new Schema<IUser>(
role: {
type: String,
default: null,
description: "candidat | cfa | administrator",
description: "candidat | administrator",
},
last_action_date: {
type: Date,
Expand Down
7 changes: 7 additions & 0 deletions server/src/common/utils/asyncUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export const asyncForEach = async <T>(array: T[], callback: (item: T, index: num
}
}

export const asyncForEachGrouped = async <T>(array: T[], groupSize: number, callback: (item: T, index: number) => Promise<void>) => {
for (let index = 0; index < array.length; index += groupSize) {
const group = array.slice(index, index + groupSize)
await Promise.all(group.map((item, itemIndex) => callback(item, index + itemIndex)))
}
}

export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

export function timeout(promise, millis) {
Expand Down
12 changes: 12 additions & 0 deletions server/src/common/utils/enumUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const parseEnum = <T extends string>(enumObj: Record<string, T>, value: string | null): T | null => {
return Object.values(enumObj).find((enumValue) => enumValue.toLowerCase() === value?.toLowerCase()) ?? null
}
export const isEnum = <T extends string>(enumValues: Record<string, T>, value: unknown): value is T => typeof value === "string" && parseEnum(enumValues, value) !== null

export const parseEnumOrError = <T extends string>(enumObj: Record<string, T>, value: string | null): T => {
const enumValue = parseEnum(enumObj, value)
if (enumValue === null) {
throw new Error(`could not parse ${value} as enum ${JSON.stringify(Object.values(enumObj))}`)
}
return enumValue
}
Loading
Loading