mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import { IdResponse } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Inject,
|
|
Param,
|
|
Put,
|
|
Query,
|
|
UseFilters,
|
|
} from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
|
import {
|
|
Authenticated,
|
|
RequireAllPermissions,
|
|
} from 'src/decorators/authentication.decorator';
|
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
|
import { CustomersService } from './customers.service';
|
|
import { CustomerDto, CustomerLinksResponse } from './dtos/customers';
|
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
|
import type { StringValue } from 'ms';
|
|
|
|
@ApiInternalOnlyController()
|
|
@ApiTags('Customers')
|
|
@Controller('customers')
|
|
@Authenticated()
|
|
@UseFilters(GrpcToHttpExceptionFilter)
|
|
export class CustomersController {
|
|
logger: DadosferaLogger;
|
|
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private customersService: CustomersService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Get(':id/links')
|
|
async getCustomerLinks(@Param('id') id): Promise<CustomerLinksResponse> {
|
|
this.logger.info('getCustomerLinks', { id });
|
|
const links = await this.customersService.getLinks(id);
|
|
return { links };
|
|
}
|
|
|
|
@Put(':id/links')
|
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
setCustomerLinks(
|
|
@Body() body: CustomerDto,
|
|
@Param('id') id,
|
|
): Promise<IdResponse> {
|
|
const { links } = body;
|
|
this.logger.info('setCustomerLinks', { id, links });
|
|
return this.customersService.setLinks(id, links);
|
|
}
|
|
|
|
@Get('token')
|
|
@RequireAllPermissions(PERMISSIONS_GROUPS.AUTH.permissions.GENERATE_TOKEN)
|
|
async getCustomerToken(
|
|
@Query('exp') exp: StringValue,
|
|
@User() user: RequestUser,
|
|
): Promise<string> {
|
|
this.logger.info('getCustomerToken', { exp, user });
|
|
const data = {
|
|
customerId: user.customer_id,
|
|
userId: user.user_id,
|
|
customerName: user.customer_name,
|
|
};
|
|
return this.customersService.generateToken(exp, data);
|
|
}
|
|
}
|