File

src/client/client.controller.ts

Prefix

/client

Index

Methods

Methods

addApplication
addApplication(clientId: number, body: AddApplicationClientBody)
Decorators :
@Post(':clientId/application')
@ApiResponse({status: undefined})
@ApiBadRequestResponse({status: undefined})
@ApiNotFoundResponse({status: undefined})
Parameters :
Name Type Optional
clientId number No
body AddApplicationClientBody No
Returns : any
Async addClientConfig
addClientConfig(body: BodyClientConfigDTO, session)
Decorators :
@Post('config')
Parameters :
Name Type Optional
body BodyClientConfigDTO No
session No
Returns : unknown
Async addConversionTypes
addConversionTypes(req, response: Response, body: AddConversionTypeBody)
Decorators :
@Post('/conversionTypes')
Parameters :
Name Type Optional
req No
response Response No
body AddConversionTypeBody No
Returns : unknown
addObersa
addObersa(req, body: ObservationDto)
Decorators :
@Post('observation')
@ApiResponse({status: undefined})
Parameters :
Name Type Optional
req No
body ObservationDto No
Returns : any
Async createLevel
createLevel(req, response: Response, body: AddLevelBody)
Decorators :
@Post('/levels')
Parameters :
Name Type Optional
req No
response Response No
body AddLevelBody No
Returns : unknown
Async createLevelOption
createLevelOption(req, response: Response, body: AddLevelOptionBody)
Decorators :
@Post('/levels/option')
Parameters :
Name Type Optional
req No
response Response No
body AddLevelOptionBody No
Returns : unknown
Async createSecret
createSecret(req: Request, response: Response)
Decorators :
@Post('/create-secret')
Parameters :
Name Type Optional
req Request No
response Response No
Returns : unknown
deleteApplication
deleteApplication(id: number, applicationId: number)
Decorators :
@Delete('application/:id/:application_id')
@ApiResponse({status: undefined})
Parameters :
Name Type Optional
id number No
applicationId number No
Returns : any
Async deleteClientConfig
deleteClientConfig(params: DeleteClientConfigDTO, session)
Decorators :
@Delete('config')
Parameters :
Name Type Optional
params DeleteClientConfigDTO No
session No
Returns : any
Async deleteCredential
deleteCredential(credentialId: string, clientId: number, req: Request, response: Response)
Decorators :
@Delete('/delete/:credentialId/:clientId')
Parameters :
Name Type Optional
credentialId string No
clientId number No
req Request No
response Response No
Returns : unknown
Async deleteLevel
deleteLevel(req, response: Response, body: DeleteLevelBody)
Decorators :
@Delete('/levels')
Parameters :
Name Type Optional
req No
response Response No
body DeleteLevelBody No
Returns : unknown
Async deleteLevelOption
deleteLevelOption(req, response: Response, body: DeleteLevelOptionBody)
Decorators :
@Delete('/levels/option')
Parameters :
Name Type Optional
req No
response Response No
body DeleteLevelOptionBody No
Returns : unknown
Async disabledApplication
disabledApplication(response, clientId: number, applicationId: number)
Decorators :
@Post(':clientId/application/:application_id/disable')
@ApiResponse({status: undefined})
@ApiBadRequestResponse({status: undefined})
@ApiNotFoundResponse({status: undefined})
Parameters :
Name Type Optional
response No
clientId number No
applicationId number No
Returns : unknown
Async editClientConfig
editClientConfig(id: number, body: BodyClientConfigDTO, session)
Decorators :
@Put('config/:id')
Parameters :
Name Type Optional
id number No
body BodyClientConfigDTO No
session No
Returns : any
Async enabledApplication
enabledApplication(response, clientId: number, applicationId: number)
Decorators :
@Post(':clientId/application/:application_id/enable')
@ApiResponse({status: undefined})
@ApiBadRequestResponse({status: undefined})
@ApiNotFoundResponse({status: undefined})
Parameters :
Name Type Optional
response No
clientId number No
applicationId number No
Returns : unknown
getApplication
getApplication(clientId: number)
Decorators :
@Get(':clientId/application')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
clientId number No
getApplicationAvaiable
getApplicationAvaiable(clientId: number)
Decorators :
@Get(':clientId/application-available')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
clientId number No
Async getClient
getClient()
Decorators :
@Get()
@ApiResponse({type: ClientDto})
Returns : unknown
Async getClientByMtrixCode
getClientByMtrixCode(query: FindClientByMtrixCodeQueryDTO)
Decorators :
@Get('/find/mtrixCode')
@ApiResponse({type: ClientDto})
Parameters :
Name Type Optional
query FindClientByMtrixCodeQueryDTO No
Returns : unknown
Async getClientConfig
getClientConfig(clientId: number, query: PaginateQuery)
Decorators :
@Get('config/:clientId')
Parameters :
Name Type Optional
clientId number No
query PaginateQuery No
Returns : unknown
getClientId
getClientId(id: number)
Decorators :
@Get('/:id')
@ApiResponse({type: ClientDto})
Parameters :
Name Type Optional
id number No
Returns : any
Async getClientPaginate
getClientPaginate(query: PaginateClientQueryDTO)
Decorators :
@Get('paginate')
@ApiResponse({type: ClientDto})
@ApiQuery({name: 'name', type: 'string', required: false})
Parameters :
Name Type Optional
query PaginateClientQueryDTO No
Returns : unknown
Async getCompany
getCompany(name: string)
Decorators :
@Get('/company/:name')
Parameters :
Name Type Optional
name string No
Returns : unknown
Async getConversionTypes
getConversionTypes(req, response: Response)
Decorators :
@Get('/conversionTypes')
Parameters :
Name Type Optional
req No
response Response No
Returns : unknown
Async getConversionTypesByClient
getConversionTypesByClient(clientId: number, req, response: Response)
Decorators :
@Get('/conversionTypes/:clientId')
Parameters :
Name Type Optional
clientId number No
req No
response Response No
Returns : unknown
Async getCredentials
getCredentials(clientId: number, req: Request, response: Response)
Decorators :
@Get('/credentials/:clientId')
Parameters :
Name Type Optional
clientId number No
req Request No
response Response No
Returns : unknown
Async getHistoricClientConfig
getHistoricClientConfig(clientId: number, query: PaginateQuery)
Decorators :
@Get('config-historic/:clientId')
Parameters :
Name Type Optional
clientId number No
query PaginateQuery No
Returns : unknown
Async getLevelOptionsByCode
getLevelOptionsByCode(clientId: number, levelCode: number, req, response: Response)
Decorators :
@Get('/levels/:clientId/:levelCode')
Parameters :
Name Type Optional
clientId number No
levelCode number No
req No
response Response No
Returns : unknown
Async getLevels
getLevels(clientId: number, req, response: Response)
Decorators :
@Get('/levels/:clientId')
Parameters :
Name Type Optional
clientId number No
req No
response Response No
Returns : unknown
getSalesForceLevelClientId
getSalesForceLevelClientId(clientId: number)
Decorators :
@Get(':clientId/salesForceLevel')
@ApiResponse({type: ClientDto})
Parameters :
Name Type Optional
clientId number No
Returns : any
getUsersByClient
getUsersByClient(clientId: number)
Decorators :
@Get(':clientId/user')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
clientId number No
Returns : any
getUsersDetailsByClient
getUsersDetailsByClient(nameOrId: number, query: PaginateQuery)
Decorators :
@Get(':nameOrId/user/details')
@ApiResponse({type: undefined})
Parameters :
Name Type Optional
nameOrId number No
query PaginateQuery No
Returns : any
postClient
postClient(body: ClientPostDto, req: any)
Decorators :
@Post()
@ApiResponse({status: undefined, type: ClientPostResponseDto})
Parameters :
Name Type Optional
body ClientPostDto No
req any No
Returns : any
putClient
putClient(req, body: ClientDto, id: number)
Decorators :
@Put('/:id')
@ApiResponse({type: ClientDto})
Parameters :
Name Type Optional
req No
body ClientDto No
id number No
Returns : any
putEnabled
putEnabled(body: ClientEnableDto, id: number)
Decorators :
@Put('enabled/:id')
@ApiResponse({type: ClientDto})
Parameters :
Name Type Optional
body ClientEnableDto No
id number No
Returns : any
Async removeConversionType
removeConversionType(req, response: Response, body: DeleteConversionTypeBody)
Decorators :
@Delete('/conversionTypes')
Parameters :
Name Type Optional
req No
response Response No
body DeleteConversionTypeBody No
Returns : unknown
import {
  Body,
  Controller,
  Delete,
  Get,
  HttpStatus,
  Logger,
  Param,
  Post,
  Put,
  Query,
  Req,
  Res,
  Session,
} from '@nestjs/common';
import {
  ApiBadRequestResponse,
  ApiBearerAuth,
  ApiNotFoundResponse,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { Request, Response } from 'express';
import { Application } from 'src/entities/application';
import { ApplicationClient } from 'src/entities/applicationClient';
import { UserClient } from 'src/entities/user-client';
import { User } from 'src/entities/user';
import { UserClientService } from 'src/user/user-client/user-client.service';
import { handleErrors, handleErrorsCatch } from 'src/util';
import { ClientService } from './client.service';
import {
  AddApplicationClientBody,
  BodyClientConfigDTO,
  AddConversionTypeBody,
  AddLevelBody,
  AddLevelOptionBody,
  ClientDto,
  ClientEnableDto,
  ClientPostDto,
  ClientPostResponseDto,
  DeleteConversionTypeBody,
  DeleteLevelBody,
  DeleteLevelOptionBody,
  FindClientByMtrixCodeQueryDTO,
  ObservationDto,
  PaginateClientQueryDTO,
  DeleteClientConfigDTO,
} from './dto/client.dto';
import { PaginateQuery } from 'src/types/paginate-query';
import { ClientConfigService } from './client-config/client-config.service';

@ApiTags('client')
@ApiBearerAuth('token')
@Controller('/client')
export class ClientController {
  private logger= new Logger(ClientController.name);
  constructor(
    private readonly clientService: ClientService,
    private readonly userClientService: UserClientService,
    private readonly clientConfigService: ClientConfigService,
  ) {}

  @Post()
  @ApiResponse({ status: HttpStatus.OK, type: ClientPostResponseDto })
  postClient(@Body() body: ClientPostDto, @Req() req: any) {
    const { session } = req;
    return this.clientService.postClient(body, session);
  }

  @Get()
  @ApiResponse({ type: ClientDto })
  async getClient() {
    return await this.clientService.getClient();
  }

  @Get('/company/:name')
  async getCompany(@Param('name') name: string) {
    return await this.clientService.getCompanyByClientName(name);
  }

  @Get('paginate')
  @ApiResponse({ type: ClientDto })
  @ApiQuery({
    name: 'name',
    type: 'string',
    required: false,
  })
  async getClientPaginate(@Query() query: PaginateClientQueryDTO) {
    return await this.clientService.findPaginate(query);
  }

  //desativando consulta por cnpjs
  // @Get('/cnpj/:cnpj')
  // @ApiResponse({ type: ClientDto })
  // async getClientCNPJ(@Param('cnpj') cnpj: string) {
  //   return await this.clientService.getClientCNPJ(cnpj);
  // }

  @Put('/:id')
  @ApiResponse({ type: ClientDto })
  putClient(@Req() req, @Body() body: ClientDto, @Param('id') id: number) {
    const { session } = req;
    return this.clientService.putClient(id, body, session);
  }

  @Put('enabled/:id')
  @ApiResponse({ type: ClientDto })
  putEnabled(@Body() body: ClientEnableDto, @Param('id') id: number) {
    return this.clientService.enabledClient(id, body);
  }

  @Get(':clientId/application-available')
  @ApiResponse({ type: [Application] })
  getApplicationAvaiable(
    @Param('clientId') clientId: number
  ): Promise<Application[]> {
    return this.clientService.getApplicationsAvailableClient(+clientId);
  }

  @Post(':clientId/application')
  @ApiResponse({ status: HttpStatus.OK })
  @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST })
  @ApiNotFoundResponse({ status: HttpStatus.NOT_FOUND })
  addApplication(
    @Param('clientId') clientId: number,
    @Body() body: AddApplicationClientBody
  ) {
    return this.clientService.addApplication(clientId, body);
  }

  @Get(':clientId/application')
  @ApiResponse({ type: [ApplicationClient] })
  getApplication(
    @Param('clientId') clientId: number
  ): Promise<ApplicationClient[]> {
    return this.clientService.getApplicationsByClientId(+clientId);
  }

  @Post(':clientId/application/:application_id/enable')
  @ApiResponse({ status: HttpStatus.OK })
  @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST })
  @ApiNotFoundResponse({ status: HttpStatus.NOT_FOUND })
  async enabledApplication(
    @Res() response,
    @Param('clientId') clientId: number,
    @Param('application_id') applicationId: number
  ) {
    try {
      const clientApplication = await this.clientService.enabledApplication(
        +applicationId,
        +clientId
      );
      return response.status(200).json(clientApplication);
    } catch (error) {
      handleErrors(error, response);
    }
  }

  @Post(':clientId/application/:application_id/disable')
  @ApiResponse({ status: HttpStatus.OK })
  @ApiBadRequestResponse({ status: HttpStatus.BAD_REQUEST })
  @ApiNotFoundResponse({ status: HttpStatus.NOT_FOUND })
  async disabledApplication(
    @Res() response,
    @Param('clientId') clientId: number,
    @Param('application_id') applicationId: number
  ) {
    try {
      const clientApplication = await this.clientService.disabledApplication(
        +applicationId,
        +clientId
      );
      return response.status(200).json(clientApplication);
    } catch (error) {
      handleErrors(error, response);
    }
  }

  @Delete('application/:id/:application_id')
  @ApiResponse({ status: HttpStatus.OK })
  deleteApplication(
    @Param('id') id: number,
    @Param('application_id') applicationId: number
  ) {
    return this.clientService.deleteApplication(applicationId, id);
  }

  @Post('observation')
  @ApiResponse({ status: HttpStatus.OK })
  addObersa(@Req() req, @Body() body: ObservationDto) {
    const { session } = req;
    return this.clientService.addObservation(body, session);
  }

  @Get('/credentials/:clientId')
  async getCredentials(
    @Param('clientId') clientId: number,
    @Req() req: Request,
    @Res() response: Response
  ) {
    try {
      const {
        session: { realm: realmUser, roles: rolesUser },
      } = req;

      const client = await this.clientService.getCredentials({
        clientId,
        realmUser,
        rolesUser,
      });

      return response.json(client);
    } catch (error) {
      handleErrorsCatch(error, response);
    }
  }

  @Post('/create-secret')
  async createSecret(@Req() req: Request, @Res() response: Response) {
    try {
      const { name, clientId } = req.body;

      const {
        headers: { authorization },
      } = req;

      const token = authorization.split(' ')[1];

      await this.clientService.createSecret(name, clientId, token);

      return response.status(201).send();
    } catch (error) {
      handleErrorsCatch(error, response);
    }
  }

  @Delete('/delete/:credentialId/:clientId')
  async deleteCredential(
    @Param('credentialId') credentialId: string,
    @Param('clientId') clientId: number,
    @Req() req: Request,
    @Res() response: Response
  ) {
    try {
      const {
        headers: { authorization },
      } = req;

      const token = authorization.split(' ')[1];

      await this.clientService.deleteCredential(credentialId, clientId, token);

      return response.status(201).send();
    } catch (error) {
      handleErrorsCatch(error, response);
    }
  }

  @Get('/levels/:clientId')
  async getLevels(
    @Param('clientId') clientId: number,
    @Req() req,
    @Res() response: Response
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.getLevels(clientId, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Post('/levels')
  async createLevel(
    @Req() req,
    @Res() response: Response,
    @Body() body: AddLevelBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.createLevel(body, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Delete('/levels')
  async deleteLevel(
    @Req() req,
    @Res() response: Response,
    @Body() body: DeleteLevelBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.deleteLevel(body, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Delete('/levels/option')
  async deleteLevelOption(
    @Req() req,
    @Res() response: Response,
    @Body() body: DeleteLevelOptionBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.deleteLevelOption(body, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Post('/levels/option')
  async createLevelOption(
    @Req() req,
    @Res() response: Response,
    @Body() body: AddLevelOptionBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.createLevelOption(body, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Get('/levels/:clientId/:levelCode')
  async getLevelOptionsByCode(
    @Param('clientId') clientId: number,
    @Param('levelCode') levelCode: number,
    @Req() req,
    @Res() response: Response
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const levels = await this.clientService.getLevelOptionsByCode(clientId, levelCode, token)
      return response.json(levels)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Get('/conversionTypes')
  async getConversionTypes(
    @Req() req,
    @Res() response: Response
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const conversionTypes = await this.clientService.getConversionTypes(token)
      return response.json(conversionTypes)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Post('/conversionTypes')
  async addConversionTypes(
    @Req() req,
    @Res() response: Response,
    @Body() body: AddConversionTypeBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const conversionTypes = await this.clientService.addConversionType(body, token)
      return response.json(conversionTypes)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Delete('/conversionTypes')
  async removeConversionType(
    @Req() req,
    @Res() response: Response,
    @Body() body: DeleteConversionTypeBody
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const conversionTypes = await this.clientService.deleteConversionType(body, token)
      return response.json(conversionTypes)
    } catch (error) {
      this.logger.error({ error: error.response })
      handleErrorsCatch(error, response)
    }
  }

  @Get('/conversionTypes/:clientId')
  async getConversionTypesByClient(
    @Param('clientId') clientId: number,
    @Req() req,
    @Res() response: Response
  ) {
    const {
      headers: { authorization },
    } = req;

    const token = authorization.split(' ')[1];

    try {
      const conversionTypes = await this.clientService.getConversionTypesByClient(clientId, token)
      return response.json(conversionTypes)
    } catch (error) {
      this.logger.error({ error: error?.response })
      handleErrorsCatch(error, response)
    }
  }

  @Get('/:id')
  @ApiResponse({ type: ClientDto })
  getClientId(@Param('id') id: number) {
    return this.clientService.getClientId(id);
  }

  @Get('/find/mtrixCode')
  @ApiResponse({ type: ClientDto })
  async getClientByMtrixCode(@Query() query: FindClientByMtrixCodeQueryDTO) {
    return await this.clientService.findClientByMtrixCode(query);
  }

  @Get(':clientId/salesForceLevel')
  @ApiResponse({ type: ClientDto })
  getSalesForceLevelClientId(@Param('clientId') clientId: number) {
    return this.clientService.getClientIdSalesForceLevel(clientId);
  }

  // UserClient
  @Get(':clientId/user')
  @ApiResponse({ type: [UserClient] })
  getUsersByClient(@Param('clientId') clientId: number) {
    return this.userClientService.getUsersByClient(+clientId);
  }

  @Get(':nameOrId/user/details')
  @ApiResponse({ type: [User] })
  getUsersDetailsByClient(
    @Param('nameOrId') nameOrId: number,
    @Query() query: PaginateQuery
  ) {
    return this.userClientService.getUsersDetailsByClient(nameOrId, query);
  }

  // ClientConfig
  @Get('config/:clientId')
  async getClientConfig(
    @Param('clientId') clientId: number,
    @Query() query: PaginateQuery,
  ) {
    return await this.clientConfigService.findByClient(clientId, query);
  }

  @Post('config')
  async addClientConfig(
    @Body() body: BodyClientConfigDTO,
    @Session() session,
  ) {
    const id = await this.clientConfigService.addConfig(body, session);
    return { id };
  }

  @Put('config/:id')
  async editClientConfig(
    @Param('id') id: number,
    @Body() body: BodyClientConfigDTO,
    @Session() session,
  ) {
    await this.clientConfigService.updateConfig(+id, body, session);
  }

  @Delete('config')
  async deleteClientConfig(
    @Body() params: DeleteClientConfigDTO,
    @Session() session,
  ) {
    await this.clientConfigService.deleteConfig(params, session);
  }

  @Get('config-historic/:clientId')
  async getHistoricClientConfig(
    @Param('clientId') clientId: number,
    @Query() query: PaginateQuery,
  ) {
    return await this.clientConfigService.getHistorict(+clientId, query);
  }
}

results matching ""

    No results matching ""