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