mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: retrieve specific sale receipt details.
This commit is contained in:
@@ -53,6 +53,14 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
this.handleServiceErrors,
|
this.handleServiceErrors,
|
||||||
this.dynamicListService.handlerErrorsToResponse,
|
this.dynamicListService.handlerErrorsToResponse,
|
||||||
);
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id', [
|
||||||
|
...this.specificReceiptValidationSchema,
|
||||||
|
],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.getSaleReceipt.bind(this)),
|
||||||
|
this.handleServiceErrors,
|
||||||
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +222,27 @@ export default class SalesReceiptsController extends BaseController{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the sale receipt with associated entries.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
async getSaleReceipt(req: Request, res: Response, next: NextFunction) {
|
||||||
|
const { id: saleReceiptId } = req.params;
|
||||||
|
const { tenantId } = req;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const saleReceipt = await this.saleReceiptService.getSaleReceipt(tenantId, saleReceiptId);
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
sale_receipt: saleReceipt,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles service errors.
|
* Handles service errors.
|
||||||
* @param {Error} error
|
* @param {Error} error
|
||||||
|
|||||||
@@ -215,13 +215,20 @@ export default class SalesReceiptService {
|
|||||||
/**
|
/**
|
||||||
* Retrieve sale receipt with associated entries.
|
* Retrieve sale receipt with associated entries.
|
||||||
* @param {Integer} saleReceiptId
|
* @param {Integer} saleReceiptId
|
||||||
|
* @return {ISaleReceipt}
|
||||||
*/
|
*/
|
||||||
async getSaleReceiptWithEntries(tenantId: number, saleReceiptId: number) {
|
async getSaleReceipt(tenantId: number, saleReceiptId: number) {
|
||||||
const { SaleReceipt } = this.tenancy.models(tenantId);
|
const { SaleReceipt } = this.tenancy.models(tenantId);
|
||||||
const saleReceipt = await SaleReceipt.query()
|
|
||||||
.where('id', saleReceiptId)
|
|
||||||
.withGraphFetched('entries');
|
|
||||||
|
|
||||||
|
const saleReceipt = await SaleReceipt.query()
|
||||||
|
.findById(saleReceiptId)
|
||||||
|
.withGraphFetched('entries')
|
||||||
|
.withGraphFetched('customer')
|
||||||
|
.withGraphFetched('depositAccount');
|
||||||
|
|
||||||
|
if (!saleReceipt) {
|
||||||
|
throw new ServiceError(ERRORS.SALE_RECEIPT_NOT_FOUND);
|
||||||
|
}
|
||||||
return saleReceipt;
|
return saleReceipt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user