diff --git a/server/src/api/controllers/Items.ts b/server/src/api/controllers/Items.ts index 804f37684..e24c0f47d 100644 --- a/server/src/api/controllers/Items.ts +++ b/server/src/api/controllers/Items.ts @@ -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(), diff --git a/server/src/database/migrations/20190822214306_create_items_table.js b/server/src/database/migrations/20190822214306_create_items_table.js index b85d66e7d..83f03280a 100644 --- a/server/src/database/migrations/20190822214306_create_items_table.js +++ b/server/src/database/migrations/20190822214306_create_items_table.js @@ -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(); diff --git a/server/src/interfaces/Item.ts b/server/src/interfaces/Item.ts index 2726fbae0..f5cf5726f 100644 --- a/server/src/interfaces/Item.ts +++ b/server/src/interfaces/Item.ts @@ -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, } diff --git a/server/src/services/Items/ItemsService.ts b/server/src/services/Items/ItemsService.ts index 3597219c4..298cb3468 100644 --- a/server/src/services/Items/ItemsService.ts +++ b/server/src/services/Items/ItemsService.ts @@ -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;