refactor: warehouses to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-21 15:07:01 +02:00
parent cb8fd68d46
commit 8a12caf48d
29 changed files with 348 additions and 100 deletions

View File

@@ -1,9 +1,9 @@
import { Knex } from 'knex';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Inject, Injectable } from '@nestjs/common';
import { Item } from './models/Item';
import { UnitOfWork } from '../Tenancy/TenancyDB/UnitOfWork.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { events } from '@/common/events/events';
import { Knex } from 'knex';
@Injectable()
export class ActivateItemService {

View File

@@ -39,11 +39,10 @@ export class DeleteItemService {
const oldItem = await this.itemModel
.query()
.findById(itemId)
.throwIfNotFound()
// @ts-expect-error
.queryAndThrowIfHasRelations({
type: ERRORS.ITEM_HAS_ASSOCIATED_TRANSACTIONS,
});
.throwIfNotFound();
// .queryAndThrowIfHasRelations({
// type: ERRORS.ITEM_HAS_ASSOCIATED_TRANSACTIONS,
// });
// Delete item in unit of work.
return this.uow.withTransaction(async (trx: Knex.Transaction) => {

View File

@@ -2,6 +2,7 @@ import * as F from 'fp-ts/function';
import * as R from 'ramda';
import { SearchableModel } from '@/modules/Search/SearchableMdel';
import { BaseModel } from '@/models/Model';
import { Warehouse } from '@/modules/Warehouses/models/Warehouse.model';
// import { TenantModel } from '@/modules/System/models/TenantModel';
// const Extend = R.compose(SearchableModel)(TenantModel);
@@ -21,6 +22,8 @@ export class Item extends BaseModel {
public readonly inventoryAccountId: number;
public readonly categoryId: number;
public readonly warehouse!: Warehouse;
static get tableName() {
return 'items';
}