mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-24 22:09:08 +00:00
FEAT: Roles WIP
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
||||
import { Role } from 'src/modules/roles/dto/entities';
|
||||
export class Customer {
|
||||
@ApiProperty()
|
||||
@@ -26,35 +26,13 @@ export class User {
|
||||
@ApiProperty({ type: [Role] })
|
||||
roles: Role[];
|
||||
@ApiProperty()
|
||||
jobTitle: string;
|
||||
jobTitle?: string;
|
||||
@ApiProperty()
|
||||
department: string;
|
||||
department?: string;
|
||||
@ApiProperty()
|
||||
hierarchy: string;
|
||||
@ApiProperty()
|
||||
customer: Customer;
|
||||
@ApiProperty()
|
||||
mfaStatus: string;
|
||||
@ApiProperty()
|
||||
createdAt: string;
|
||||
@ApiProperty()
|
||||
updatedAt: string;
|
||||
}
|
||||
export class UserWithoutRoles {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
email: string;
|
||||
@ApiProperty()
|
||||
jobTitle: string;
|
||||
@ApiProperty()
|
||||
department: string;
|
||||
@ApiProperty()
|
||||
hierarchy: string;
|
||||
@ApiProperty()
|
||||
customer: Customer;
|
||||
hierarchy?: string;
|
||||
@ApiPropertyOptional()
|
||||
customer?: Customer;
|
||||
@ApiProperty()
|
||||
mfaStatus: string;
|
||||
@ApiProperty()
|
||||
@@ -62,6 +40,10 @@ export class UserWithoutRoles {
|
||||
@ApiProperty()
|
||||
updatedAt: string;
|
||||
}
|
||||
export class UserNoRoles extends OmitType(User, ['roles']) {}
|
||||
export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [
|
||||
'customer',
|
||||
]) {}
|
||||
export class UserByCustomer {
|
||||
@ApiProperty({ type: [Role] })
|
||||
roles: Role[];
|
||||
@@ -80,17 +62,17 @@ export class UserByCustomer {
|
||||
}
|
||||
export class CreateUserReq {
|
||||
@ApiPropertyOptional()
|
||||
name: string;
|
||||
name?: string;
|
||||
@ApiProperty()
|
||||
email: string;
|
||||
@ApiPropertyOptional()
|
||||
roles: string[];
|
||||
roles?: string[];
|
||||
@ApiPropertyOptional()
|
||||
jobTitle: string;
|
||||
jobTitle?: string;
|
||||
@ApiPropertyOptional()
|
||||
department: string;
|
||||
department?: string;
|
||||
@ApiPropertyOptional()
|
||||
hierarchy: string;
|
||||
hierarchy?: string;
|
||||
}
|
||||
export class CreateUserRes {
|
||||
@ApiProperty()
|
||||
@@ -107,7 +89,7 @@ export class BatchCreateUserRes {
|
||||
|
||||
export class GetAllUsersByCustomerIdReq {
|
||||
@ApiPropertyOptional()
|
||||
s: string;
|
||||
s?: string;
|
||||
}
|
||||
export class GetAllUsersByCustomerIdRes {
|
||||
@ApiProperty({ type: [UserByCustomer] })
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from './dtos/entities';
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
// TODO GET de hierarquias e do PATCH em usuário
|
||||
@ApiTags('Users')
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
@@ -54,42 +55,41 @@ export class UsersController {
|
||||
|
||||
@Post()
|
||||
@ApiOkResponse({ type: CreateUserRes })
|
||||
async createUser(@User() user, @Body() body: CreateUserReq) {
|
||||
async createUser(@User() user: RequestUser, @Body() body: CreateUserReq) {
|
||||
this.logger.info('createUser', { user });
|
||||
}
|
||||
|
||||
@Post('batch')
|
||||
@ApiOkResponse({ type: CreateUserRes })
|
||||
async batchCreateUser(@User() user, @Body() body: CreateUserReq) {
|
||||
async batchCreateUser(
|
||||
@User() user: RequestUser,
|
||||
@Body() body: CreateUserReq,
|
||||
) {
|
||||
this.logger.info('batchCreateUser', { user });
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOkResponse({ type: DeleteUserRes })
|
||||
async deleteUser(@User() user, @Param('id') id: string) {
|
||||
async deleteUser(@User() user: RequestUser, @Param('id') id: string) {
|
||||
this.logger.info('deleteUser', { user });
|
||||
return await this.userService.deleteUser({ id });
|
||||
}
|
||||
|
||||
@Put('role')
|
||||
async assignRoleToUser(@User() user, @Body() body: AssignRoleToUserReq) {
|
||||
async assignRoleToUser(
|
||||
@User() user: RequestUser,
|
||||
@Body() body: AssignRoleToUserReq,
|
||||
) {
|
||||
this.logger.info('assignRoleToUser', { user });
|
||||
return await this.userService.assignRoleToUser(body);
|
||||
}
|
||||
|
||||
@Delete('role')
|
||||
async unassignRoleToUser(@User() user, @Body() body: UnassignRoleToUserReq) {
|
||||
async unassignRoleToUser(
|
||||
@User() user: RequestUser,
|
||||
@Body() body: UnassignRoleToUserReq,
|
||||
) {
|
||||
this.logger.info('unassignRoleToUser', { user });
|
||||
return await this.userService.unassignRoleToUser(body);
|
||||
}
|
||||
|
||||
// @Get('search')
|
||||
// @ApiOkResponse({ type: SearchUserRes })
|
||||
// async searchUser(
|
||||
// @User() user: RequestUser,
|
||||
// @Query('s') searchQuery: SearchUserReq,
|
||||
// ) {
|
||||
// this.logger.info('searchUser', { user });
|
||||
// console.log(searchQuery);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user