mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-08 16:39:08 +00:00
FIX: get departments and jobTitles
This commit is contained in:
@@ -103,14 +103,13 @@ export class UpdateUserRes {
|
||||
@ApiProperty()
|
||||
user: UserByCustomer;
|
||||
}
|
||||
|
||||
export class GetAllUsersByCustomerIdReq {
|
||||
@ApiPropertyOptional()
|
||||
s?: string;
|
||||
}
|
||||
export class GetAllUsersByCustomerIdRes {
|
||||
@ApiProperty({ type: [UserByCustomer] })
|
||||
users: UserByCustomer[];
|
||||
@ApiProperty()
|
||||
departments: string[];
|
||||
@ApiProperty()
|
||||
jobTitles: string[];
|
||||
}
|
||||
|
||||
export class AssignRoleToUserReq {
|
||||
@@ -153,3 +152,12 @@ export class GetAllHierarchiesRes {
|
||||
@ApiProperty({ type: [Hierarchy] })
|
||||
hierarchies: Hierarchy[];
|
||||
}
|
||||
|
||||
export class GetAllJobTitlesRes {
|
||||
@ApiProperty()
|
||||
jobTitles: string[];
|
||||
}
|
||||
export class GetAllDepartmentsRes {
|
||||
@ApiProperty()
|
||||
departments: string[];
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ import {
|
||||
CreateUserReq,
|
||||
CreateUserRes,
|
||||
DeleteUserRes,
|
||||
GetAllDepartmentsRes,
|
||||
GetAllHierarchiesRes,
|
||||
GetAllJobTitlesRes,
|
||||
GetAllUsersByCustomerIdRes,
|
||||
SetUserRolesReq,
|
||||
SetUserRolesRes,
|
||||
@@ -72,7 +74,7 @@ export class UsersController {
|
||||
async getAllUsersByCustomerId(
|
||||
@User() user: RequestUser,
|
||||
@Headers('dadosfera-lang') language,
|
||||
) {
|
||||
): Promise<GetAllUsersByCustomerIdRes> {
|
||||
this.logger.info('getAllUsersByCustomerId', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.findAllUsersByCustomerId(user.customer_id);
|
||||
@@ -90,6 +92,30 @@ export class UsersController {
|
||||
return await this.userService.getAllHierarchies();
|
||||
}
|
||||
|
||||
@Get('departments')
|
||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
||||
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
||||
async getAllDepartments(
|
||||
@User() user: RequestUser,
|
||||
@Headers('dadosfera-lang') language,
|
||||
): Promise<GetAllDepartmentsRes> {
|
||||
this.logger.info('getAllHierarchies', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.getAllDepartments(user.customer_id);
|
||||
}
|
||||
|
||||
@Get('jobTitles')
|
||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
||||
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
||||
async getAllJobTitles(
|
||||
@User() user: RequestUser,
|
||||
@Headers('dadosfera-lang') language,
|
||||
): Promise<GetAllJobTitlesRes> {
|
||||
this.logger.info('getAllHierarchies', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.getAllJobTitles(user.customer_id);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
||||
@ApiOkResponse({
|
||||
|
||||
@@ -54,7 +54,17 @@ export class UsersService implements OnModuleInit {
|
||||
this.usersClientService.UserFindAllByCustomerId({ customerId }),
|
||||
);
|
||||
this.adjustUsersPayload(users);
|
||||
return { users };
|
||||
const dintinctDepartments = [...new Set(users.map((u) => u.department))]
|
||||
.filter((value) => value != null)
|
||||
.sort();
|
||||
const dintinctJobTitles = [...new Set(users.map((u) => u.jobTitle))]
|
||||
.filter((value) => value != null)
|
||||
.sort();
|
||||
return {
|
||||
users,
|
||||
jobTitles: dintinctJobTitles,
|
||||
departments: dintinctDepartments,
|
||||
};
|
||||
}
|
||||
|
||||
async findOneById(id: string) {
|
||||
@@ -156,6 +166,18 @@ export class UsersService implements OnModuleInit {
|
||||
return { hierarchies };
|
||||
}
|
||||
|
||||
async getAllDepartments(customerId?: string) {
|
||||
return lastValueFrom(
|
||||
this.usersClientService.FindDistinctDepartments({ customerId }),
|
||||
);
|
||||
}
|
||||
|
||||
async getAllJobTitles(customerId?: string) {
|
||||
return lastValueFrom(
|
||||
this.usersClientService.FindDistinctJobTitles({ customerId }),
|
||||
);
|
||||
}
|
||||
|
||||
adjustUsersPayload(users: UserByCustomer[]) {
|
||||
users?.forEach((u) => {
|
||||
if (!u) return;
|
||||
|
||||
Reference in New Issue
Block a user