From a722fc6c86cb538accefdec54d6a89c92f93c0f8 Mon Sep 17 00:00:00 2001 From: Gabriel Amorim Date: Fri, 5 May 2023 12:12:59 -0300 Subject: [PATCH] WIP: new logic for feature request --- docsfera.json | 56 +++++++++++++--- .../productboard/productboard.controller.ts | 66 ++++++++++--------- src/modules/users/users.controller.ts | 13 ++++ src/modules/users/users.service.ts | 13 ++++ 4 files changed, 107 insertions(+), 41 deletions(-) diff --git a/docsfera.json b/docsfera.json index 49b938a..af64134 100644 --- a/docsfera.json +++ b/docsfera.json @@ -1412,6 +1412,51 @@ ] } }, + "/users/connector_request": { + "post": { + "operationId": "UsersController_sendConnectorRequest", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UpdateUserRes" + } + } + } + }, + "201": { + "description": "" + } + }, + "tags": [ + "Users" + ], + "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + } + }, "/roles": { "get": { "operationId": "RolesController_searchRoles", @@ -4923,14 +4968,7 @@ }, "responses": { "201": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object" - } - } - } + "description": "" } }, "tags": [ @@ -5041,7 +5079,7 @@ } }, "info": { - "title": "Maestro - feature/customer-links", + "title": "Maestro - main", "description": "This is the Maestro API", "version": "1.0.0", "contact": {} diff --git a/src/modules/productboard/productboard.controller.ts b/src/modules/productboard/productboard.controller.ts index 749b03d..cf534af 100644 --- a/src/modules/productboard/productboard.controller.ts +++ b/src/modules/productboard/productboard.controller.ts @@ -14,42 +14,44 @@ import { INote } from './dtos'; export class ProductboardController { @Post('notes') async sendNote(@Body() note: INote, @User() user: RequestUser) { - const { title, content, tags } = note; - const { username, customer_name } = user; + const [request_type, urgency, connector_name = 'Não informado'] = note.tags; - const email = username.includes('@') - ? username - : username + `@${customer_name}.default`; + const { title, content } = note; + // const { username, customer_name } = user; - const path = process.env.PB_TOKEN_PATH; - const token = await getSecretFromSecretsManager(path); + // const email = username.includes('@') + // ? username + // : username + `@${customer_name}.default`; - const response = await axios - .post( - `https://api.productboard.com/notes`, - { - title, - content, - tags, - user: { - email, - }, - }, - { - headers: { - Authorization: 'Bearer ' + token, - }, - }, - ) - .catch(() => null); + // const path = process.env.PB_TOKEN_PATH; + // const token = await getSecretFromSecretsManager(path); - if (!response) { - throw new HttpException( - 'Your request could not be submitted, please try again in a few moments or contact support.', - 502, - ); - } + // const response = await axios + // .post( + // `https://api.productboard.com/notes`, + // { + // title, + // content, + // tags, + // user: { + // email, + // }, + // }, + // { + // headers: { + // Authorization: 'Bearer ' + token, + // }, + // }, + // ) + // .catch(() => null); - return response.data; + // if (!response) { + // throw new HttpException( + // 'Your request could not be submitted, please try again in a few moments or contact support.', + // 502, + // ); + // } + + // return response.data; } } diff --git a/src/modules/users/users.controller.ts b/src/modules/users/users.controller.ts index 9e00f7c..0e70104 100644 --- a/src/modules/users/users.controller.ts +++ b/src/modules/users/users.controller.ts @@ -263,4 +263,17 @@ export class UsersController { this.logger.info('synchronizeUser', { user }); return await this.userService.synchronizeUser(id); } + + @Post('connector_request') + @RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.SYNC_USER) + @ApiOkResponse({ type: UpdateUserRes }) + async sendConnectorRequest(@User() user: RequestUser, request) { + const metadata = PackTheMetadata({ + customer_name: user.customer_name, + customer_id: user.customer_id, + user_id: user.user_id, + username: user.username, + }); + this.userService.sendUserConnectorRequest(request, metadata); + } } diff --git a/src/modules/users/users.service.ts b/src/modules/users/users.service.ts index e6717fa..a309919 100644 --- a/src/modules/users/users.service.ts +++ b/src/modules/users/users.service.ts @@ -243,4 +243,17 @@ export class UsersService implements OnModuleInit { this.usersClientService.INTERNAL_UserSynchronize({ userId }), ); } + async sendUserConnectorRequest( + request: { + connector_name: string; + description: string; + title: string; + urgency: string; + }, + metadata: Metadata, + ) { + return await lastValueFrom( + this.usersClientService.UserConnectorRequest({ request }, metadata), + ); + } }