mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
Merge branch 'develop' into stripe-integrate
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { check, param, query } from 'express-validator';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import BaseController from '@/api/controllers/BaseController';
|
||||
import { PdfTemplateApplication } from '@/services/PdfTemplate/PdfTemplateApplication';
|
||||
|
||||
@Service()
|
||||
export class PdfTemplatesController extends BaseController {
|
||||
@Inject()
|
||||
public pdfTemplateApplication: PdfTemplateApplication;
|
||||
|
||||
/**
|
||||
* Router constructor method.
|
||||
*/
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.delete(
|
||||
'/:template_id',
|
||||
[param('template_id').exists().isInt().toInt()],
|
||||
this.validationResult,
|
||||
this.deletePdfTemplate.bind(this)
|
||||
);
|
||||
router.post(
|
||||
'/:template_id',
|
||||
[
|
||||
param('template_id').exists().isInt().toInt(),
|
||||
check('template_name').exists(),
|
||||
check('attributes').exists(),
|
||||
],
|
||||
this.validationResult,
|
||||
this.editPdfTemplate.bind(this)
|
||||
);
|
||||
router.get(
|
||||
'/',
|
||||
[query('resource').optional()],
|
||||
this.validationResult,
|
||||
this.getPdfTemplates.bind(this)
|
||||
);
|
||||
router.get(
|
||||
'/:template_id',
|
||||
[param('template_id').exists().isInt().toInt()],
|
||||
this.validationResult,
|
||||
this.getPdfTemplate.bind(this)
|
||||
);
|
||||
router.post(
|
||||
'/',
|
||||
[
|
||||
check('template_name').exists(),
|
||||
check('resource').exists(),
|
||||
check('attributes').exists(),
|
||||
],
|
||||
this.validationResult,
|
||||
this.createPdfInvoiceTemplate.bind(this)
|
||||
);
|
||||
router.post(
|
||||
'/:template_id/assign_default',
|
||||
[param('template_id').exists().isInt().toInt()],
|
||||
this.validationResult,
|
||||
this.assginPdfTemplateAsDefault.bind(this)
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
async createPdfInvoiceTemplate(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { templateName, resource, attributes } = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
const result = await this.pdfTemplateApplication.createPdfTemplate(
|
||||
tenantId,
|
||||
templateName,
|
||||
resource,
|
||||
attributes
|
||||
);
|
||||
return res.status(201).send({
|
||||
id: result.id,
|
||||
message: 'The PDF template has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async editPdfTemplate(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { template_id: templateId } = req.params;
|
||||
const editTemplateDTO = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
const result = await this.pdfTemplateApplication.editPdfTemplate(
|
||||
tenantId,
|
||||
Number(templateId),
|
||||
editTemplateDTO
|
||||
);
|
||||
return res.status(200).send({
|
||||
id: result.id,
|
||||
message: 'The PDF template has been updated successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async deletePdfTemplate(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { template_id: templateId } = req.params;
|
||||
|
||||
try {
|
||||
await this.pdfTemplateApplication.deletePdfTemplate(
|
||||
tenantId,
|
||||
Number(templateId)
|
||||
);
|
||||
return res.status(204).send({
|
||||
id: templateId,
|
||||
message: 'The PDF template has been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getPdfTemplate(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { template_id: templateId } = req.params;
|
||||
|
||||
try {
|
||||
const template = await this.pdfTemplateApplication.getPdfTemplate(
|
||||
tenantId,
|
||||
Number(templateId)
|
||||
);
|
||||
return res.status(200).send(template);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getPdfTemplates(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const query = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const templates = await this.pdfTemplateApplication.getPdfTemplates(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
return res.status(200).send(templates);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async assginPdfTemplateAsDefault(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { template_id: templateId } = req.params;
|
||||
|
||||
try {
|
||||
await this.pdfTemplateApplication.assignPdfTemplateAsDefault(
|
||||
tenantId,
|
||||
Number(templateId)
|
||||
);
|
||||
return res.status(204).send({
|
||||
id: templateId,
|
||||
message: 'The given pdf template has been assigned as default template',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,9 @@ export default class PaymentReceivesController extends BaseController {
|
||||
|
||||
check('attachments').isArray().optional(),
|
||||
check('attachments.*.key').exists().isString(),
|
||||
|
||||
// Pdf template id.
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -167,6 +167,9 @@ export default class PaymentReceivesController extends BaseController {
|
||||
|
||||
check('attachments').isArray().optional(),
|
||||
check('attachments.*.key').exists().isString(),
|
||||
|
||||
// Pdf template id.
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -168,9 +168,7 @@ export default class SalesEstimatesController extends BaseController {
|
||||
check('entries.*.item_id').exists().isNumeric().toInt(),
|
||||
check('entries.*.quantity').exists().isNumeric().toInt(),
|
||||
check('entries.*.rate').exists().isNumeric().toFloat(),
|
||||
check('entries.*.description')
|
||||
.optional({ nullable: true })
|
||||
.trim(),
|
||||
check('entries.*.description').optional({ nullable: true }).trim(),
|
||||
check('entries.*.discount')
|
||||
.optional({ nullable: true })
|
||||
.isNumeric()
|
||||
@@ -186,6 +184,9 @@ export default class SalesEstimatesController extends BaseController {
|
||||
|
||||
check('attachments').isArray().optional(),
|
||||
check('attachments.*.key').exists().isString(),
|
||||
|
||||
// Pdf template id.
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -224,9 +224,7 @@ export default class SaleInvoicesController extends BaseController {
|
||||
.optional({ nullable: true })
|
||||
.isNumeric()
|
||||
.toFloat(),
|
||||
check('entries.*.description')
|
||||
.optional({ nullable: true })
|
||||
.trim(),
|
||||
check('entries.*.description').optional({ nullable: true }).trim(),
|
||||
check('entries.*.tax_code')
|
||||
.optional({ nullable: true })
|
||||
.trim()
|
||||
@@ -257,6 +255,9 @@ export default class SaleInvoicesController extends BaseController {
|
||||
.optional({ nullable: true })
|
||||
.isNumeric()
|
||||
.toFloat(),
|
||||
|
||||
// Pdf template id.
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -148,17 +148,20 @@ export default class SalesReceiptsController extends BaseController {
|
||||
.optional({ nullable: true })
|
||||
.isNumeric()
|
||||
.toInt(),
|
||||
check('entries.*.description')
|
||||
.optional({ nullable: true })
|
||||
.trim(),
|
||||
check('entries.*.description').optional({ nullable: true }).trim(),
|
||||
check('entries.*.warehouse_id')
|
||||
.optional({ nullable: true })
|
||||
.isNumeric()
|
||||
.toInt(),
|
||||
|
||||
check('receipt_message').optional().trim(),
|
||||
|
||||
check('statement').optional().trim(),
|
||||
check('attachments').isArray().optional(),
|
||||
check('attachments.*.key').exists().isString(),
|
||||
|
||||
// Pdf template id.
|
||||
check('pdf_template_id').optional({ nullable: true }).isNumeric().toInt(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user