fix: subtitle issue with sales transaction number.

This commit is contained in:
Ahmed Bouhuolia
2020-11-24 11:33:29 +02:00
parent 218d90c571
commit 9779591029
24 changed files with 218 additions and 76 deletions

View File

@@ -1,4 +1,4 @@
import { check, param, query, ValidationChain } from 'express-validator';
import { check, param, query, body, ValidationChain } from 'express-validator';
import BaseController from "api/controllers/BaseController";
export default class ContactsController extends BaseController {
@@ -48,7 +48,8 @@ export default class ContactsController extends BaseController {
*/
get contactNewDTOSchema(): ValidationChain[] {
return [
check('balance').optional().isNumeric().toInt(),
check('opening_balance').optional({ nullable: true }).isNumeric().toInt(),
body('opening_balance_at').if(body('opening_balance').exists()).exists(),
];
}

View File

@@ -90,9 +90,6 @@ export default class CustomersController extends ContactsController {
*/
get createCustomerDTOSchema() {
return [
check('opening_balance').optional({ nullable: true }).isNumeric().toInt(),
check('opening_balance_at').optional({ nullable: true }).isISO8601(),
check('currency_code').optional().trim().escape(),
];
}

View File

@@ -1,6 +1,7 @@
import { Request, Response, Router, NextFunction } from 'express';
import { Service, Inject } from 'typedi';
import { check, query, ValidationChain } from 'express-validator';
import { body, query, ValidationChain, check } from 'express-validator';
import ContactsController from 'api/controllers/Contacts/Contacts';
import VendorsService from 'services/Contacts/VendorsService';
import { ServiceError } from 'exceptions';
@@ -72,7 +73,7 @@ export default class VendorsController extends ContactsController {
*/
get vendorDTOSchema(): ValidationChain[] {
return [
check('opening_balance').optional().isNumeric().toInt(),
check('currency_code').optional().trim().escape(),
];
}
@@ -105,7 +106,11 @@ export default class VendorsController extends ContactsController {
try {
const vendor = await this.vendorsService.newVendor(tenantId, contactDTO);
return res.status(200).send({ id: vendor.id });
return res.status(200).send({
id: vendor.id,
message: 'The vendor has been created successfully.',
});
} catch (error) {
next(error);
}
@@ -124,7 +129,11 @@ export default class VendorsController extends ContactsController {
try {
await this.vendorsService.editVendor(tenantId, contactId, contactDTO);
return res.status(200).send({ id: contactId });
return res.status(200).send({
id: contactId,
message: 'The vendor has been edited successfully.',
});
} catch (error) {
next(error);
}
@@ -142,7 +151,11 @@ export default class VendorsController extends ContactsController {
try {
await this.vendorsService.deleteVendor(tenantId, contactId)
return res.status(200).send({ id: contactId });
return res.status(200).send({
id: contactId,
message: 'The vendor has been deleted successfully.',
});
} catch (error) {
next(error);
}
@@ -198,7 +211,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,
@@ -219,21 +236,27 @@ export default class VendorsController extends ContactsController {
*/
handlerServiceErrors(error, req: Request, res: Response, next: NextFunction) {
if (error instanceof ServiceError) {
if (error.errorType === 'contact_not_found') {
return res.boom.badRequest(null, {
errors: [{ type: 'VENDOR.NOT.FOUND', code: 100 }],
});
}
if (error.errorType === 'contacts_not_found') {
return res.boom.badRequest(null, {
errors: [{ type: 'VENDORS.NOT.FOUND', code: 100 }],
errors: [{ type: 'VENDORS.NOT.FOUND', code: 200 }],
});
}
if (error.errorType === 'some_vendors_have_bills') {
return res.boom.badRequest(null, {
errors: [{ type: 'SOME.VENDORS.HAVE.BILLS', code: 200 }],
errors: [{ type: 'SOME.VENDORS.HAVE.BILLS', code: 300 }],
});
}
if (error.errorType === 'vendor_has_bills') {
return res.status(400).send({
errors: [{ type: 'VENDOR.HAS.BILLS', code: 200 }],
errors: [{ type: 'VENDOR.HAS.BILLS', code: 400 }],
});
}
}
next(error);
}
}

View File

@@ -84,7 +84,7 @@ export default class PaymentReceivesController extends BaseController {
check('payment_date').exists(),
check('reference_no').optional(),
check('deposit_account_id').exists().isNumeric().toInt(),
check('payment_receive_no').exists().trim().escape(),
check('payment_receive_no').optional({ nullable: true }).trim().escape(),
check('statement').optional().trim().escape(),
check('entries').isArray({ min: 1 }),