File

src/sales-force/linked-distributors-chart/linked-distributors-chart.controller.ts

Prefix

linked-distributors-chart

Index

Methods

Methods

Async createLinkedDistributorsChart
createLinkedDistributorsChart(res, organizationChartId: number, body: LinkedDistributorsChartBody)
Decorators :
@Post(':organizationChartId')
Parameters :
Name Type Optional
res No
organizationChartId number No
body LinkedDistributorsChartBody No
Returns : any
Async deleteLinkedDistributorsChart
deleteLinkedDistributorsChart(res, id: number, organizationChartId: number)
Decorators :
@Delete(':organizationChartId/:id')
Parameters :
Name Type Optional
res No
id number No
organizationChartId number No
Returns : any
Async deleteLinkedDistributorsChartAll
deleteLinkedDistributorsChartAll(res, organizationChartId: number)
Decorators :
@Delete(':organizationChartId')
Parameters :
Name Type Optional
res No
organizationChartId number No
Returns : any
Async getIdDistributorsSalesForce
getIdDistributorsSalesForce(res, salesForceId: number)
Decorators :
@Get('/distributor/salesForce/:salesForceId')
Parameters :
Name Type Optional
res No
salesForceId number No
Returns : any
Async getLinkedDistributorsChart
getLinkedDistributorsChart(res, organizationChartId: number, query: LinkedDistributorsChartQuery)
Decorators :
@Get(':organizationChartId')
Parameters :
Name Type Optional
res No
organizationChartId number No
query LinkedDistributorsChartQuery No
Returns : any
Async getLinkedDistributorsChartId
getLinkedDistributorsChartId(res, id: number, organizationChartId: number)
Decorators :
@Get(':organizationChartId/:id')
Parameters :
Name Type Optional
res No
id number No
organizationChartId number No
Returns : any
Async getOrganizationChart
getOrganizationChart(res, query: LinkedDistributorsChartQueryDTO)
Decorators :
@Get('')
Parameters :
Name Type Optional
res No
query LinkedDistributorsChartQueryDTO No
Returns : any
Async getOrganizationChartExcelDistributors
getOrganizationChartExcelDistributors(res, query: LinkedDistributorsChartQueryDTO)
Decorators :
@Get('/excel/export/report')
Parameters :
Name Type Optional
res No
query LinkedDistributorsChartQueryDTO No
Returns : any
Async getOrganizationChartHeaders
getOrganizationChartHeaders(res)
Decorators :
@Get('template/excel/header')
Parameters :
Name Optional
res No
Returns : any
Async updateLinkedDistributorsChart
updateLinkedDistributorsChart(res, id: number, organizationChartId: number, body: LinkedDistributorsChartBody)
Decorators :
@Put(':organizationChartId/:id')
Parameters :
Name Type Optional
res No
id number No
organizationChartId number No
body LinkedDistributorsChartBody No
Returns : any
Async uploadFile
uploadFile(file: Express.Multer.File, organizationChartId: number, res, req)
Decorators :
@Post('excel/:organizationChartId')
@ApiConsumes('multipart/form-data')
@ApiBody({type: FileUploadDto})
@UseInterceptors(undefined)
Parameters :
Name Type Optional
file Express.Multer.File No
organizationChartId number No
res No
req No
Returns : unknown
import { Controller, Get, Put, Post, Param, Delete, Res, Body, Query, UseInterceptors, UploadedFile, Req, HttpStatus } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { LinkedDistributorsChartService } from './linked-distributors-chart.services';
import { LinkedDistributorsChartBody, LinkedDistributorsChartQuery, LinkedDistributorsChartQueryDTO } from '../dto/linked-distributors-chart.dto';
import { FileUploadDto } from '../dto/sales-force.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import { query } from 'express';
import { addBoldToFirstRow } from 'src/util/excelToJson';

@ApiTags('Linked Distributors Chart')
@ApiBearerAuth('token')
@Controller('linked-distributors-chart')
export class LinkedDistributorsChartController {
  constructor(
    private readonly linkedDistributorsChartService: LinkedDistributorsChartService
  ) { }

  @Post(':organizationChartId')
  async createLinkedDistributorsChart(
    @Res() res,
    @Param('organizationChartId') organizationChartId: number,
    @Body() body: LinkedDistributorsChartBody) {
    try {
      const recordset = await this.linkedDistributorsChartService.createlinkedDistributorsChart(body, organizationChartId);
      res.status(201).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }

  @Put(':organizationChartId/:id')
  async updateLinkedDistributorsChart(
    @Res() res,
    @Param('id') id: number,
    @Param('organizationChartId') organizationChartId: number,
    @Body() body: LinkedDistributorsChartBody) {
    try {
      const recordset = await this.linkedDistributorsChartService.putlinkedDistributorsChart(body, +organizationChartId, +id)
      res.status(201).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }


  @Get(':organizationChartId')
  async getLinkedDistributorsChart(
    @Res() res,
    @Param('organizationChartId') organizationChartId: number,
    @Query() query: LinkedDistributorsChartQuery) {

    try {
      const response = await this.linkedDistributorsChartService.getlinkedDistributorsChart(query, +organizationChartId)
      res.status(201).json(response);
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }

  @Delete(':organizationChartId/:id')
  async deleteLinkedDistributorsChart(
    @Res() res,
    @Param('id') id: number,
    @Param('organizationChartId') organizationChartId: number
  ) {
    try {
      const recordset = await this.linkedDistributorsChartService.deletelinkedDistributorsChart(+organizationChartId, +id)
      res.status(201).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }

  @Delete(':organizationChartId')
  async deleteLinkedDistributorsChartAll(
    @Res() res,
    @Param('organizationChartId') organizationChartId: number
  ) {
    try {
      const recordset = await this.linkedDistributorsChartService.deletelinkedDistributorsChartAll(+organizationChartId)
      res.status(HttpStatus.ACCEPTED).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }


  @Get(':organizationChartId/:id')
  async getLinkedDistributorsChartId(
    @Res() res,
    @Param('id') id: number,
    @Param('organizationChartId') organizationChartId: number
  ) {
    try {
      const recordset = await this.linkedDistributorsChartService.getlinkedDistributorsChartId(+id, +organizationChartId)
      res.status(201).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }

  @Get('/distributor/salesForce/:salesForceId')
  async getIdDistributorsSalesForce(
    @Res() res,
    @Param('salesForceId') salesForceId: number
  ) {
    try {
      const recordset = await this.linkedDistributorsChartService.getIdDistributorsSalesForce(+salesForceId)
      res.status(201).json({ recordset });
    } catch (error) {
      res.status(error?.status|| 501).json({message:error.detail || error.message})
    }
  }

  @Post('excel/:organizationChartId')
  @ApiConsumes('multipart/form-data')
  @ApiBody({ type: FileUploadDto })
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(
    @UploadedFile() file: Express.Multer.File,
    @Param('organizationChartId') organizationChartId: number,
    @Res() res,
    @Req() req,
  ) {
    try {
      const {
        headers: { authorization },
      } = req;
  
      const token = authorization.split(' ')[1];
      const result =
        await this.linkedDistributorsChartService.uploadFile(
          file,
          +organizationChartId,
          token
        );
      res.status(HttpStatus.OK).json(result);
    } catch (error) {
      if (error.status === 415) {
        return res
          .status(200)
          .json({ error: true, recordset: error.response });
      }
      
      return res
        .status(error.status || 500)
        .json({ message: error.message || 'Bad Request' });
    }
  }


  @Get('template/excel/header')
  async getOrganizationChartHeaders(
    @Res() res,
  ) {
    try {
      const result = await this.linkedDistributorsChartService.getLinkDistributorsHeaders()
      res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      res.setHeader("Content-Disposition", `attachment; filename=${result[0]}-Links.xlsx`);
      res.status(HttpStatus.OK).send(result[1]);
    } catch (error) {
      res.status(error?.status || 501).json({ message: error.detail || error.message })
    }
  }


  @Get('')
  async getOrganizationChart(
    @Res() res,
    @Query() query: LinkedDistributorsChartQueryDTO
  ) {
    try {
      const result = await this.linkedDistributorsChartService.getLinkDistributors(query)
      // res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      // res.setHeader("Content-Disposition", `attachment; filename=${result[0]}-Links.xlsx`);
      res.status(HttpStatus.OK).send(result);
    } catch (error) {
      res.status(error?.status || 501).json({ message: error.detail || error.message })
    }
  }

  @Get('/excel/export/report')
  async getOrganizationChartExcelDistributors(
    @Res() res,
    @Query() query: LinkedDistributorsChartQueryDTO
  ) {
    try {
      const result = await this.linkedDistributorsChartService.getLinkDistributorsExcel(query)
      const nameDate = (new Date()).toISOString();
      res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      res.setHeader("Content-Disposition", `attachment; filename=${result[0]}-OC-${nameDate}.xlsx`);
      res.status(HttpStatus.OK).send(result[1]);
    } catch (error) {
      res.status(error?.status || 501).json({ message: error.detail || error.message })
    }
  }



}

results matching ""

    No results matching ""