Skip to content

Commit

Permalink
CLEtoCLE
Browse files Browse the repository at this point in the history
  • Loading branch information
C2Chandelier committed Jan 30, 2025
1 parent 92f9c18 commit 689df1d
Show file tree
Hide file tree
Showing 24 changed files with 656 additions and 25 deletions.
1 change: 1 addition & 0 deletions apiv2/src/admin/core/sejours/jeune/Jeune.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface JeuneGateway {
create(jeune: CreateJeuneModel): Promise<JeuneModel>;
countAffectedByLigneDeBus(ligneDeBusId: string): Promise<number>;
findByClasseId(classeId: string): Promise<JeuneModel[]>;
find(query: any): Promise<JeuneModel[]>;
}

export const JeuneGateway = Symbol("JeuneGateway");
8 changes: 5 additions & 3 deletions apiv2/src/admin/core/sejours/jeune/Jeune.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ interface Referent {
role?: string;
}

interface Note {
export type NoteType = {
phase?: string;
note?: string;
referent?: Referent;
createdAt?: Date;
updatedAt?: Date;
}
};

export type JeuneModel = {
id: string;
Expand Down Expand Up @@ -168,6 +168,7 @@ export type JeuneModel = {
autresTransportsMobilite?: string;
formatMission?: string;
engagement?: string;
cniFiles?: string[];
fichiers?: {
cniFiles?: File[];
highSkilledActivityProofFiles?: File[];
Expand Down Expand Up @@ -195,7 +196,7 @@ export type JeuneModel = {
missionsInMail?: { missionId?: string; date?: Date }[];
status_equivalence?: string;
correctionRequests?: CorrectionRequest[];
notes?: Note[];
notes?: NoteType[];
hasNotes?: string;
defenseInterest?: string;
defenseTypeInterest?: string;
Expand Down Expand Up @@ -261,6 +262,7 @@ export type JeuneModel = {
departSejourMotif?: string;
departSejourMotifComment?: string;
youngPhase1Agreement: string;
cohesionStayMedicalFileReceived?: string;

// Parent 1 Information
parent1Prenom?: string;
Expand Down
4 changes: 2 additions & 2 deletions apiv2/src/admin/core/sejours/jeune/Jeune.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { JeuneGateway } from "./Jeune.gateway";

@Injectable()
export class JeuneService {
constructor(@Inject(JeuneGateway) private readonly classeGateway: JeuneGateway) {}
constructor(@Inject(JeuneGateway) private readonly jeuneGateway: JeuneGateway) {}

findAll(): Promise<JeuneModel[]> {
return this.classeGateway.findAll();
return this.jeuneGateway.findAll();
}
}
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 apiv2/src/admin/core/sejours/phase1/bascule/service/index.ts
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,
);
}
}
Loading

0 comments on commit 689df1d

Please sign in to comment.