-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d206143
commit 1cf6edf
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
apps/e-commerce/src/admin/discount-condition-type/discount-condition-type.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
apps/e-commerce/src/admin/discount-condition-type/discount-condition-type.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
37 changes: 37 additions & 0 deletions
37
apps/e-commerce/src/admin/discount-condition-type/discount-condition-type.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
libs/database/src/models/ecommerce-eav/ec-discount-condition-type.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |