FEAT: Roles WIP

This commit is contained in:
Gabriel Rosa
2022-07-14 10:23:04 -03:00
parent d5cd562860
commit 14cfc46492
15 changed files with 247 additions and 116 deletions
+16 -34
View File
@@ -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] })
+15 -15
View File
@@ -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);
// }
}