fix: delete manual journals in bulk.

This commit is contained in:
Ahmed Bouhuolia
2020-11-29 20:41:15 +02:00
parent 0f672e788e
commit 0acc998283
2 changed files with 16 additions and 10 deletions

View File

@@ -128,6 +128,7 @@ export default class ManualJournalsController extends BaseController {
.isLength({ max: DATATYPES_LENGTH.STRING }), .isLength({ max: DATATYPES_LENGTH.STRING }),
check('reference') check('reference')
.optional({ nullable: true }) .optional({ nullable: true })
.isString()
.trim() .trim()
.escape() .escape()
.isLength({ max: DATATYPES_LENGTH.STRING }), .isLength({ max: DATATYPES_LENGTH.STRING }),
@@ -144,15 +145,11 @@ export default class ManualJournalsController extends BaseController {
.isInt({ max: DATATYPES_LENGTH.INT_10 }).toInt(), .isInt({ max: DATATYPES_LENGTH.INT_10 }).toInt(),
check('entries.*.credit') check('entries.*.credit')
.optional({ nullable: true }) .optional({ nullable: true })
.isNumeric() .isFloat({ min: 0, max: DATATYPES_LENGTH.DECIMAL_13_3 })
.isDecimal()
.isFloat({ max: DATATYPES_LENGTH.INT_13_3 }) // 13, 3
.toFloat(), .toFloat(),
check('entries.*.debit') check('entries.*.debit')
.optional({ nullable: true }) .optional({ nullable: true })
.isNumeric() .isFloat({ min: 0, max: DATATYPES_LENGTH.DECIMAL_13_3 })
.isDecimal()
.isFloat({ max: DATATYPES_LENGTH.INT_13_3 }) // 13, 3
.toFloat(), .toFloat(),
check('entries.*.account_id').isInt({ max: DATATYPES_LENGTH.INT_10 }).toInt(), check('entries.*.account_id').isInt({ max: DATATYPES_LENGTH.INT_10 }).toInt(),
check('entries.*.note') check('entries.*.note')
@@ -245,7 +242,11 @@ export default class ManualJournalsController extends BaseController {
try { try {
await this.manualJournalsService.deleteManualJournal(tenantId, manualJournalId); await this.manualJournalsService.deleteManualJournal(tenantId, manualJournalId);
return res.status(200).send();
return res.status(200).send({
id: manualJournalId,
message: 'Manual journal has been deleted successfully.',
});
} catch (error) { } catch (error) {
next(error); next(error);
} }
@@ -263,7 +264,11 @@ export default class ManualJournalsController extends BaseController {
try { try {
await this.manualJournalsService.deleteManualJournals(tenantId, manualJournalsIds); await this.manualJournalsService.deleteManualJournals(tenantId, manualJournalsIds);
return res.status(200).send();
return res.status(200).send({
ids: manualJournalsIds,
message: 'Manual journal have been delete successfully.',
});
} catch (error) { } catch (error) {
next(error); next(error);
} }
@@ -280,7 +285,8 @@ export default class ManualJournalsController extends BaseController {
const manualJournalDTO = this.matchedBodyData(req); const manualJournalDTO = this.matchedBodyData(req);
try { try {
const { manualJournal } = await this.manualJournalsService.makeJournalEntries(tenantId, manualJournalDTO, user); const { manualJournal } = await this.manualJournalsService
.makeJournalEntries(tenantId, manualJournalDTO, user);
return res.status(200).send({ id: manualJournal.id }); return res.status(200).send({ id: manualJournal.id });
} catch (error) { } catch (error) {

View File

@@ -345,7 +345,7 @@ export default class ManualJournalsService implements IManualJournalsService {
await this.validateManualJournalsExistance(tenantId, manualJournalsIds); await this.validateManualJournalsExistance(tenantId, manualJournalsIds);
this.logger.info('[manual_journal] trying to delete the manual journals.', { tenantId, manualJournalsIds }); this.logger.info('[manual_journal] trying to delete the manual journals.', { tenantId, manualJournalsIds });
await ManualJournal.query().where('id', manualJournalsIds).delete(); await ManualJournal.query().whereIn('id', manualJournalsIds).delete();
// Triggers `onManualJournalDeletedBulk` event. // Triggers `onManualJournalDeletedBulk` event.
this.eventDispatcher.dispatch(events.manualJournals.onDeletedBulk, { this.eventDispatcher.dispatch(events.manualJournals.onDeletedBulk, {