feat: remove parent item category from item categories service.

This commit is contained in:
Ahmed Bouhuolia
2020-12-02 17:38:49 +02:00
parent e0f1b71930
commit ac6904daaa
5 changed files with 1 additions and 22 deletions

View File

@@ -84,10 +84,6 @@ export default class ItemsCategoriesController extends BaseController {
.trim()
.escape()
.isLength({ min: 0, max: DATATYPES_LENGTH.STRING }),
check('parent_category_id')
.optional({ nullable: true })
.isInt({ min: 0, max: DATATYPES_LENGTH.INT_10 })
.toInt(),
check('description')
.optional({ nullable: true })
.isString()

View File

@@ -3,7 +3,7 @@ exports.up = function (knex) {
return knex.schema.createTable('items_categories', (table) => {
table.increments();
table.string('name').index();
table.integer('parent_category_id').unsigned().references('id').inTable('items_categories');
table.text('description');
table.integer('user_id').unsigned().index();

View File

@@ -4,8 +4,6 @@ import { ISystemUser } from "./User";
export interface IItemCategory {
id: number,
name: string,
parentCategoryId?: number,
description?: string,
userId: number,
@@ -19,7 +17,6 @@ export interface IItemCategory {
export interface IItemCategoryOTD {
name: string,
parentCategoryId?: number,
description?: string,
userId: number,

View File

@@ -57,13 +57,6 @@ export default class ItemCategory extends TenantModel {
column: 'description',
columnType: 'string'
},
parent_category_id: {
label: 'Parent category',
column: 'parent_category_id',
relation: 'items_categories.id',
relationColumn: 'items_categories.id',
optionsResource: 'item_category',
},
user: {
label: 'User',
column: 'user_id',

View File

@@ -99,9 +99,6 @@ export default class ItemCategoriesService implements IItemCategoriesService {
if (itemCategoryOTD.inventoryAccountId) {
await this.validateInventoryAccount(tenantId, itemCategoryOTD.inventoryAccountId);
}
if (itemCategoryOTD.parentCategoryId) {
await this.getItemCategoryOrThrowError(tenantId, itemCategoryOTD.parentCategoryId);
}
const itemCategoryObj = this.transformOTDToObject(itemCategoryOTD, authorizedUser);
const itemCategory = await ItemCategory.query().insert({ ...itemCategoryObj });
@@ -203,10 +200,6 @@ export default class ItemCategoriesService implements IItemCategoriesService {
if (itemCategoryOTD.inventoryAccountId) {
await this.validateInventoryAccount(tenantId, itemCategoryOTD.inventoryAccountId);
}
if (itemCategoryOTD.parentCategoryId) {
await this.getItemCategoryOrThrowError(tenantId, itemCategoryOTD.parentCategoryId);
}
const itemCategoryObj = this.transformOTDToObject(itemCategoryOTD, authorizedUser);
const itemCategory = await ItemCategory.query().patchAndFetchById(itemCategoryId, { ...itemCategoryObj });