Skip to content

Commit 92157bd

Browse files
committed
fix(back): add currentSupervisor decorator
1 parent 01acf90 commit 92157bd

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
2+
import { UserSupervisorAuthenticated } from "../../_common/model/users/user-supervisor";
3+
4+
export const CurrentSupervisor = createParamDecorator(
5+
(_data: unknown, ctx: ExecutionContext) => {
6+
const request = ctx.switchToHttp().getRequest();
7+
return request.user as UserSupervisorAuthenticated;
8+
}
9+
);

packages/backend/src/modules/portail-admin/controllers/admin-structures-delete/admin-structures-delete.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
1515
import {
1616
AllowUserProfiles,
1717
AllowUserSupervisorRoles,
18-
CurrentUser,
1918
} from "../../../../auth/decorators";
2019
import { AppUserGuard } from "../../../../auth/guards";
2120
import { structureRepository } from "../../../../database";
@@ -30,6 +29,7 @@ import { cleanPath } from "../../../../util";
3029
import { STRUCTURE_LIGHT_ATTRIBUTES } from "../../constants/STRUCTURE_LIGHT_ATTRIBUTES.const";
3130
import { deleteStructureEmailSender } from "../../../mails/services/templates-renderers";
3231
import { UserAdminAuthenticated } from "../../../../_common/model";
32+
import { CurrentSupervisor } from "../../../../auth/decorators/current-supervisor.decorator";
3333

3434
@UseGuards(AuthGuard("jwt"), AppUserGuard)
3535
@Controller("admin/structures-delete")
@@ -52,7 +52,7 @@ export class AdminStructuresDeleteController {
5252

5353
if (structure) {
5454
return deleteStructureEmailSender.sendMail({ structure }).then(
55-
async () => {
55+
() => {
5656
return res.status(HttpStatus.OK).json({ message: "OK" });
5757
},
5858
() => {
@@ -99,7 +99,7 @@ export class AdminStructuresDeleteController {
9999
@AllowUserSupervisorRoles("super-admin-domifa")
100100
@Delete("confirm-delete-structure")
101101
public async deleteStructureConfirm(
102-
@CurrentUser() user: UserAdminAuthenticated,
102+
@CurrentSupervisor() user: UserAdminAuthenticated,
103103
@Res() res: ExpressResponse,
104104
@Body() structureConfirmationDto: StructureConfirmationDto
105105
) {

packages/backend/src/modules/portail-admin/controllers/admin-structures/admin-structures.controller.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import { SmsModule } from "../../../sms/sms.module";
1111

1212
describe("Dashboard AdminStructuresController", () => {
1313
let controller: AdminStructuresController;
14-
let appLogService: AppLogsService;
1514
let context: AppTestContext;
1615
beforeAll(async () => {
17-
appLogService = {
18-
create: jest.fn(),
19-
};
2016
context = await AppTestHelper.bootstrapTestApp({
2117
controllers: [AdminStructuresController],
2218
imports: [
@@ -26,13 +22,7 @@ describe("Dashboard AdminStructuresController", () => {
2622
forwardRef(() => InteractionsModule),
2723
forwardRef(() => SmsModule),
2824
],
29-
providers: [
30-
AdminStructuresService,
31-
{
32-
provide: AppLogsService,
33-
useValue: appLogService,
34-
},
35-
],
25+
providers: [AdminStructuresService, AppLogsService],
3626
});
3727
controller = context.module.get<AdminStructuresController>(
3828
AdminStructuresController

packages/backend/src/modules/portail-admin/controllers/admin-structures/admin-structures.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
AllowUserProfiles,
1717
AllowUserSupervisorRoles,
1818
CurrentStructure,
19-
CurrentUser,
2019
} from "../../../../auth/decorators";
2120
import { AppUserGuard, StructureAccessGuard } from "../../../../auth/guards";
2221
import {
@@ -39,6 +38,7 @@ import { userAccountActivatedEmailSender } from "../../../mails/services/templat
3938
import { structureCreatorService } from "../../../structures/services";
4039
import { format } from "date-fns";
4140
import { getBackoffTime } from "../../../users/services";
41+
import { CurrentSupervisor } from "../../../../auth/decorators/current-supervisor.decorator";
4242

4343
@UseGuards(AuthGuard("jwt"), AppUserGuard)
4444
@Controller("admin/structures")
@@ -54,7 +54,7 @@ export class AdminStructuresController {
5454

5555
@Get("export")
5656
public async export(
57-
@CurrentUser() user: UserAdminAuthenticated,
57+
@CurrentSupervisor() user: UserAdminAuthenticated,
5858
@Res() response: ExpressResponse
5959
) {
6060
await this.appLogsService.create({
@@ -90,7 +90,7 @@ export class AdminStructuresController {
9090
@Get("structure/:structureId")
9191
@UseGuards(StructureAccessGuard)
9292
public async getStructure(
93-
@CurrentUser() _user: UserAdminAuthenticated,
93+
@CurrentSupervisor() _user: UserAdminAuthenticated,
9494
@CurrentStructure() structure: Structure,
9595
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9696
@Param("structureId") _structureId: number
@@ -103,7 +103,7 @@ export class AdminStructuresController {
103103
@Get("structure/:structureId/users")
104104
@UseGuards(StructureAccessGuard)
105105
public async getUsers(
106-
@CurrentUser() _user: UserAdminAuthenticated,
106+
@CurrentSupervisor() _user: UserAdminAuthenticated,
107107
@CurrentStructure() structure: Structure,
108108
// eslint-disable-next-line @typescript-eslint/no-unused-vars
109109
@Param("structureId", new ParseIntPipe()) _structureId: number
@@ -141,7 +141,7 @@ export class AdminStructuresController {
141141

142142
@Post("confirm-structure-creation")
143143
public async confirmStructureCreation(
144-
@CurrentUser() _user: UserAdminAuthenticated,
144+
@CurrentSupervisor() _user: UserAdminAuthenticated,
145145
@Body() structureConfirmationDto: StructureConfirmationDto,
146146
@Res() res: ExpressResponse
147147
): Promise<ExpressResponse> {

packages/backend/src/modules/users/controllers/users-supervisor.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export class UsersSupervisorController {
104104
});
105105
} catch (err) {
106106
appLogger.error("Cannot reset password");
107-
throw err;
108107
}
109108

110109
return res.status(HttpStatus.OK).json({ message: "OK" });

packages/backend/src/modules/users/services/userSecurityResetPasswordInitiator.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addDays } from "date-fns";
22

3-
import { CommonUser, UserStructure } from "@domifa/common";
3+
import { CommonUser } from "@domifa/common";
44
import {
55
UserProfile,
66
UserSecurity,
@@ -50,7 +50,7 @@ async function generateResetPasswordToken({
5050
const repository = getUserRepository(userProfile);
5151
const securityRepository = getUserSecurityRepository(userProfile);
5252

53-
const user: Pick<UserStructure, "id" | "nom" | "prenom" | "email"> =
53+
const user: Pick<CommonUser, "id" | "nom" | "prenom" | "email"> =
5454
await repository.findOneByOrFail({
5555
email,
5656
});

0 commit comments

Comments
 (0)