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

feat(frontend): add referrer #3636

Merged
merged 5 commits into from
Jan 27, 2025
Merged
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
Binary file modified _scripts/db/dumps/domifa_test.postgres.custom.gz
Binary file not shown.
48 changes: 14 additions & 34 deletions _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql

Large diffs are not rendered by default.

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions packages/backend/src/_common/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
//@index('./*.ts', f => `export * from '${f.path}'`)
export * from "./IsValidPasswordDecorator";
export * from "./IsValidPhoneDecorator";
export * from "./LowerCaseDecorator";
export * from "./parse-hard-reset-token.pipe";
export * from "./parse-token.pipe";
export * from "./ParseRegion.pipe";
export * from "./ParseString.pipe";
export * from "./PhoneTransformDecorator";
export * from "./StripTagsDecorator";
export * from "./TrimDecorator";
export * from "./TrimOrNullDecorator";
export * from "./UpperCaseDecorator";
export * from "./transformers";
export * from "./parse-pipes";
5 changes: 5 additions & 0 deletions packages/backend/src/_common/decorators/parse-pipes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@index('./*.ts', f => `export * from '${f.path}'`)
export * from "./parse-hard-reset-token.pipe";
export * from "./parse-token.pipe";
export * from "./ParseRegion.pipe";
export * from "./ParseString.pipe";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BadRequestException } from "@nestjs/common";
import { ParseHardResetTokenPipe } from "../parse-hard-reset-token.pipe";
import { ParseHardResetTokenPipe } from "../parse-pipes/parse-hard-reset-token.pipe";

describe("ParseHardResetTokenPipe", () => {
let pipe: ParseHardResetTokenPipe;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BadRequestException } from "@nestjs/common";
import { tokenGenerator } from "../../../util";
import { ParseTokenPipe } from "../parse-token.pipe";
import { ParseTokenPipe } from "../parse-pipes/parse-token.pipe";

describe("ParseTokenPipe", () => {
let pipe: ParseTokenPipe;
Expand Down
7 changes: 7 additions & 0 deletions packages/backend/src/_common/decorators/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@index('./*.ts', f => `export * from '${f.path}'`)
export * from "./LowerCaseDecorator";
export * from "./PhoneTransformDecorator";
export * from "./StripTagsDecorator";
export * from "./TrimDecorator";
export * from "./TrimOrNullDecorator";
export * from "./UpperCaseDecorator";
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { UserStructureProfile } from "@domifa/common";

export const VERIFIED_USERS_STRUCTURE: Pick<
UserStructureProfile,
"id" | "nom" | "prenom"
>[] = [
{
id: 1,
nom: "Martin",
prenom: "Sophie",
},
{
id: 2,
nom: "Dubois",
prenom: "Pierre",
},
{
id: 3,
nom: "Laurent",
prenom: "Marie",
},
];
3 changes: 2 additions & 1 deletion packages/backend/src/_common/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./POST_USER_STRUCTURE_BODY.mock";
export * from "./STRUCTURE_MOCK.const";
export * from "./usagers";
export * from "./POST_USER_STRUCTURE_BODY.mock";
export * from "./VERIFIED_USERS_STRUCTURE.const";
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const POST_USAGER: {
surnom: "Surnom ",
villeNaissance: "Monaco",
nationalite: null,
referrerId: null,
},
response: {
nationalite: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const CUSTOM_DOCS_LABELS: {
USAGER_NATIONALITE: "Nationalité",
USAGER_DATE_NAISSANCE: "Date naissance",
USAGER_LIEU_NAISSANCE: "Lieu naissance",
REFERENT: "Référent.e dans la structure",
AYANTS_DROITS_NOMBRE: "Nombre d'ayants-droit",
AYANTS_DROITS_LISTE:
"La liste des ayants droits avec nom prénom et date de naissance",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type StructureCustomDocKeys =
| "USAGER_NUMERO_DISTRIBUTION_SPECIALE"
| "AYANTS_DROITS_LISTE"
| "AYANTS_DROITS_NOMBRE"
| "REFERENT"
// DECISION
| "STATUT_DOM"
| "TYPE_DOM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type UsagerLight = AppEntity &
| "options"
| "historique"
| "ayantsDroits"
| "referrerId"
| "villeNaissance"
| "telephone"
| "import"
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserStructure } from "./UserStructure.type";
import { UserStructure } from "@domifa/common";

// UserStructure: attributs publics (retournés au frontend via UserStructureAuthenticated)
export type UserStructurePublic = Pick<
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/_common/model/user-structure/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./_constants";
export * from "./UserStructure.type";
export * from "./UserStructureAuthenticated.type";
export * from "./UserStructureProfile.type";
export * from "./UserStructurePublic.type";
export * from "./UserStructureSecurity.type";
export * from "./UserStructureSecurityEvent.type";
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/src/_migrations/1736291936636-auto-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { domifaConfig } from "../config";

export class AutoMigration1736291936636 implements MigrationInterface {
name = "AutoMigration1736291936636";

public async up(queryRunner: QueryRunner): Promise<void> {
if (
domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local"
) {
await queryRunner.query(`ALTER TABLE "usager" ADD "referrerId" integer`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "usager" DROP COLUMN "referrerId"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ async function createTables(queryRunner: QueryRunner) {
"numeroDistribution" text NULL,
"pinnedNote" jsonb NULL,
nationalite text NULL,
"referrerId" int4 NULL,
statut text DEFAULT 'INSTRUCTION'::text NOT NULL,
nom_prenom_surnom_ref varchar NOT NULL,
CONSTRAINT "PK_1bb36e24229bec446a281573612" PRIMARY KEY (uuid),
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/app.bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export async function bootstrapApplication(): Promise<{
stopAtFirstError: true,
enableDebugMessages: true,
disableErrorMessages: domifaConfig().envId !== "local",
transform: true,
transformOptions: {
enableImplicitConversion: false,
},
})
);

Expand Down
8 changes: 2 additions & 6 deletions packages/backend/src/auth/services/auth-checker.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { appLogger } from "../../util";
import {
UserAuthenticated,
UserProfile,
UserStructure,
} from "../../_common/model";
import { UserAuthenticated, UserProfile } from "../../_common/model";
import { DOMIFA_ADMIN_STRUCTURE_ID } from "./DOMIFA_ADMIN_STRUCTURE_ID.const";
import { UserStructureRole } from "@domifa/common";
import { UserStructure, UserStructureRole } from "@domifa/common";

export const authChecker = {
checkRole,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { domifaConfig } from "../../config";
import { userStructureRepository, structureRepository } from "../../database";
import {
CURRENT_JWT_PAYLOAD_VERSION,
UserStructure,
UserStructureAuthenticated,
UserStructureJwtPayload,
UserStructurePublic,
} from "../../_common/model";
import { isDomifaAdmin } from "./auth-checker.service";
import { StructureCommon } from "@domifa/common";
import { UserStructure, StructureCommon } from "@domifa/common";

export const APP_USER_PUBLIC_ATTRIBUTES: (keyof UserStructurePublic)[] = [
"uuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export class UsagerTable
@Column({ type: "integer", default: 0 })
public etapeDemande!: number;

@Column({ type: "integer", default: null, nullable: true })
public referrerId!: number;

@Column({ type: "jsonb", nullable: true })
public rdv!: UsagerRdv | null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserStructure } from "@domifa/common";
import { passwordGenerator } from "../../../../util";
import { userStructureRepository } from "../../user-structure";
import { passwordGenerator } from "../../../../util/encoding/passwordGenerator.service";
import { UserStructure } from "../../../../_common/model";
import { userStructureSecurityEventHistoryManager } from "./userStructureSecurityEventHistoryManager.service";
import { userStructureSecurityRepository } from "./userStructureSecurityRepository.service";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { addDays } from "date-fns";
import { domifaConfig } from "../../../../config";
import { tokenGenerator } from "../../../../util";
import {
UserStructureProfile,
UserStructureSecurity,
UserStructureTokens,
UserStructureTokenType,
} from "../../../../_common/model";
import { userStructureRepository } from "../../user-structure";
import { userStructureSecurityEventHistoryManager } from "./userStructureSecurityEventHistoryManager.service";
import { userStructureSecurityRepository } from "./userStructureSecurityRepository.service";
import { UserStructureProfile } from "@domifa/common";

export const userStructureSecurityResetPasswordInitiator = {
buildResetPasswordLink,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { passwordGenerator } from "../../../../util/encoding/passwordGenerator.service";
import {
UserStructureProfile,
UserStructureSecurity,
} from "../../../../_common/model";
import { UserStructureSecurity } from "../../../../_common/model";
import { userStructureRepository } from "../../user-structure/userStructureRepository.service";
import { userStructureSecurityEventHistoryManager } from "./userStructureSecurityEventHistoryManager.service";
import { userStructureSecurityRepository } from "./userStructureSecurityRepository.service";
import { UserStructureProfile } from "@domifa/common";

export const userStructureSecurityResetPasswordUpdater = {
checkResetPasswordToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const USAGER_LIGHT_ATTRIBUTES: (keyof Usager)[] = [
"lastInteraction",
"options",
"historique",
"referrerId",
"ayantsDroits",
//"villeNaissance",
"telephone",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { In } from "typeorm";
import { UserStructureProfile } from "../../../_common/model";
import { UserStructureTable } from "../../entities";
import { myDataSource } from "../_postgres";
import { UserStructureRole, UserStructure } from "@domifa/common";
import {
UserStructureRole,
UserStructure,
UserStructureProfile,
} from "@domifa/common";

export type AppUserForAdminEmail = Pick<
UserStructure,
Expand All @@ -12,6 +15,29 @@ export type AppUserForAdminEmail = Pick<
export const userStructureRepository = myDataSource
.getRepository(UserStructureTable)
.extend({
getVerifiedUsersByStructureId(
structureId: number
): Promise<UserStructureProfile[]> {
return userStructureRepository.find({
where: {
structureId,
},
select: {
uuid: true,
id: true,
role: true,
nom: true,
prenom: true,
email: true,
createdAt: true,
lastLogin: true,
verified: true,
},
order: {
nom: "ASC",
},
});
},
findVerifiedStructureUsersByRoles({
structureId,
roles,
Expand Down
17 changes: 1 addition & 16 deletions packages/backend/src/usagers/controllers/agenda.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import {
usagerRepository,
} from "../../database";
import { ExpressResponse } from "../../util/express";
import {
UserStructureAuthenticated,
UserStructureProfile,
} from "../../_common/model";
import { UserStructureAuthenticated } from "../../_common/model";
import { RdvDto } from "../dto/decision-form/rdv.dto";
import { UsagersService } from "../services/usagers.service";
import { getUsagerNomComplet, Usager } from "@domifa/common";
Expand All @@ -39,18 +36,6 @@ import { usagerAppointmentCreatedEmailSender } from "../../modules/mails/service
export class AgendaController {
constructor(private readonly usagersService: UsagersService) {}

@Get("users")
@ApiOperation({ summary: "Liste des utilisateurs pour l'agenda" })
@AllowUserStructureRoles("simple", "responsable", "admin")
public getAllUsersForAgenda(
@CurrentUser() currentUser: UserStructureAuthenticated
): Promise<UserStructureProfile[]> {
return userStructureRepository.findVerifiedStructureUsersByRoles({
structureId: currentUser.structureId,
roles: ["admin", "simple", "responsable"],
});
}

@Get("")
@ApiOperation({ summary: "Liste des rendez-vous à venir" })
@AllowUserStructureRoles("simple", "responsable", "admin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AppLogsService } from "../../modules/app-logs/app-logs.service";
import { domifaConfig } from "../../config";

import { UsagersFilterCriteriaStatut } from "@domifa/common";
import { userStructureRepository } from "../../database";

let lastCpuUsage = process.cpuUsage();
let lastTime = Date.now();
Expand Down Expand Up @@ -91,6 +92,9 @@ export class ExportStructureUsagersController {

const workbook = XLSX.utils.book_new();

const users = await userStructureRepository.getVerifiedUsersByStructureId(
user.structureId
);
const { firstSheetHeaders, secondSheetHeaders } =
renderStructureUsagersHeaders(user.structure);

Expand Down Expand Up @@ -128,7 +132,7 @@ export class ExportStructureUsagersController {
logProcessState(`Processing chunk (${currentRowUsagers}/${count})`);

const { firstSheetUsagers, secondSheetEntretiens } =
renderStructureUsagersRows(chunk, user.structure);
renderStructureUsagersRows(chunk, user.structure, users);

// Application du format des dates
applyDateFormat(firstSheetUsagers, [
Expand Down
Loading
Loading