BIG-60: fix response [object] when delete any sale estimate.

This commit is contained in:
a.bouhuolia
2021-09-13 19:35:42 +02:00
parent 1bcd55e794
commit aabcf71621
3 changed files with 27 additions and 15 deletions

View File

@@ -413,11 +413,6 @@ export default class SalesEstimatesController extends BaseController {
errors: [{ type: 'NOT_SELL_ABLE_ITEMS', code: 800 }], errors: [{ type: 'NOT_SELL_ABLE_ITEMS', code: 800 }],
}); });
} }
if (error.errorType === 'SALE_ESTIMATE_ALREADY_APPROVED') {
return res.boom.badRequest(null, {
errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 900 }],
});
}
if (error.errorType === 'SALE_ESTIMATE_ALREADY_APPROVED') { if (error.errorType === 'SALE_ESTIMATE_ALREADY_APPROVED') {
return res.boom.badRequest(null, { return res.boom.badRequest(null, {
errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 1000 }], errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 1000 }],
@@ -443,6 +438,16 @@ export default class SalesEstimatesController extends BaseController {
errors: [{ type: 'SALE_ESTIMATE_NO_IS_REQUIRED', code: 1400 }], errors: [{ type: 'SALE_ESTIMATE_NO_IS_REQUIRED', code: 1400 }],
}); });
} }
if (error.errorType === 'SALE_ESTIMATE_CONVERTED_TO_INVOICE') {
return res.boom.badRequest(null, {
errors: [{ type: 'SALE_ESTIMATE_CONVERTED_TO_INVOICE', code: 1500 }],
});
}
if (error.errorType === 'SALE_ESTIMATE_ALREADY_DELIVERED') {
return res.boom.badRequest(null, {
errors: [{ type: 'SALE_ESTIMATE_ALREADY_DELIVERED', code: 1600 }],
});
}
} }
next(error); next(error);
} }

View File

@@ -1,3 +1,16 @@
export const ERRORS = {
SALE_ESTIMATE_NOT_FOUND: 'SALE_ESTIMATE_NOT_FOUND',
SALE_ESTIMATE_NUMBER_EXISTANCE: 'SALE_ESTIMATE_NUMBER_EXISTANCE',
SALE_ESTIMATE_CONVERTED_TO_INVOICE: 'SALE_ESTIMATE_CONVERTED_TO_INVOICE',
SALE_ESTIMATE_NOT_DELIVERED: 'SALE_ESTIMATE_NOT_DELIVERED',
SALE_ESTIMATE_ALREADY_REJECTED: 'SALE_ESTIMATE_ALREADY_REJECTED',
CUSTOMER_HAS_SALES_ESTIMATES: 'CUSTOMER_HAS_SALES_ESTIMATES',
SALE_ESTIMATE_NO_IS_REQUIRED: 'SALE_ESTIMATE_NO_IS_REQUIRED',
SALE_ESTIMATE_ALREADY_DELIVERED: 'SALE_ESTIMATE_ALREADY_DELIVERED',
SALE_ESTIMATE_ALREADY_APPROVED: 'SALE_ESTIMATE_ALREADY_APPROVED'
};
export const DEFAULT_VIEW_COLUMNS = []; export const DEFAULT_VIEW_COLUMNS = [];
export const DEFAULT_VIEWS = [ export const DEFAULT_VIEWS = [
{ {

View File

@@ -22,8 +22,8 @@ import { ServiceError } from 'exceptions';
import CustomersService from 'services/Contacts/CustomersService'; import CustomersService from 'services/Contacts/CustomersService';
import moment from 'moment'; import moment from 'moment';
import AutoIncrementOrdersService from './AutoIncrementOrdersService'; import AutoIncrementOrdersService from './AutoIncrementOrdersService';
import { ERRORS } from './constants';
import SaleEstimateTransformer from './Estimates/SaleEstimateTransformer'; import SaleEstimateTransformer from './Estimates/SaleEstimateTransformer';
import { ERRORS } from './Estimates/constants';
/** /**
* Sale estimate service. * Sale estimate service.
@@ -355,26 +355,20 @@ export default class SaleEstimateService implements ISalesEstimatesService{
tenantId, tenantId,
estimateId estimateId
); );
// Throw error if the sale estimate converted to sale invoice. // Throw error if the sale estimate converted to sale invoice.
if (oldSaleEstimate.convertedToInvoiceId) { if (oldSaleEstimate.convertedToInvoiceId) {
throw new ServiceError(ERRORS.SALE_ESTIMATE_CONVERTED_TO_INVOICE); throw new ServiceError(ERRORS.SALE_ESTIMATE_CONVERTED_TO_INVOICE);
} }
// Delete sale estimate entries.
this.logger.info(
'[sale_estimate] delete sale estimate and associated entries from the storage.'
);
await ItemEntry.query() await ItemEntry.query()
.where('reference_id', estimateId) .where('reference_id', estimateId)
.where('reference_type', 'SaleEstimate') .where('reference_type', 'SaleEstimate')
.delete(); .delete();
// Delete sale estimate transaction.
await SaleEstimate.query().where('id', estimateId).delete(); await SaleEstimate.query().where('id', estimateId).delete();
this.logger.info('[sale_estimate] deleted successfully.', {
tenantId,
estimateId,
});
// Triggers `onSaleEstimatedDeleted` event.
await this.eventDispatcher.dispatch(events.saleEstimate.onDeleted, { await this.eventDispatcher.dispatch(events.saleEstimate.onDeleted, {
tenantId, tenantId,
saleEstimateId: estimateId, saleEstimateId: estimateId,