fix: activate/inactivate item.

This commit is contained in:
Ahmed Bouhuolia
2020-11-29 13:04:00 +02:00
parent ea39eb17a7
commit 130aa6a400
4 changed files with 9 additions and 2 deletions

View File

@@ -116,6 +116,7 @@ export default class ItemsController extends BaseController {
check('category_id').optional({ nullable: true }).isInt().toInt(),
check('note').optional(),
check('active').optional().isBoolean().toBoolean(),
check('media_ids').optional().isArray(),
check('media_ids.*').exists().isNumeric().toInt(),

View File

@@ -18,6 +18,7 @@ exports.up = function (knex) {
table.text('purchase_description').nullable();
table.integer('quantity_on_hand');
table.text('note').nullable();
table.boolean('active');
table.integer('category_id').unsigned().index().references('id').inTable('items_categories');
table.integer('user_id').unsigned().index();
table.timestamps();

View File

@@ -22,6 +22,7 @@ export interface IItem{
quantityOnHand: number,
note: string,
active: boolean,
categoryId: number,
userId: number,
@@ -52,6 +53,7 @@ export interface IItemDTO {
quantityOnHand: number,
note: string,
active: boolean,
categoryId: number,
}

View File

@@ -1,4 +1,4 @@
import { difference } from "lodash";
import { defaultTo, difference } from "lodash";
import { Service, Inject } from "typedi";
import { IItemsFilter, IItemsService, IItemDTO, IItem } from 'interfaces';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
@@ -176,7 +176,10 @@ export default class ItemsService implements IItemsService {
if (itemDTO.inventoryAccountId) {
await this.validateItemInventoryAccountExistance(tenantId, itemDTO.inventoryAccountId);
}
const storedItem = await Item.query().insertAndFetch({ ...itemDTO });
const storedItem = await Item.query().insertAndFetch({
...itemDTO,
active: defaultTo(itemDTO.active, 1),
});
this.logger.info('[items] item inserted successfully.', { tenantId, itemDTO });
return storedItem;