-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
C2Chandelier
committed
Jan 30, 2025
1 parent
92f9c18
commit 689df1d
Showing
24 changed files
with
656 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
45 changes: 45 additions & 0 deletions
45
apiv2/src/admin/core/sejours/phase1/PlanDeTransport/PlanDeTransport.service.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,45 @@ | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
import { PlanDeTransportGateway } from "./PlanDeTransport.gateway"; | ||
import { LigneDeBusGateway } from "../ligneDeBus/LigneDeBus.gateway"; | ||
import { JeuneGateway } from "../../jeune/Jeune.gateway"; | ||
|
||
@Injectable() | ||
export class PlanDeTransportService { | ||
constructor( | ||
@Inject(PlanDeTransportGateway) | ||
@Inject(JeuneGateway) | ||
@Inject(LigneDeBusGateway) | ||
private readonly planDeTransportGateway: PlanDeTransportGateway, | ||
private readonly jeuneGateway: JeuneGateway, | ||
private readonly ligneDeBusGateway: LigneDeBusGateway, | ||
) {} | ||
|
||
async updateSeatsTakenInBusLine(busId: string) { | ||
const ligneBus = await this.ligneDeBusGateway.findById(busId); | ||
const jeuneDansLeBus = await this.jeuneGateway.find({ | ||
$and: [ | ||
{ | ||
status: "VALIDATED", | ||
ligneId: busId, | ||
}, | ||
{ | ||
$or: [ | ||
{ statusPhase1: { $in: ["AFFECTED", "DONE"] } }, | ||
{ statusPhase1Tmp: { $in: ["AFFECTED", "DONE"] } }, | ||
], | ||
}, | ||
], | ||
}); | ||
const placesPrises = jeuneDansLeBus.length; | ||
if (ligneBus.placesOccupeesJeunes !== placesPrises) { | ||
ligneBus.placesOccupeesJeunes = placesPrises; | ||
await this.ligneDeBusGateway.update(ligneBus); | ||
|
||
const planTransport = await this.planDeTransportGateway.findById(busId); | ||
planTransport.placesOccupeesJeunes = placesPrises; | ||
planTransport.lineFillingRate = | ||
planTransport.placesOccupeesJeunes && Math.floor((placesPrises / planTransport.capaciteJeunes) * 100); | ||
await this.planDeTransportGateway.update(planTransport); | ||
} | ||
} | ||
} |
Empty file.
Empty file.
167 changes: 167 additions & 0 deletions
167
apiv2/src/admin/core/sejours/phase1/bascule/service/index.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,167 @@ | ||
import { Injectable, Inject } from "@nestjs/common"; | ||
import { NoteType } from "@admin/core/sejours/jeune/Jeune.model"; | ||
import { JeuneModel } from "@admin/core/sejours/jeune/Jeune.model"; | ||
import { SessionModel } from "../../session/Session.model"; | ||
import { ClasseModel } from "@admin/core/sejours/cle/classe/Classe.model"; | ||
import { EtablissementModel } from "@admin/core/sejours/cle/etablissement/Etablissement.model"; | ||
import { ReferentModel } from "@admin/core/iam/Referent.model"; | ||
import { ReferentGateway } from "@admin/core/iam/Referent.gateway"; | ||
import { YOUNG_SOURCE, getCohortPeriod } from "snu-lib"; | ||
import { NotificationGateway } from "@notification/core/Notification.gateway"; | ||
import { | ||
EmailTemplate, | ||
jeuneBasculeCLEParams, | ||
jeuneBasculeParentNotifParams, | ||
jeuneBasculeNotifToJeune, | ||
} from "@notification/core/Notification"; | ||
import configuration from "@config/configuration"; | ||
|
||
interface generateYoungNoteForBaculeProps { | ||
jeune: JeuneModel; | ||
session: SessionModel; | ||
sessionChangeReason: string | null; | ||
previousEtablissement: EtablissementModel; | ||
previousClasse: ClasseModel; | ||
newSource: keyof typeof YOUNG_SOURCE; | ||
user: Partial<ReferentModel>; | ||
} | ||
|
||
interface generateNotificationForBasculeProsp { | ||
jeune: JeuneModel; | ||
originaleSource: keyof typeof YOUNG_SOURCE; | ||
session: SessionModel; | ||
sessionChangeReason: string; | ||
message: string; | ||
classe: ClasseModel; | ||
} | ||
|
||
@Injectable() | ||
export class BasculeService { | ||
constructor( | ||
@Inject(ReferentGateway) private readonly referentGateway: ReferentGateway, | ||
@Inject(NotificationGateway) private readonly notificationGateway: NotificationGateway, | ||
) {} | ||
generateYoungNoteForBascule({ | ||
jeune, | ||
session, | ||
sessionChangeReason, | ||
previousClasse, | ||
previousEtablissement, | ||
newSource, | ||
user, | ||
}: generateYoungNoteForBaculeProps): NoteType { | ||
const date = new Date(); | ||
const newNote = { | ||
note: ` | ||
Changement de cohorte de ${jeune.sessionNom} (${jeune.source || YOUNG_SOURCE.VOLONTAIRE}) à ${ | ||
session.nom | ||
} (${newSource})${sessionChangeReason && ` pour la raison suivante : ${sessionChangeReason}`}.\n${ | ||
previousEtablissement ? `Etablissement précédent : ${previousEtablissement.nom}.` : "" | ||
}\n${previousClasse ? `Classe précédente : ${previousClasse.uniqueKeyAndId} ${previousClasse.nom}.` : ""}\n${ | ||
jeune.centreId ? `Centre précédent : ${jeune.centreId}.` : "" | ||
}\n${jeune.sejourId ? `Session précédente : ${jeune.sejourId}.` : ""}\n${ | ||
jeune.pointDeRassemblementId ? `Point de rendez-vous précédent : ${jeune.pointDeRassemblementId}.` : "" | ||
}\n${ | ||
Object.prototype.hasOwnProperty.call(jeune, "presenceJDM") | ||
? `Présence JDM précédente : ${jeune.presenceJDM}.` | ||
: "" | ||
} | ||
`.trim(), | ||
phase: "PHASE_1", | ||
createdAt: date, | ||
updatedAt: date, | ||
referent: { | ||
_id: user.id, | ||
firstName: user.prenom, | ||
lastName: user.nom, | ||
role: user.role, | ||
}, | ||
}; | ||
return newNote; | ||
} | ||
|
||
async generateNotificationForBascule({ | ||
jeune, | ||
originaleSource, | ||
session, | ||
sessionChangeReason, | ||
message, | ||
classe, | ||
}: generateNotificationForBasculeProsp) { | ||
const config = configuration(); | ||
|
||
if (jeune.source === YOUNG_SOURCE.CLE || originaleSource === YOUNG_SOURCE.CLE) { | ||
const referentsClasse = await this.referentGateway.findByIds(classe.referentClasseIds); | ||
const emailTo = referentsClasse.map((r) => ({ name: `${r.prenom} ${r.nom}`, email: r.email })); | ||
|
||
const params = { | ||
to: emailTo, | ||
firstname: jeune.prenom || "", | ||
name: jeune.nom || "", | ||
class_name: classe.nom || "", | ||
class_code: classe.uniqueKeyAndId, | ||
cta: `${config.urls.admin}/classes/${classe.id?.toString()}`, | ||
}; | ||
|
||
// Bascule vers CLE | ||
if (jeune.source === YOUNG_SOURCE.CLE) { | ||
await this.notificationGateway.sendEmail<jeuneBasculeCLEParams>( | ||
params, | ||
EmailTemplate.JEUNE_CHANGE_SESSION_TO_CLE, | ||
); | ||
} | ||
|
||
// Bascule CLE > HTS | ||
if (jeune.source === YOUNG_SOURCE.VOLONTAIRE && originaleSource === YOUNG_SOURCE.CLE) { | ||
await this.notificationGateway.sendEmail<jeuneBasculeCLEParams>( | ||
params, | ||
EmailTemplate.JEUNE_CHANGE_SESSION_CLE_TO_HTS, | ||
); | ||
} | ||
} | ||
|
||
const emailsTo: { name: string; email: string }[] = []; | ||
if (jeune.autorisationSNUParent1 === "true") | ||
emailsTo.push({ name: `${jeune.parent1Prenom} ${jeune.parent1Nom}`, email: jeune.parent1Email || "" }); | ||
if (jeune.autorisationSNUParent2 === "true") | ||
emailsTo.push({ name: `${jeune.parent2Prenom} ${jeune.parent2Nom}`, email: jeune.parent2Email || "" }); | ||
if (emailsTo.length !== 0) { | ||
const params = { | ||
to: emailsTo, | ||
cohort: session.nom, | ||
youngFirstName: jeune.prenom || "", | ||
youngName: jeune.nom || "", | ||
cta: config.urls.app || "", | ||
}; | ||
await this.notificationGateway.sendEmail<jeuneBasculeParentNotifParams>( | ||
params, | ||
EmailTemplate.JEUNE_CHANGE_SESSION_CLE_TO_HTS, | ||
); | ||
} | ||
|
||
const sessionPeriod = getCohortPeriod({ | ||
name: session.nom, | ||
dateStart: session.dateStart, | ||
dateEnd: session.dateEnd, | ||
}); | ||
const programs = { | ||
[YOUNG_SOURCE.VOLONTAIRE]: "Volontaire hors temps scolaire (HTS)", | ||
[YOUNG_SOURCE.CLE]: "Classe engagée (CLE)", | ||
}; | ||
|
||
const params = { | ||
to: [{ name: `${jeune.prenom} ${jeune.nom}`, email: jeune.email }], | ||
motif: sessionChangeReason, | ||
message, | ||
newcohortdate: sessionPeriod, | ||
oldprogram: programs[originaleSource], | ||
newprogram: jeune.source !== originaleSource ? programs[jeune.source] : "", | ||
cta: config.urls.app || "", | ||
}; | ||
|
||
await this.notificationGateway.sendEmail<jeuneBasculeNotifToJeune>( | ||
params, | ||
EmailTemplate.JEUNE_CHANGE_SESSION_CLE_TO_HTS, | ||
); | ||
} | ||
} |
Oops, something went wrong.