Skip to content

Commit

Permalink
fix bug of incorret model query
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jul 2, 2024
1 parent a162521 commit b02405d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
95 changes: 95 additions & 0 deletions apps/main/src/sql/core-v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
)
Expand Down

0 comments on commit b02405d

Please sign in to comment.