mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-22 00:54:48 +00:00
FIX: Swagger
This commit is contained in:
@@ -504,7 +504,7 @@ export const PERMISSIONS_GROUPS = {
|
||||
'es-es': 'Usuarios',
|
||||
},
|
||||
permissions: {
|
||||
ADMIN: {
|
||||
CONNECTIONS_MIGRATION: {
|
||||
seqid: 40,
|
||||
claim: 'dadosfera:connections-migration',
|
||||
usage: PermissionUsages.INTERNAL,
|
||||
@@ -514,6 +514,16 @@ export const PERMISSIONS_GROUPS = {
|
||||
'es-es': 'connections-migration',
|
||||
},
|
||||
},
|
||||
SYNC_USER: {
|
||||
seqid: 41,
|
||||
claim: 'dadosfera:sync-user',
|
||||
usage: PermissionUsages.INTERNAL,
|
||||
name: {
|
||||
'pt-br': 'sync-user',
|
||||
'en-us': 'sync-user',
|
||||
'es-es': 'sync-user',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -45,7 +45,9 @@ export class ConnectionController {
|
||||
}
|
||||
|
||||
@Get('connections-migration')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.ADMIN)
|
||||
@RequireAllPermissions(
|
||||
PERMISSIONS_GROUPS.DADOSFERA.permissions.CONNECTIONS_MIGRATION,
|
||||
)
|
||||
async synchronizeConnections(@Query('apply') apply: string) {
|
||||
return this.clientService.synchronizeConnections(apply === 'true');
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ export class ConnectorClientService implements OnModuleInit {
|
||||
return lastValueFrom(
|
||||
this.connectorServiceWrite.RegisterConnector(serviceBody),
|
||||
).catch((err) => {
|
||||
console.log(err.details);
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
@@ -64,7 +63,6 @@ export class ConnectorClientService implements OnModuleInit {
|
||||
|
||||
return lastValueFrom(this.connectorServiceWrite.UploadFile(body)).catch(
|
||||
(err) => {
|
||||
console.log(err.details);
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
UserByCustomer,
|
||||
} from './dtos/entities';
|
||||
import { UsersService } from './users.service';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
// TODO GET de hierarquias e do PATCH em usuário
|
||||
@ApiTags('Users')
|
||||
@@ -141,9 +142,12 @@ export class UsersController {
|
||||
@Body() body: CreateUserReq,
|
||||
@Headers('dadosfera-lang') language,
|
||||
) {
|
||||
const meta = new Metadata();
|
||||
meta.add('access_token', user.access_token);
|
||||
this.logger.info('createUser', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.createUser(body);
|
||||
|
||||
return await this.userService.createUser(body, meta);
|
||||
}
|
||||
|
||||
@Post('batch')
|
||||
@@ -154,9 +158,11 @@ export class UsersController {
|
||||
@Body() body: BatchCreateUserReq,
|
||||
@Headers('dadosfera-lang') language,
|
||||
) {
|
||||
const meta = new Metadata();
|
||||
meta.add('access_token', user.access_token);
|
||||
this.logger.info('batchCreateUser', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.batchCreateUser(body);
|
||||
return await this.userService.batchCreateUser(body, meta);
|
||||
}
|
||||
|
||||
@Post(':id/resend-invite')
|
||||
@@ -235,4 +241,12 @@ export class UsersController {
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.updateUser(body, id, user.customer_id);
|
||||
}
|
||||
|
||||
@Post('synchronize/:id')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.SYNC_USER)
|
||||
@ApiOkResponse({ type: UpdateUserRes })
|
||||
async synchronizeUser(@User() user: RequestUser, @Param('id') id: string) {
|
||||
this.logger.info('synchronizeUser', { user });
|
||||
return await this.userService.synchronizeUser(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
||||
import { UserByCustomer } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||
import { EnrichErrorCode } from 'src/utils/ErrorBuilder';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService implements OnModuleInit {
|
||||
@@ -83,18 +84,21 @@ export class UsersService implements OnModuleInit {
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
|
||||
async createUser(req: CreateUserReq) {
|
||||
async createUser(req: CreateUserReq, meta?: Metadata) {
|
||||
const { email, department, hierarchy, jobTitle, name, roleNames } = req;
|
||||
const { user } = await lastValueFrom(
|
||||
this.usersClientService.UserCreate({
|
||||
email,
|
||||
hierarchy,
|
||||
name,
|
||||
roleIds: [],
|
||||
department,
|
||||
jobTitle,
|
||||
roleNames,
|
||||
}),
|
||||
this.usersClientService.UserCreate(
|
||||
{
|
||||
email,
|
||||
hierarchy,
|
||||
name,
|
||||
roleIds: [],
|
||||
department,
|
||||
jobTitle,
|
||||
roleNames,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
);
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
@@ -134,7 +138,8 @@ export class UsersService implements OnModuleInit {
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
|
||||
async batchCreateUser({ users }: BatchCreateUserReq) {
|
||||
async batchCreateUser(req: BatchCreateUserReq, meta?: Metadata) {
|
||||
const { users } = req;
|
||||
const usersToCreate: UserCreateRequest[] = users.map(
|
||||
({ roleNames, email, department, hierarchy, jobTitle, name }) => ({
|
||||
roleNames,
|
||||
@@ -147,14 +152,16 @@ export class UsersService implements OnModuleInit {
|
||||
}),
|
||||
);
|
||||
const { errorUsers, usersCreated } = await lastValueFrom(
|
||||
this.usersClientService.UserBatchCreate({
|
||||
users: usersToCreate,
|
||||
}),
|
||||
this.usersClientService.UserBatchCreate(
|
||||
{
|
||||
users: usersToCreate,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
usersCreated: this.adjustUsersPayload(usersCreated),
|
||||
// mapping error code to message
|
||||
errorUsers: errorUsers.map(({ user, error }) => ({
|
||||
user,
|
||||
error: EnrichErrorCode(error).message,
|
||||
@@ -212,4 +219,10 @@ export class UsersService implements OnModuleInit {
|
||||
async findAllCustomers() {
|
||||
return await lastValueFrom(this.customersClientService.CustomerFindAll({}));
|
||||
}
|
||||
|
||||
async synchronizeUser(userId: string) {
|
||||
return await lastValueFrom(
|
||||
this.usersClientService.INTERNAL_UserSynchronize({ userId }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,14 @@ export function EnrichErrorCode(code: string) {
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.USER.NOT_CREATED:
|
||||
return {
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: 'Ocorreu um erro ao criar seu usúario',
|
||||
message: 'Tente novamente ou entre em contato com o suporte',
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.USER.NOT_FOUND:
|
||||
return {
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
|
||||
@@ -31,6 +31,7 @@ export const USER = {
|
||||
ALREADY_EXISTS: 'USER.ALREADY_EXISTS',
|
||||
ROLE_ALREADY_ASSIGNED: 'USER.ROLE_ALREADY_ASSIGNED',
|
||||
ROLE_NOT_ASSIGNED: 'USER.ROLE_NOT_ASSIGNED',
|
||||
NOT_CREATED: 'USER.NOT_CREATED',
|
||||
};
|
||||
|
||||
export const CUSTOMER = {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user