src/sales-force/linked-distributors-chart/linked-distributors-chart.controller.ts
linked-distributors-chart
Methods |
|
Async createLinkedDistributorsChart | ||||||||||||
createLinkedDistributorsChart(res, organizationChartId: number, body: LinkedDistributorsChartBody)
|
||||||||||||
Decorators :
@Post(':organizationChartId')
|
||||||||||||
Parameters :
Returns :
any
|
Async deleteLinkedDistributorsChart |
deleteLinkedDistributorsChart(res, id: number, organizationChartId: number)
|
Decorators :
@Delete(':organizationChartId/:id')
|
Returns :
any
|
Async deleteLinkedDistributorsChartAll | |||||||||
deleteLinkedDistributorsChartAll(res, organizationChartId: number)
|
|||||||||
Decorators :
@Delete(':organizationChartId')
|
|||||||||
Parameters :
Returns :
any
|
Async getIdDistributorsSalesForce | |||||||||
getIdDistributorsSalesForce(res, salesForceId: number)
|
|||||||||
Decorators :
@Get('/distributor/salesForce/:salesForceId')
|
|||||||||
Parameters :
Returns :
any
|
Async getLinkedDistributorsChart | ||||||||||||
getLinkedDistributorsChart(res, organizationChartId: number, query: LinkedDistributorsChartQuery)
|
||||||||||||
Decorators :
@Get(':organizationChartId')
|
||||||||||||
Parameters :
Returns :
any
|
Async getLinkedDistributorsChartId |
getLinkedDistributorsChartId(res, id: number, organizationChartId: number)
|
Decorators :
@Get(':organizationChartId/:id')
|
Returns :
any
|
Async getOrganizationChart | |||||||||
getOrganizationChart(res, query: LinkedDistributorsChartQueryDTO)
|
|||||||||
Decorators :
@Get('')
|
|||||||||
Parameters :
Returns :
any
|
Async getOrganizationChartExcelDistributors | |||||||||
getOrganizationChartExcelDistributors(res, query: LinkedDistributorsChartQueryDTO)
|
|||||||||
Decorators :
@Get('/excel/export/report')
|
|||||||||
Parameters :
Returns :
any
|
Async getOrganizationChartHeaders | ||||
getOrganizationChartHeaders(res)
|
||||
Decorators :
@Get('template/excel/header')
|
||||
Parameters :
Returns :
any
|
Async updateLinkedDistributorsChart | |||||||||||||||
updateLinkedDistributorsChart(res, id: number, organizationChartId: number, body: LinkedDistributorsChartBody)
|
|||||||||||||||
Decorators :
@Put(':organizationChartId/:id')
|
|||||||||||||||
Parameters :
Returns :
any
|
Async uploadFile | |||||||||||||||
uploadFile(file: Express.Multer.File, organizationChartId: number, res, req)
|
|||||||||||||||
Decorators :
@Post('excel/:organizationChartId')
|
|||||||||||||||
Parameters :
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 })
}
}
}