Skip to content

Commit e24462d

Browse files
committed
fix(backend): fix reviews
1 parent 824b3d5 commit e24462d

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class ManualMigration1756117243336 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
UPDATE "app_log"
7+
SET action = CASE
8+
WHEN action = 'DOWNLOAD_IMPORT_GUIDE' THEN 'IMPORT_DOWNLOAD_GUIDE'
9+
WHEN action = 'DOWNLOAD_IMPORT_TEMPLATE' THEN 'IMPORT_TEMPLATE_DOWNLOAD'
10+
ELSE action
11+
END
12+
WHERE action IN ('DOWNLOAD_IMPORT_GUIDE', 'DOWNLOAD_IMPORT_TEMPLATE');
13+
`);
14+
}
15+
16+
public async down(queryRunner: QueryRunner): Promise<void> {
17+
await queryRunner.query(`
18+
UPDATE "app_log"
19+
SET action = CASE
20+
WHEN action = 'IMPORT_DOWNLOAD_GUIDE' THEN 'DOWNLOAD_IMPORT_GUIDE'
21+
WHEN action = 'IMPORT_TEMPLATE_DOWNLOAD' THEN 'DOWNLOAD_IMPORT_TEMPLATE'
22+
ELSE action
23+
END
24+
WHERE action IN ('IMPORT_DOWNLOAD_GUIDE', 'IMPORT_TEMPLATE_DOWNLOAD');
25+
`);
26+
}
27+
}

packages/backend/src/usagers/controllers/import/import.controller.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ describe("Import Controller", () => {
7474

7575
expect(response.status).toBe(HttpStatus.BAD_REQUEST);
7676

77-
const logs = await appLogsRepository.find({});
77+
const logs = await appLogsRepository.find({
78+
where: {
79+
userId: authInfo.id,
80+
structureId: authInfo.structureId,
81+
},
82+
});
7883
expect(logs.length).toBe(1);
7984
expect(logs[0].action).toBe("IMPORT_USAGERS_FAILED");
8085
expect(logs[0].context).toEqual({
@@ -108,7 +113,12 @@ describe("Import Controller", () => {
108113
},
109114
});
110115

111-
const logs = await appLogsRepository.find({});
116+
const logs = await appLogsRepository.find({
117+
where: {
118+
userId: authInfo.id,
119+
structureId: authInfo.structureId,
120+
},
121+
});
112122
expect(logs.length).toBe(1);
113123
expect(logs[0].action).toBe("IMPORT_USAGERS_SUCCESS");
114124
expect(logs[0].context).toEqual({
@@ -140,7 +150,12 @@ describe("Import Controller", () => {
140150
},
141151
});
142152

143-
const logs = await appLogsRepository.find({});
153+
const logs = await appLogsRepository.find({
154+
where: {
155+
userId: authInfo.id,
156+
structureId: authInfo.structureId,
157+
},
158+
});
144159
expect(logs.length).toBe(1);
145160
expect(logs[0].action).toBe("IMPORT_USAGERS_SUCCESS");
146161
expect(logs[0].context).toEqual({

packages/backend/src/usagers/controllers/import/import.controller.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,15 @@ export class ImportController {
320320
@Param("documentType", new ParseEnumPipe(ImportDocumentType))
321321
documentType: ImportDocumentType
322322
) {
323-
if (documentType === ImportDocumentType.GUIDE)
324-
await this.appLogsService.create({
325-
role: user.role,
326-
structureId: user.structureId,
327-
userId: user.id,
328-
action: "IMPORT_DOWNLOAD_GUIDE",
329-
});
330-
331-
if (documentType === ImportDocumentType.MODELE)
332-
await this.appLogsService.create({
333-
role: user.role,
334-
structureId: user.structureId,
335-
userId: user.id,
336-
action: "IMPORT_TEMPLATE_DOWNLOAD",
337-
});
323+
await this.appLogsService.create({
324+
role: user.role,
325+
structureId: user.structureId,
326+
userId: user.id,
327+
action:
328+
documentType === ImportDocumentType.GUIDE
329+
? "IMPORT_DOWNLOAD_GUIDE"
330+
: "IMPORT_TEMPLATE_DOWNLOAD",
331+
});
338332
}
339333
}
340334

0 commit comments

Comments
 (0)