mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: universal search.
This commit is contained in:
@@ -19,14 +19,16 @@ export default class VendorsController extends ContactsController {
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.post('/', [
|
||||
...this.contactDTOSchema,
|
||||
...this.contactNewDTOSchema,
|
||||
...this.vendorDTOSchema,
|
||||
],
|
||||
router.post(
|
||||
'/',
|
||||
[
|
||||
...this.contactDTOSchema,
|
||||
...this.contactNewDTOSchema,
|
||||
...this.vendorDTOSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.newVendor.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.post(
|
||||
'/:id/opening_balance',
|
||||
@@ -37,36 +39,38 @@ export default class VendorsController extends ContactsController {
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.editOpeningBalanceVendor.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.post('/:id', [
|
||||
...this.contactDTOSchema,
|
||||
...this.contactEditDTOSchema,
|
||||
...this.vendorDTOSchema,
|
||||
],
|
||||
router.post(
|
||||
'/:id',
|
||||
[
|
||||
...this.contactDTOSchema,
|
||||
...this.contactEditDTOSchema,
|
||||
...this.vendorDTOSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.editVendor.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.delete('/:id', [
|
||||
...this.specificContactSchema,
|
||||
],
|
||||
router.delete(
|
||||
'/:id',
|
||||
[...this.specificContactSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deleteVendor.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.get('/:id', [
|
||||
...this.specificContactSchema,
|
||||
],
|
||||
router.get(
|
||||
'/:id',
|
||||
[...this.specificContactSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getVendor.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.get('/', [
|
||||
...this.vendorsListSchema,
|
||||
],
|
||||
router.get(
|
||||
'/',
|
||||
[...this.vendorsListSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getVendorsList.bind(this)),
|
||||
asyncMiddleware(this.getVendorsList.bind(this))
|
||||
);
|
||||
return router;
|
||||
}
|
||||
@@ -102,22 +106,26 @@ export default class VendorsController extends ContactsController {
|
||||
query('page_size').optional().isNumeric().toInt(),
|
||||
|
||||
query('inactive_mode').optional().isBoolean().toBoolean(),
|
||||
query('search_keyword').optional({ nullable: true }).isString().trim()
|
||||
query('search_keyword').optional({ nullable: true }).isString().trim(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new vendor.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async newVendor(req: Request, res: Response, next: NextFunction) {
|
||||
const contactDTO: IVendorNewDTO = this.matchedBodyData(req);
|
||||
const { tenantId, user } = req;
|
||||
|
||||
try {
|
||||
const vendor = await this.vendorsService.newVendor(tenantId, contactDTO, user);
|
||||
const vendor = await this.vendorsService.newVendor(
|
||||
tenantId,
|
||||
contactDTO,
|
||||
user
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
id: vendor.id,
|
||||
@@ -130,9 +138,9 @@ export default class VendorsController extends ContactsController {
|
||||
|
||||
/**
|
||||
* Edits the given vendor details.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async editVendor(req: Request, res: Response, next: NextFunction) {
|
||||
const contactDTO: IVendorEditDTO = this.matchedBodyData(req);
|
||||
@@ -140,7 +148,12 @@ export default class VendorsController extends ContactsController {
|
||||
const { id: contactId } = req.params;
|
||||
|
||||
try {
|
||||
await this.vendorsService.editVendor(tenantId, contactId, contactDTO, user);
|
||||
await this.vendorsService.editVendor(
|
||||
tenantId,
|
||||
contactId,
|
||||
contactDTO,
|
||||
user
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
id: contactId,
|
||||
@@ -157,24 +170,26 @@ export default class VendorsController extends ContactsController {
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async editOpeningBalanceVendor(req: Request, res: Response, next: NextFunction) {
|
||||
async editOpeningBalanceVendor(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: vendorId } = req.params;
|
||||
const {
|
||||
openingBalance,
|
||||
openingBalanceAt,
|
||||
} = this.matchedBodyData(req);
|
||||
const { openingBalance, openingBalanceAt } = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
await this.vendorsService.changeOpeningBalance(
|
||||
tenantId,
|
||||
vendorId,
|
||||
openingBalance,
|
||||
openingBalanceAt,
|
||||
openingBalanceAt
|
||||
);
|
||||
return res.status(200).send({
|
||||
id: vendorId,
|
||||
message: 'The opening balance of the given vendor has been changed successfully.',
|
||||
message:
|
||||
'The opening balance of the given vendor has been changed successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -183,16 +198,16 @@ export default class VendorsController extends ContactsController {
|
||||
|
||||
/**
|
||||
* Deletes the given vendor from the storage.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async deleteVendor(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: contactId } = req.params;
|
||||
|
||||
try {
|
||||
await this.vendorsService.deleteVendor(tenantId, contactId, user)
|
||||
await this.vendorsService.deleteVendor(tenantId, contactId, user);
|
||||
|
||||
return res.status(200).send({
|
||||
id: contactId,
|
||||
@@ -205,18 +220,21 @@ export default class VendorsController extends ContactsController {
|
||||
|
||||
/**
|
||||
* Retrieve details of the given vendor id.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async getVendor(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, user } = req;
|
||||
const { id: vendorId } = req.params;
|
||||
|
||||
try {
|
||||
const vendor = await this.vendorsService.getVendor(tenantId, vendorId, user)
|
||||
|
||||
return res.status(200).send({ vendor });
|
||||
const vendor = await this.vendorsService.getVendor(
|
||||
tenantId,
|
||||
vendorId,
|
||||
user
|
||||
);
|
||||
return res.status(200).send(this.transfromToResponse({ vendor }));
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -224,9 +242,9 @@ export default class VendorsController extends ContactsController {
|
||||
|
||||
/**
|
||||
* Retrieve vendors datatable list.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async getVendorsList(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
@@ -241,14 +259,11 @@ export default class VendorsController extends ContactsController {
|
||||
};
|
||||
|
||||
try {
|
||||
const {
|
||||
vendors,
|
||||
pagination,
|
||||
filterMeta,
|
||||
} = await this.vendorsService.getVendorsList(tenantId, vendorsFilter);
|
||||
const { vendors, pagination, filterMeta } =
|
||||
await this.vendorsService.getVendorsList(tenantId, vendorsFilter);
|
||||
|
||||
return res.status(200).send({
|
||||
vendors,
|
||||
vendors: this.transfromToResponse(vendors),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
@@ -259,7 +274,7 @@ export default class VendorsController extends ContactsController {
|
||||
|
||||
/**
|
||||
* Handle service errors.
|
||||
* @param {Error} error -
|
||||
* @param {Error} error -
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
@@ -289,4 +304,4 @@ export default class VendorsController extends ContactsController {
|
||||
}
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { IExpenseDTO } from 'interfaces';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import { DATATYPES_LENGTH } from 'data/DataTypes';
|
||||
import HasItemEntries from 'services/Sales/HasItemsEntries';
|
||||
|
||||
@Service()
|
||||
export default class ExpensesController extends BaseController {
|
||||
@@ -304,7 +305,7 @@ export default class ExpensesController extends BaseController {
|
||||
await this.expensesService.getExpensesList(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
expenses,
|
||||
expenses: this.transfromToResponse(expenses),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
@@ -328,7 +329,7 @@ export default class ExpensesController extends BaseController {
|
||||
tenantId,
|
||||
expenseId
|
||||
);
|
||||
return res.status(200).send({ expense });
|
||||
return res.status(200).send(this.transfromToResponse({ expense }));
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ export default class ItemsController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate list query schema
|
||||
* Validate list query schema.
|
||||
*/
|
||||
get validateListQuerySchema() {
|
||||
return [
|
||||
|
||||
@@ -221,7 +221,7 @@ export default class ManualJournalsController extends BaseController {
|
||||
manualJournalId
|
||||
);
|
||||
return res.status(200).send({
|
||||
manual_journal: manualJournal,
|
||||
manual_journal: this.transfromToResponse(manualJournal),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -301,7 +301,7 @@ export default class ManualJournalsController extends BaseController {
|
||||
} = await this.manualJournalsService.getManualJournals(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
manual_journals: manualJournals,
|
||||
manual_journals: this.transfromToResponse(manualJournals),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
|
||||
@@ -264,7 +264,7 @@ export default class BillsController extends BaseController {
|
||||
try {
|
||||
const bill = await this.billsService.getBill(tenantId, billId);
|
||||
|
||||
return res.status(200).send({ bill });
|
||||
return res.status(200).send(this.transfromToResponse({ bill }));
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -312,7 +312,7 @@ export default class BillsController extends BaseController {
|
||||
await this.billsService.getBills(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
bills,
|
||||
bills: this.transfromToResponse(bills),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
|
||||
@@ -335,7 +335,7 @@ export default class BillsPayments extends BaseController {
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payments: billPayments,
|
||||
bill_payments: this.transfromToResponse(billPayments),
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
|
||||
@@ -302,6 +302,10 @@ export default class SalesEstimatesController extends BaseController {
|
||||
);
|
||||
// Response formatter.
|
||||
res.format({
|
||||
// JSON content type.
|
||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
||||
return res.status(200).send(this.transfromToResponse({ estimate }));
|
||||
},
|
||||
// PDF content type.
|
||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
||||
const pdfContent = await this.saleEstimatesPdf.saleEstimatePdf(
|
||||
@@ -314,10 +318,6 @@ export default class SalesEstimatesController extends BaseController {
|
||||
});
|
||||
res.send(pdfContent);
|
||||
},
|
||||
// JSON content type.
|
||||
default: () => {
|
||||
return res.status(200).send(this.transfromToResponse({ estimate }));
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -277,6 +277,10 @@ export default class SaleInvoicesController extends BaseController {
|
||||
);
|
||||
// Response formatter.
|
||||
res.format({
|
||||
// JSON content type.
|
||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
||||
return res.status(200).send(this.transfromToResponse({ saleInvoice }));
|
||||
},
|
||||
// PDF content type.
|
||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
||||
const pdfContent = await this.saleInvoicePdf.saleInvoicePdf(
|
||||
@@ -289,10 +293,6 @@ export default class SaleInvoicesController extends BaseController {
|
||||
});
|
||||
res.send(pdfContent);
|
||||
},
|
||||
// JSON content type.
|
||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
||||
return res.status(200).send(this.transfromToResponse({ saleInvoice }));
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -243,11 +243,13 @@ export default class SalesReceiptsController extends BaseController {
|
||||
};
|
||||
|
||||
try {
|
||||
const { salesReceipts, pagination, filterMeta } =
|
||||
const { data, pagination, filterMeta } =
|
||||
await this.saleReceiptService.salesReceiptsList(tenantId, filter);
|
||||
|
||||
const response = this.transfromToResponse({
|
||||
salesReceipts, pagination, filterMeta
|
||||
data,
|
||||
pagination,
|
||||
filterMeta,
|
||||
});
|
||||
return res.status(200).send(response);
|
||||
} catch (error) {
|
||||
@@ -272,6 +274,11 @@ export default class SalesReceiptsController extends BaseController {
|
||||
);
|
||||
|
||||
res.format({
|
||||
'application/json': () => {
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transfromToResponse({ saleReceipt }));
|
||||
},
|
||||
'application/pdf': async () => {
|
||||
const pdfContent = await this.saleReceiptsPdf.saleReceiptPdf(
|
||||
tenantId,
|
||||
@@ -283,10 +290,7 @@ export default class SalesReceiptsController extends BaseController {
|
||||
});
|
||||
res.send(pdfContent);
|
||||
},
|
||||
'application/json': () => {
|
||||
return res.status(200).send(this.transfromToResponse({ saleReceipt }));
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user