Skip to content

Commit

Permalink
add discount condition type
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Mar 18, 2024
1 parent d206143 commit 1cf6edf
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
Controller,
Get,
HttpCode,
HttpStatus,
UseGuards,
UseInterceptors,
} from '@nestjs/common';

import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { DiscountConditionTypeService } from './discount-condition-type.service';
import { JwtGuard } from '@rahino/auth/guard';

@ApiTags('Admin-DiscountConditionTypes')
@ApiBearerAuth()
@UseGuards(JwtGuard)
@Controller({
path: '/api/ecommerce/admin/discountConditionTypes',
version: ['1'],
})
@UseInterceptors(JsonResponseTransformInterceptor)
export class DiscountConditionTypeController {
constructor(private service: DiscountConditionTypeService) {}

// public url
@ApiOperation({ description: 'show all discount Condition Types' })
@Get('/')
@HttpCode(HttpStatus.OK)
async findAll() {
return await this.service.findAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { DiscountConditionTypeController } from './discount-condition-type.controller';
import { DiscountConditionTypeService } from './discount-condition-type.service';
import { SequelizeModule } from '@nestjs/sequelize';
import { ECDiscountConditionType } from '@rahino/database/models/ecommerce-eav/ec-discount-condition-type.entity';

@Module({
imports: [SequelizeModule.forFeature([ECDiscountConditionType])],
controllers: [DiscountConditionTypeController],
providers: [DiscountConditionTypeService],
})
export class DiscountActionRuleModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { ECDiscountConditionType } from '@rahino/database/models/ecommerce-eav/ec-discount-condition-type.entity';
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder';
import * as _ from 'lodash';
import { Sequelize } from 'sequelize';
import { Op } from 'sequelize';

@Injectable()
export class DiscountConditionTypeService {
constructor(
@InjectModel(ECDiscountConditionType)
private repository: typeof ECDiscountConditionType,
) {}

async findAll() {
const queryBuilder = new QueryOptionsBuilder().filter(
Sequelize.where(
Sequelize.fn(
'isnull',
Sequelize.col('ECDiscountConditionType.isDeleted'),
0,
),
{
[Op.eq]: 0,
},
),
);
const count = await this.repository.count(queryBuilder.build());
const queryOptions = queryBuilder.attributes(['id', 'name']).build();
const result = await this.repository.findAll(queryOptions);
return {
result: result,
total: count,
};
}
}
48 changes: 47 additions & 1 deletion apps/main/src/sql/core-v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ END

GO

-- ec-disoucnts-v1
-- ec-discounts-v1
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'ec-discounts-v1'
)
AND EXISTS (
Expand Down Expand Up @@ -2386,6 +2386,29 @@ END
GO


-- ec-discount-condition-types-v1
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'ec-discount-condition-types-v1'
)
AND EXISTS (
SELECT 1 FROM Settings
WHERE ([key] = 'SITE_NAME' AND [value] IN ('ecommerce'))
)
BEGIN

CREATE TABLE ECDiscountConditionTypes(
id int PRIMARY KEY,
[name] nvarchar(512) NOT NULL,
isDeleted bit NULL,
[createdAt] datetimeoffset NOT NULL,
[updatedAt] datetimeoffset NOT NULL,
);

INSERT INTO Migrations(version, createdAt, updatedAt)
SELECT 'ec-discount-condition-types-v1', GETDATE(), GETDATE()
END

GO


-- ec discount-types
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'ec-discount-types-Data-v1'
Expand Down Expand Up @@ -2452,6 +2475,29 @@ END

GO

-- ec discount-condition-types
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'ec-discount-condition-types-Data-v1'
)
AND EXISTS (
SELECT 1 FROM Settings
WHERE ([key] = 'SITE_NAME' AND [value] IN ('ecommerce'))
)
BEGIN

INSERT INTO ECDiscountConditionTypes(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 'ec-discount-condition-types-Data-v1', GETDATE(), GETDATE()
END

GO


-- eav
-- attributetypes
IF NOT EXISTS (SELECT 1 FROM Migrations WHERE version = 'eav-attributetypes-Data-v1'
Expand Down
2 changes: 2 additions & 0 deletions libs/database/src/database.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { ECDiscountActionType } from './models/ecommerce-eav/ec-discount-action-
import { ECDiscountActionRule } from './models/ecommerce-eav/ec-discount-action-rule.entity';
import { ECDiscount } from './models/ecommerce-eav/ec-discount.entity';
import { SequelizeOverrideModule } from './override/sequelize-override.module';
import { ECDiscountConditionType } from './models/ecommerce-eav/ec-discount-condition-type.entity';

@Module({
imports: [
Expand Down Expand Up @@ -136,6 +137,7 @@ import { SequelizeOverrideModule } from './override/sequelize-override.module';
ECDiscountActionType,
ECDiscountActionRule,
ECDiscount,
ECDiscountConditionType,
Buffet,
BuffetGallery,
BuffetType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Table, Column, Model, DataType } from 'sequelize-typescript';

@Table({ tableName: 'ECDiscountConditionTypes' })
export class ECDiscountConditionType extends Model {
@Column({
type: DataType.INTEGER,
primaryKey: true,
})
id: number;
@Column({
type: DataType.STRING,
})
name: string;
@Column({
type: DataType.BOOLEAN,
allowNull: true,
})
isDeleted?: boolean;
}

0 comments on commit 1cf6edf

Please sign in to comment.