mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
refactor(nestjs): wip import module
This commit is contained in:
7
packages/server/src/common/config/bank-feed.ts
Normal file
7
packages/server/src/common/config/bank-feed.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
|
export default registerAs('bank-feed', () => ({
|
||||||
|
enabled:
|
||||||
|
process.env.BANK_FEED_ENABLED === 'true' ||
|
||||||
|
process.env.BANK_FEED_ENABLED === 'yes',
|
||||||
|
}));
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import FormData from 'form-data';
|
import * as FormData from 'form-data';
|
||||||
import { GotenbergUtils } from './GotenbergUtils';
|
import { GotenbergUtils } from './GotenbergUtils';
|
||||||
import { PageProperties } from './_types';
|
import { PageProperties } from './_types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import FormData from 'form-data';
|
import * as FormData from 'form-data';
|
||||||
import Axios from 'axios';
|
import { Axios } from 'axios';
|
||||||
|
|
||||||
export class GotenbergUtils {
|
export class GotenbergUtils {
|
||||||
public static assert(condition: boolean, message: string): asserts condition {
|
public static assert(condition: boolean, message: string): asserts condition {
|
||||||
@@ -10,12 +10,12 @@ export class GotenbergUtils {
|
|||||||
|
|
||||||
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
const response = await Axios.post(endpoint, data, {
|
const response = await new Axios({
|
||||||
headers: {
|
headers: {
|
||||||
...data.getHeaders(),
|
...data.getHeaders(),
|
||||||
},
|
},
|
||||||
responseType: 'arraybuffer', // This ensures you get a Buffer bac
|
responseType: 'arraybuffer', // This ensures you get a Buffer bac
|
||||||
});
|
}).post(endpoint, data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { constants, createReadStream, PathLike, promises } from 'fs';
|
import { constants, createReadStream, PathLike, promises } from 'fs';
|
||||||
import FormData from 'form-data';
|
import * as FormData from 'form-data';
|
||||||
import { GotenbergUtils } from './GotenbergUtils';
|
import { GotenbergUtils } from './GotenbergUtils';
|
||||||
import { IConverter, PageProperties } from './_types';
|
import { IConverter, PageProperties } from './_types';
|
||||||
import { PdfFormat, ChromiumRoute } from './_types';
|
import { PdfFormat, ChromiumRoute } from './_types';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import FormData from 'form-data';
|
import * as FormData from 'form-data';
|
||||||
import { IConverter, PageProperties, PdfFormat, ChromiumRoute } from './_types';
|
import { IConverter, PageProperties, PdfFormat, ChromiumRoute } from './_types';
|
||||||
import { ConverterUtils } from './ConvertUtils';
|
import { ConverterUtils } from './ConvertUtils';
|
||||||
import { Converter } from './Converter';
|
import { Converter } from './Converter';
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const models = [
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [S3Module, ...models],
|
imports: [S3Module, ...models],
|
||||||
|
exports: [...models],
|
||||||
controllers: [AttachmentsController],
|
controllers: [AttachmentsController],
|
||||||
providers: [
|
providers: [
|
||||||
DeleteAttachment,
|
DeleteAttachment,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
// import config from '@/config';
|
// import config from '@/config';
|
||||||
|
|
||||||
export const getUploadedObjectUri = (objectKey: string) => {
|
export const getUploadedObjectUri = (objectKey: string) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { PageProperties, PdfFormat } from '@/libs/Chromiumly/_types';
|
import { PageProperties, PdfFormat } from '@/libs/Chromiumly/_types';
|
||||||
import { UrlConverter } from '@/libs/Chromiumly/UrlConvert';
|
import { UrlConverter } from '@/libs/Chromiumly/UrlConvert';
|
||||||
@@ -40,7 +40,7 @@ export class ChromiumlyHtmlConvert {
|
|||||||
|
|
||||||
const cleanup = async () => {
|
const cleanup = async () => {
|
||||||
await fs.unlink(filePath);
|
await fs.unlink(filePath);
|
||||||
await Document.query().where('key', filename).delete();
|
await this.documentModel().query().where('key', filename).delete();
|
||||||
};
|
};
|
||||||
return [filename, cleanup];
|
return [filename, cleanup];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export const PDF_FILE_SUB_DIR = '/pdf';
|
export const PDF_FILE_SUB_DIR = '/pdf';
|
||||||
export const PDF_FILE_EXPIRE_IN = 40; // ms
|
export const PDF_FILE_EXPIRE_IN = 40; // ms
|
||||||
@@ -9,6 +9,5 @@ export const getPdfFilesStorageDir = (filename: string) => {
|
|||||||
|
|
||||||
export const getPdfFilePath = (filename: string) => {
|
export const getPdfFilePath = (filename: string) => {
|
||||||
const storageDir = getPdfFilesStorageDir(filename);
|
const storageDir = getPdfFilesStorageDir(filename);
|
||||||
|
return path.join(global.__static_dirname, storageDir);
|
||||||
return path.join(global.__storage_dir, storageDir);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,23 +6,28 @@ import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ImportFileMeta {
|
export class ImportFileMeta {
|
||||||
|
/**
|
||||||
|
* @param {TransformerInjectable} transformer - Transformer injectable service.
|
||||||
|
* @param {TenancyContext} tenancyContext - Tenancy context service.
|
||||||
|
* @param {typeof ImportModel} importModel - Import model.
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transformer: TransformerInjectable,
|
private readonly transformer: TransformerInjectable,
|
||||||
private readonly tenancyContext: TenancyContext,
|
private readonly tenancyContext: TenancyContext,
|
||||||
|
|
||||||
@Inject(ImportModel.name)
|
@Inject(ImportModel.name)
|
||||||
private readonly importModel: () => typeof ImportModel,
|
private readonly importModel: typeof ImportModel,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the import meta of the given import model id.
|
* Retrieves the import meta of the given import model id.
|
||||||
* @param {number} importId
|
* @param {string} importId - Import id.
|
||||||
*/
|
*/
|
||||||
async getImportMeta(importId: string) {
|
async getImportMeta(importId: string) {
|
||||||
const tenant = await this.tenancyContext.getTenant();
|
const tenant = await this.tenancyContext.getTenant();
|
||||||
const tenantId = tenant.id;
|
const tenantId = tenant.id;
|
||||||
|
|
||||||
const importFile = await this.importModel()
|
const importFile = await this.importModel
|
||||||
.query()
|
.query()
|
||||||
.where('tenantId', tenantId)
|
.where('tenantId', tenantId)
|
||||||
.findOne('importId', importId);
|
.findOne('importId', importId);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Headers,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
@@ -13,12 +14,14 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PaymentReceivesApplication } from './PaymentReceived.application';
|
import { PaymentReceivesApplication } from './PaymentReceived.application';
|
||||||
import {
|
import {
|
||||||
IPaymentReceivedCreateDTO,
|
|
||||||
IPaymentReceivedEditDTO,
|
|
||||||
IPaymentsReceivedFilter,
|
IPaymentsReceivedFilter,
|
||||||
PaymentReceiveMailOptsDTO,
|
PaymentReceiveMailOptsDTO,
|
||||||
} from './types/PaymentReceived.types';
|
} from './types/PaymentReceived.types';
|
||||||
import { CreatePaymentReceivedDto, EditPaymentReceivedDto } from './dtos/PaymentReceived.dto';
|
import {
|
||||||
|
CreatePaymentReceivedDto,
|
||||||
|
EditPaymentReceivedDto,
|
||||||
|
} from './dtos/PaymentReceived.dto';
|
||||||
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
|
|
||||||
@Controller('payments-received')
|
@Controller('payments-received')
|
||||||
@ApiTags('payments-received')
|
@ApiTags('payments-received')
|
||||||
@@ -89,7 +92,9 @@ export class PaymentReceivesController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Retrieves the payment received list.' })
|
@ApiOperation({ summary: 'Retrieves the payment received list.' })
|
||||||
public getPaymentsReceived(@Query() filterDTO: Partial<IPaymentsReceivedFilter>) {
|
public getPaymentsReceived(
|
||||||
|
@Query() filterDTO: Partial<IPaymentsReceivedFilter>,
|
||||||
|
) {
|
||||||
return this.paymentReceivesApplication.getPaymentsReceived(filterDTO);
|
return this.paymentReceivesApplication.getPaymentsReceived(filterDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,21 +132,16 @@ export class PaymentReceivesController {
|
|||||||
})
|
})
|
||||||
public getPaymentReceive(
|
public getPaymentReceive(
|
||||||
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
||||||
|
@Headers('accept') acceptHeader: string,
|
||||||
) {
|
) {
|
||||||
return this.paymentReceivesApplication.getPaymentReceive(paymentReceiveId);
|
if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/pdf')
|
|
||||||
@ApiOperation({ summary: 'Retrieves the payment received pdf.' })
|
|
||||||
@ApiResponse({
|
|
||||||
status: 200,
|
|
||||||
description: 'The payment received pdf has been successfully retrieved.',
|
|
||||||
})
|
|
||||||
public getPaymentReceivePdf(
|
|
||||||
@Param('id', ParseIntPipe) paymentReceivedId: number,
|
|
||||||
) {
|
|
||||||
return this.paymentReceivesApplication.getPaymentReceivePdf(
|
return this.paymentReceivesApplication.getPaymentReceivePdf(
|
||||||
paymentReceivedId,
|
paymentReceiveId,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return this.paymentReceivesApplication.getPaymentReceive(
|
||||||
|
paymentReceiveId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Headers,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
|
Res,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SaleEstimatesApplication } from './SaleEstimates.application';
|
import { SaleEstimatesApplication } from './SaleEstimates.application';
|
||||||
import {
|
import {
|
||||||
@@ -21,6 +23,8 @@ import {
|
|||||||
CreateSaleEstimateDto,
|
CreateSaleEstimateDto,
|
||||||
EditSaleEstimateDto,
|
EditSaleEstimateDto,
|
||||||
} from './dtos/SaleEstimate.dto';
|
} from './dtos/SaleEstimate.dto';
|
||||||
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
|
import { Response } from 'express';
|
||||||
|
|
||||||
@Controller('sale-estimates')
|
@Controller('sale-estimates')
|
||||||
@ApiTags('sale-estimates')
|
@ApiTags('sale-estimates')
|
||||||
@@ -184,18 +188,6 @@ export class SaleEstimatesController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/pdf')
|
|
||||||
@ApiOperation({ summary: 'Retrieves the sale estimate PDF.' })
|
|
||||||
@ApiParam({
|
|
||||||
name: 'id',
|
|
||||||
required: true,
|
|
||||||
type: Number,
|
|
||||||
description: 'The sale estimate id',
|
|
||||||
})
|
|
||||||
public getSaleEstimatePdf(@Param('id', ParseIntPipe) saleEstimateId: number) {
|
|
||||||
return this.saleEstimatesApplication.getSaleEstimatePdf(saleEstimateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post(':id/mail')
|
@Post(':id/mail')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@ApiOperation({ summary: 'Send the given sale estimate by mail.' })
|
@ApiOperation({ summary: 'Send the given sale estimate by mail.' })
|
||||||
@@ -237,7 +229,22 @@ export class SaleEstimatesController {
|
|||||||
type: Number,
|
type: Number,
|
||||||
description: 'The sale estimate id',
|
description: 'The sale estimate id',
|
||||||
})
|
})
|
||||||
public getSaleEstimate(@Param('id', ParseIntPipe) estimateId: number) {
|
public async getSaleEstimate(
|
||||||
|
@Param('id', ParseIntPipe) estimateId: number,
|
||||||
|
@Headers('accept') acceptHeader: string,
|
||||||
|
@Res() res: Response,
|
||||||
|
) {
|
||||||
|
if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
|
||||||
|
const pdfContent =
|
||||||
|
await this.saleEstimatesApplication.getSaleEstimatePdf(estimateId);
|
||||||
|
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
} else {
|
||||||
return this.saleEstimatesApplication.getSaleEstimate(estimateId);
|
return this.saleEstimatesApplication.getSaleEstimate(estimateId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
|
import { Response } from 'express';
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Headers,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
|
Res,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ISaleInvoiceWriteoffDTO,
|
ISaleInvoiceWriteoffDTO,
|
||||||
@@ -29,6 +32,7 @@ import {
|
|||||||
CreateSaleInvoiceDto,
|
CreateSaleInvoiceDto,
|
||||||
EditSaleInvoiceDto,
|
EditSaleInvoiceDto,
|
||||||
} from './dtos/SaleInvoice.dto';
|
} from './dtos/SaleInvoice.dto';
|
||||||
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
|
|
||||||
@Controller('sale-invoices')
|
@Controller('sale-invoices')
|
||||||
@ApiTags('sale-invoices')
|
@ApiTags('sale-invoices')
|
||||||
@@ -154,9 +158,23 @@ export class SaleInvoicesController {
|
|||||||
type: Number,
|
type: Number,
|
||||||
description: 'The sale invoice id',
|
description: 'The sale invoice id',
|
||||||
})
|
})
|
||||||
getSaleInvoice(@Param('id', ParseIntPipe) id: number) {
|
async getSaleInvoice(
|
||||||
|
@Param('id', ParseIntPipe) id: number,
|
||||||
|
@Headers('accept') acceptHeader: string,
|
||||||
|
@Res({ passthrough: true }) res: Response,
|
||||||
|
) {
|
||||||
|
if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
|
||||||
|
const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf(id);
|
||||||
|
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
} else {
|
||||||
return this.saleInvoiceApplication.getSaleInvoice(id);
|
return this.saleInvoiceApplication.getSaleInvoice(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Retrieves the sale invoices.' })
|
@ApiOperation({ summary: 'Retrieves the sale invoices.' })
|
||||||
@@ -239,19 +257,6 @@ export class SaleInvoicesController {
|
|||||||
return this.saleInvoiceApplication.getInvoicePayments(id);
|
return this.saleInvoiceApplication.getInvoicePayments(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/pdf')
|
|
||||||
@ApiOperation({ summary: 'Retrieves the sale invoice PDF.' })
|
|
||||||
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
|
|
||||||
@ApiParam({
|
|
||||||
name: 'id',
|
|
||||||
required: true,
|
|
||||||
type: Number,
|
|
||||||
description: 'The sale invoice id',
|
|
||||||
})
|
|
||||||
saleInvoicePdf(@Param('id', ParseIntPipe) id: number) {
|
|
||||||
return this.saleInvoiceApplication.saleInvoicePdf(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/html')
|
@Get(':id/html')
|
||||||
@ApiOperation({ summary: 'Retrieves the sale invoice HTML.' })
|
@ApiOperation({ summary: 'Retrieves the sale invoice HTML.' })
|
||||||
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
|
@ApiResponse({ status: 404, description: 'The sale invoice not found.' })
|
||||||
|
|||||||
@@ -105,11 +105,9 @@ export class SaleReceiptApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the given sale receipt pdf.
|
* Retrieves the given sale receipt pdf.
|
||||||
* @param {number} tenantId
|
|
||||||
* @param {number} saleReceiptId
|
* @param {number} saleReceiptId
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
public getSaleReceiptPdf(tenantId: number, saleReceiptId: number) {
|
public getSaleReceiptPdf(saleReceiptId: number) {
|
||||||
return this.getSaleReceiptPdfService.saleReceiptPdf(saleReceiptId);
|
return this.getSaleReceiptPdfService.saleReceiptPdf(saleReceiptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,24 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Headers,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
|
Res,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
||||||
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateSaleReceiptDto,
|
CreateSaleReceiptDto,
|
||||||
EditSaleReceiptDto,
|
EditSaleReceiptDto,
|
||||||
} from './dtos/SaleReceipt.dto';
|
} from './dtos/SaleReceipt.dto';
|
||||||
import { ISalesReceiptsFilter } from './types/SaleReceipts.types';
|
import { ISalesReceiptsFilter } from './types/SaleReceipts.types';
|
||||||
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
|
import { Response } from 'express';
|
||||||
|
|
||||||
@Controller('sale-receipts')
|
@Controller('sale-receipts')
|
||||||
@ApiTags('sale-receipts')
|
@ApiTags('sale-receipts')
|
||||||
@@ -72,15 +76,35 @@ export class SaleReceiptsController {
|
|||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiOperation({ summary: 'Retrieves the sale receipt details.' })
|
@ApiOperation({ summary: 'Retrieves the sale receipt details.' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'The sale receipt details have been successfully retrieved.',
|
||||||
|
})
|
||||||
|
@ApiResponse({ status: 404, description: 'The sale receipt not found.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
required: true,
|
required: true,
|
||||||
type: Number,
|
type: Number,
|
||||||
description: 'The sale receipt id',
|
description: 'The sale receipt id',
|
||||||
})
|
})
|
||||||
getSaleReceipt(@Param('id', ParseIntPipe) id: number) {
|
async getSaleReceipt(
|
||||||
|
@Param('id', ParseIntPipe) id: number,
|
||||||
|
@Headers('accept') acceptHeader: string,
|
||||||
|
@Res({ passthrough: true }) res: Response,
|
||||||
|
) {
|
||||||
|
if (acceptHeader.includes(AcceptType.ApplicationPdf)) {
|
||||||
|
const pdfContent =
|
||||||
|
await this.saleReceiptApplication.getSaleReceiptPdf(id);
|
||||||
|
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
} else {
|
||||||
return this.saleReceiptApplication.getSaleReceipt(id);
|
return this.saleReceiptApplication.getSaleReceipt(id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Retrieves the sale receipts paginated list' })
|
@ApiOperation({ summary: 'Retrieves the sale receipts paginated list' })
|
||||||
@@ -112,18 +136,6 @@ export class SaleReceiptsController {
|
|||||||
return this.saleReceiptApplication.closeSaleReceipt(id);
|
return this.saleReceiptApplication.closeSaleReceipt(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/pdf')
|
|
||||||
@ApiOperation({ summary: 'Retrieves the sale receipt PDF.' })
|
|
||||||
@ApiParam({
|
|
||||||
name: 'id',
|
|
||||||
required: true,
|
|
||||||
type: Number,
|
|
||||||
description: 'The sale receipt id',
|
|
||||||
})
|
|
||||||
getSaleReceiptPdf(@Param('id', ParseIntPipe) id: number) {
|
|
||||||
return this.saleReceiptApplication.getSaleReceiptPdf(0, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('state')
|
@Get('state')
|
||||||
@ApiOperation({ summary: 'Retrieves the sale receipt state.' })
|
@ApiOperation({ summary: 'Retrieves the sale receipt state.' })
|
||||||
getSaleReceiptState() {
|
getSaleReceiptState() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
import pug from 'pug';
|
import * as pug from 'pug';
|
||||||
|
|
||||||
export function templateRender(filePath: string, options: Record<string, any>) {
|
export function templateRender(filePath: string, options: Record<string, any>) {
|
||||||
const basePath = path.join(global.__resources_dir, '/views');
|
const basePath = path.join(global.__resources_dir, '/views');
|
||||||
|
|||||||
Reference in New Issue
Block a user