From b02405da54aa55445cead0a971ddde180d874177 Mon Sep 17 00:00:00 2001 From: bahram rajabi Date: Wed, 3 Jul 2024 02:49:59 +0330 Subject: [PATCH] fix bug of incorret model query --- .../inventory-history.module.ts | 10 +- .../inventory-history.service.ts | 5 +- .../services/inventory-validation.service.ts | 6 +- apps/main/src/sql/core-v1.sql | 95 +++++++++++++++++++ 4 files changed, 111 insertions(+), 5 deletions(-) diff --git a/apps/e-commerce/src/admin/inventory-history/inventory-history.module.ts b/apps/e-commerce/src/admin/inventory-history/inventory-history.module.ts index c4f48fd6..4e238deb 100644 --- a/apps/e-commerce/src/admin/inventory-history/inventory-history.module.ts +++ b/apps/e-commerce/src/admin/inventory-history/inventory-history.module.ts @@ -5,9 +5,17 @@ import { InventoryHistoryService } from './inventory-history.service'; import { InventoryHistoryController } from './inventory-history.controller'; import { User } from '@rahino/database/models/core/user.entity'; import { Permission } from '@rahino/database/models/core/permission.entity'; +import { ECInventory } from '@rahino/database/models/ecommerce-eav/ec-inventory.entity'; @Module({ - imports: [SequelizeModule.forFeature([User, Permission, ECInventoryHistory])], + imports: [ + SequelizeModule.forFeature([ + User, + Permission, + ECInventoryHistory, + ECInventory, + ]), + ], controllers: [InventoryHistoryController], providers: [InventoryHistoryService], exports: [InventoryHistoryService], diff --git a/apps/e-commerce/src/admin/inventory-history/inventory-history.service.ts b/apps/e-commerce/src/admin/inventory-history/inventory-history.service.ts index e8dd0ac1..6756684d 100644 --- a/apps/e-commerce/src/admin/inventory-history/inventory-history.service.ts +++ b/apps/e-commerce/src/admin/inventory-history/inventory-history.service.ts @@ -3,6 +3,7 @@ import { InjectModel } from '@nestjs/sequelize'; import { User } from '@rahino/database/models/core/user.entity'; import { ECInventoryHistory } from '@rahino/database/models/ecommerce-eav/ec-inventory-history.entity'; import { ECInventoryTrackChangeStatus } from '@rahino/database/models/ecommerce-eav/ec-inventory-track-change-status.entity'; +import { ECInventory } from '@rahino/database/models/ecommerce-eav/ec-inventory.entity'; import { ECProduct } from '@rahino/database/models/ecommerce-eav/ec-product.entity'; import { ListFilter } from '@rahino/query-filter'; import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; @@ -12,10 +13,12 @@ export class InventoryHistoryService { constructor( @InjectModel(ECInventoryHistory) private readonly repository: typeof ECInventoryHistory, + @InjectModel(ECInventory) + private readonly inventoryRepository: typeof ECInventory, ) {} async findAll(user: User, inventoryId: bigint, filter: ListFilter) { - let inventory = await this.repository.findOne( + let inventory = await this.inventoryRepository.findOne( new QueryOptionsBuilder().filter({ id: inventoryId }).build(), ); if (!inventory) { diff --git a/apps/e-commerce/src/inventory/services/inventory-validation.service.ts b/apps/e-commerce/src/inventory/services/inventory-validation.service.ts index 5e275bf1..45f976b5 100644 --- a/apps/e-commerce/src/inventory/services/inventory-validation.service.ts +++ b/apps/e-commerce/src/inventory/services/inventory-validation.service.ts @@ -172,9 +172,9 @@ export class InventoryValidationService { if (inventoryDto.guaranteeId == null && inventoryDto.guaranteeMonthId) { throw new BadRequestException('guarantee month is not valid !'); } - if (inventoryDto.guaranteeMonthId == null && inventoryDto.guaranteeId) { - throw new BadRequestException('guarantee month must be send it !'); - } + // if (inventoryDto.guaranteeMonthId == null && inventoryDto.guaranteeId) { + // throw new BadRequestException('guarantee month must be send it !'); + // } if (inventoryDto.guaranteeId) { const guarantee = await this.guaranteeRepository.findOne( new QueryOptionsBuilder() diff --git a/apps/main/src/sql/core-v1.sql b/apps/main/src/sql/core-v1.sql index 7b8fb3e0..5c8a01c4 100644 --- a/apps/main/src/sql/core-v1.sql +++ b/apps/main/src/sql/core-v1.sql @@ -3777,11 +3777,15 @@ BEGIN CONSTRAINT FK_ECInventoryHistory_InventoryTrackChangeStatusId FOREIGN KEY REFERENCES ECInventoryTrackChangeStatuses(id), qty int NOT NULL, + orderId bigint NULL + CONSTRAINT FK_ECInventoryHistories_OrderId + FOREIGN KEY REFERENCES ECOrders(id), [createdAt] datetimeoffset NOT NULL, [updatedAt] datetimeoffset NOT NULL, ); + INSERT INTO Migrations(version, createdAt, updatedAt) SELECT 'ec-inventoryhistories-v1', GETDATE(), GETDATE() END @@ -6347,6 +6351,28 @@ GO +IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'ecommerce-inventorytrackchangestatuses-Data-v1' + ) + AND EXISTS ( + SELECT 1 FROM Settings + WHERE ([key] = 'SITE_NAME' AND [value] IN ('ecommerce')) + ) +BEGIN + + INSERT INTO ECInventoryTrackChangeStatuses(id, [name], createdAt, updatedAt) + VALUES (1, N'ثبت موجودی', GETDATE(), GETDATE()) + ,(2, N'بروزرسانی موجودی', GETDATE(), GETDATE()) + ,(3, N'کاهش موجودی به منظور ثبت سفارش', GETDATE(), GETDATE()) + ,(4, N'بازگشت موجودی به منظور سفارش پرداخت نشده', GETDATE(), GETDATE()) + + + INSERT INTO Migrations(version, createdAt, updatedAt) + SELECT 'ecommerce-inventorytrackchangestatuses-Data-v1', GETDATE(), GETDATE() +END + +GO + + -- data takhfif -- buffetType IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'DiscountCoffe-buffetType-Data-v1' @@ -14486,6 +14512,75 @@ END GO + + + +-- ecommerce/admin/inventoryhistories +IF NOT EXISTS ((SELECT 1 FROM Migrations WHERE version = 'CORE-Permissions-Data-v60' + )) + AND EXISTS ( + SELECT 1 FROM Settings WHERE 1=1 + AND ([key] = 'SITE_NAME' AND [value] IN ('ecommerce')) + ) +BEGIN + + DECLARE @roleId int = (SELECT TOP 1 id FROM Roles WHERE static_id = 1) + DECLARE @userId bigint = (SELECT TOP 1 id FROM Users WHERE static_id = 1) + + DECLARE @GroupTemp TABLE ( + gorupId int + ); + + DECLARE @groupId int = null; + + DECLARE @entityName nvarchar(256) = N'InventoryHistories' + DECLARE @groupName nvarchar(256) = N'ecommerce.admin.inventoryhistories' + + + DECLARE @permissionSymbolGetAll nvarchar(512) = @groupName + '.getall'; + DECLARE @permissionSymbolGetOne nvarchar(512) = @groupName + '.getone'; + + + + -- permission groups + INSERT INTO PermissionGroups(permissionGroupName, [visibility], createdAt, updatedAt) + OUTPUT inserted.id INTO @GroupTemp(gorupId) + SELECT @groupName, 1, GETDATE(), GETDATE(); + + SELECT @groupId = gorupId FROM @GroupTemp + + + -- permissions + + + DECLARE @PermissionTemp TABLE ( + permissionId int + ); + + INSERT INTO Permissions(permissionName ,permissionSymbol,permissionGroupId, createdAt, updatedAt) + OUTPUT inserted.id INTO @PermissionTemp(permissionId) + SELECT 'GETALL_' + @entityName, @permissionSymbolGetAll, @groupId, GETDATE(), GETDATE() + + INSERT INTO Permissions(permissionName ,permissionSymbol,permissionGroupId, createdAt, updatedAt) + OUTPUT inserted.id INTO @PermissionTemp(permissionId) + SELECT 'GETONE_' + @entityName, @permissionSymbolGetOne, @groupId, GETDATE(), GETDATE() + + + -- CRUD THIS Enity FOR super-admin + INSERT INTO RolePermissions(roleId, permissionId, createdAt, updatedAt) + SELECT @roleId, permissionId, GETDATE(), GETDATE() + FROM @PermissionTemp + + DELETE FROM @PermissionTemp + + + INSERT INTO Migrations(version, createdAt, updatedAt) + SELECT 'CORE-Permissions-Data-v60', GETDATE(), GETDATE() +END + +GO + + -- period types IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'PCMPeriodTypes-Data-v1' )