Skip to content

Commit

Permalink
fix(frontend): fix checking of duplicates & add edit of structure type
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Sep 17, 2024
1 parent 13eb884 commit 123620b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export class UsagersDecisionController {
// On récupère la dernière décision
usager.decision = usager.historique[usager.historique.length - 1];
usager.statut = usager.decision.statut;
usager.options.npai = {
actif: false,
dateDebut: null,
};

usager.lastInteraction.dateInteraction = await getLastInteractionOut(
usager,
Expand Down
42 changes: 15 additions & 27 deletions packages/backend/src/usagers/controllers/usagers.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
joinSelectFields,
} from "../../database";

import { appLogger, cleanPath } from "../../util";
import { cleanPath } from "../../util";
import { dataCompare } from "../../util/dataCompare.service";
import {
UserStructureAuthenticated,
Expand Down Expand Up @@ -169,8 +169,8 @@ export class UsagersController {
.getRawMany();
}

@AllowUserStructureRoles("simple", "responsable", "admin")
@Post()
@AllowUserStructureRoles("simple", "responsable", "admin")
public createUsager(
@Body() usagerDto: CreateUsagerDto,
@CurrentUser() user: UserStructureAuthenticated
Expand Down Expand Up @@ -327,23 +327,21 @@ export class UsagersController {
@Body() duplicateUsagerDto: CheckDuplicateUsagerDto,
@CurrentUser() user: UserStructureAuthenticated
): Promise<Usager[]> {
let query = `SELECT nom, prenom, ref, "dateNaissance" FROM usager WHERE "structureId" = $1 and LOWER("nom") = $2 and LOWER("prenom") = $3`;

const params = [
user.structureId,
duplicateUsagerDto.nom,
duplicateUsagerDto.prenom,
];

if (duplicateUsagerDto.usagerRef) {
query = query + ` and "ref" != $4`;
params.push(duplicateUsagerDto.usagerRef);
}

return usagerRepository.query(query, params);
return usagerRepository
.createQueryBuilder()
.select(["nom", "prenom", "ref", "dateNaissance"])
.where(
`"structureId" = :structureId and LOWER("nom") = :nom and LOWER("prenom") = :prenom`,
{
structureId: user.structureId,
nom: duplicateUsagerDto.nom,
prenom: duplicateUsagerDto.prenom,
}
)
.getRawMany();
}

@UseGuards(AuthGuard("jwt"), AppUserGuard, UsagerAccessGuard)
@UseGuards(UsagerAccessGuard)
@AllowUserStructureRoles("responsable", "admin")
@Delete(":usagerRef")
public async delete(
Expand Down Expand Up @@ -416,16 +414,6 @@ export class UsagersController {
const buffer = await pdftk.input(filePath).fillForm(pdfInfos).output();
return res.setHeader("content-type", "application/pdf").send(buffer);
} catch (err) {
appLogger.error(
`CERFA ERROR structure : ${user.structureId} / usager :${currentUsager.ref} `,
{
sentry: true,
error: err,
context: {
...pdfInfos,
},
}
);
return res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.json({ message: "CERFA_ERROR" });
Expand Down
15 changes: 1 addition & 14 deletions packages/backend/src/usagers/dto/check-duplicate-usager.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { ApiProperty } from "@nestjs/swagger";
import {
IsNotEmpty,
IsNumber,
IsString,
MaxLength,
IsOptional,
} from "class-validator";
import { IsNotEmpty, IsString, MaxLength } from "class-validator";

import {
LowerCaseTransform,
Expand Down Expand Up @@ -36,11 +30,4 @@ export class CheckDuplicateUsagerDto {
@StripTagsTransform()
@LowerCaseTransform()
public prenom!: string;

@ApiProperty({
required: false,
})
@IsOptional()
@IsNumber()
public usagerRef!: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="title">Modifier les informations de votre structure</h2>
<span class="fw-bold text-danger">*</span> sont obligatoires
</p>

<div class="row" *ngIf="structure.structureType !== 'asso'">
<div class="row">
<div class="col-12 col-md-12 form-group required">
<fieldset class="text-center">
<legend>Vous appartenez à quel type de structure</legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,21 @@ export class StepEtatCivilComponent
const params: {
nom: string;
prenom: string;
usagerRef: number | null;
} = {
nom: this.usagerForm.controls.nom.value,
prenom: this.usagerForm.controls.prenom.value,
usagerRef: this.usager.ref ?? null,
};

this.subscription.add(
this.usagerDossierService
.isDuplicateName(params)
.subscribe((duplicates: UsagerLight[]) => {
this.duplicates = duplicates;
this.duplicates = duplicates ?? [];
if (this.usager?.ref && this.duplicates.length) {
this.duplicates.filter(
(usager) => this.usager.ref !== usager.ref
);
}
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export class UsagerDossierService {
public isDuplicateName(params: {
nom: string;
prenom: string;
usagerRef: number | null;
}) {
}): Observable<UsagerLight[]> {
return this.http.post<UsagerLight[]>(
`${this.endPointUsagers}/check-duplicates-name`,
params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h2>Transfert de courrier</h2>
</div>

<form
*ngIf="isFormVisible"
*ngIf="isFormVisible && transfertForm"
[formGroup]="transfertForm"
(ngSubmit)="editTransfert()"
autocomplete="off"
Expand Down

0 comments on commit 123620b

Please sign in to comment.