Add a small internal warehouse and party balances when Tahesab is off.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { InventoryModule } from '../inventory/inventory.module';
|
||||
import { ProductsController } from './products.controller';
|
||||
import { ProductsService } from './products.service';
|
||||
|
||||
@Module({
|
||||
imports: [AuthModule],
|
||||
imports: [AuthModule, InventoryModule],
|
||||
controllers: [ProductsController],
|
||||
providers: [ProductsService],
|
||||
exports: [ProductsService],
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
} from '@mento/shared';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { InventoryService } from '../inventory/inventory.service';
|
||||
|
||||
type ProductRow = {
|
||||
id: string;
|
||||
@@ -33,7 +34,10 @@ type ProductRow = {
|
||||
|
||||
@Injectable()
|
||||
export class ProductsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly inventory: InventoryService,
|
||||
) {}
|
||||
|
||||
async list(
|
||||
organizationId: string,
|
||||
@@ -115,6 +119,12 @@ export class ProductsService {
|
||||
isActive: dto.isActive ?? true,
|
||||
},
|
||||
});
|
||||
await this.inventory.onProductCreated(
|
||||
organizationId,
|
||||
row.id,
|
||||
row.stockQty,
|
||||
row.kind,
|
||||
);
|
||||
return this.toDto(row);
|
||||
}
|
||||
|
||||
@@ -154,6 +164,14 @@ export class ProductsService {
|
||||
if (dto.isActive !== undefined) data.isActive = dto.isActive;
|
||||
|
||||
const row = await this.prisma.product.update({ where: { id }, data });
|
||||
if ('stockQty' in dto) {
|
||||
await this.inventory.onProductStockEdited(
|
||||
organizationId,
|
||||
row.id,
|
||||
row.stockQty,
|
||||
row.kind,
|
||||
);
|
||||
}
|
||||
return this.toDto(row);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user