-
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
63bc961
commit 9d28182
Showing
23 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
apps/e-commerce/src/admin/discount-condition-value/discount-condition-value.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,51 @@ | ||
import { | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Inject, | ||
Query, | ||
UseGuards, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { | ||
ConditionValueResInterface, | ||
ConditionValueSourceInterface, | ||
} from './provider/interface'; | ||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { JwtGuard } from '@rahino/auth/guard'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { GetConditionValueDto } from './dto'; | ||
import { GetUser } from '@rahino/auth/decorator'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN } from './provider/discount-condition-value.constants'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
|
||
@ApiTags('Admin-DiscountConditionValues') | ||
@ApiBearerAuth() | ||
@UseGuards(JwtGuard, PermissionGuard) | ||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@Controller({ | ||
path: '/api/ecommerce/admin/discountConditionValues', | ||
version: ['1'], | ||
}) | ||
export class DiscountConditionValueController { | ||
constructor( | ||
@Inject(DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN) | ||
private readonly service: ConditionValueSourceInterface, | ||
) {} | ||
|
||
@ApiOperation({ | ||
description: 'show all discount condition values based conditionTypeId', | ||
}) | ||
@CheckPermission({ permissionSymbol: 'ecommerce.admin.discounts.create' }) | ||
@Get('/') | ||
@HttpCode(HttpStatus.OK) | ||
async findAll( | ||
@GetUser() user: User, | ||
@Query() filter: GetConditionValueDto, | ||
): Promise<ConditionValueResInterface> { | ||
return await this.service.findAll(user, filter); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/e-commerce/src/admin/discount-condition-value/discount-condition-value.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,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ServiceProviderModule } from './provider/service-provider.module'; | ||
import { DiscountConditionValueController } from './discount-condition-value.controller'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
|
||
@Module({ | ||
imports: [ | ||
ServiceProviderModule, | ||
SequelizeModule.forFeature([User, Permission]), | ||
], | ||
controllers: [DiscountConditionValueController], | ||
}) | ||
export class DiscountConditionValueModule {} |
3 changes: 3 additions & 0 deletions
3
apps/e-commerce/src/admin/discount-condition-value/dto/condition-type.dto.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,3 @@ | ||
export class ConditionTypeDto { | ||
conditionTypeId: number; | ||
} |
8 changes: 8 additions & 0 deletions
8
apps/e-commerce/src/admin/discount-condition-value/dto/get-condition-value.dto.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,8 @@ | ||
import { IntersectionType } from '@nestjs/swagger'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { ConditionTypeDto } from './condition-type.dto'; | ||
|
||
export class GetConditionValueDto extends IntersectionType( | ||
ListFilter, | ||
ConditionTypeDto, | ||
) {} |
1 change: 1 addition & 0 deletions
1
apps/e-commerce/src/admin/discount-condition-value/dto/index.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 @@ | ||
export * from './get-condition-value.dto'; |
2 changes: 2 additions & 0 deletions
2
...ommerce/src/admin/discount-condition-value/provider/discount-condition-value.constants.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,2 @@ | ||
export const DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN = | ||
'DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN'; |
1 change: 1 addition & 0 deletions
1
apps/e-commerce/src/admin/discount-condition-value/provider/factory/index.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 @@ | ||
export * from './service-provider.factory'; |
38 changes: 38 additions & 0 deletions
38
...-commerce/src/admin/discount-condition-value/provider/factory/service-provider.factory.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,38 @@ | ||
import { Inject, Injectable, NotFoundException, Scope } from '@nestjs/common'; | ||
import { Request } from 'express'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { DiscountConditionTypeEnum } from '@rahino/ecommerce/admin/discount-condition-type/enum'; | ||
import { | ||
ProductMiddleService, | ||
EntityTypeMiddleService, | ||
InventoryMiddleService, | ||
VendorMiddleService, | ||
} from '../services'; | ||
|
||
@Injectable({ scope: Scope.REQUEST }) | ||
export class ServiceProviderFactory { | ||
constructor( | ||
@Inject(REQUEST) | ||
private request: Request, | ||
private productService: ProductMiddleService, | ||
private entityTypeService: EntityTypeMiddleService, | ||
private inventoryService: InventoryMiddleService, | ||
private vendorService: VendorMiddleService, | ||
) {} | ||
|
||
create() { | ||
const conditionType = Number(this.request?.query?.conditionTypeId); | ||
switch (conditionType) { | ||
case DiscountConditionTypeEnum.product: | ||
return this.productService; | ||
case DiscountConditionTypeEnum.entityType: | ||
return this.entityTypeService; | ||
case DiscountConditionTypeEnum.inventory: | ||
return this.inventoryService; | ||
case DiscountConditionTypeEnum.vendor: | ||
return this.vendorService; | ||
default: | ||
throw new NotFoundException(`Invalid data source: ${conditionType}`); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ce/src/admin/discount-condition-value/provider/interface/condition-value-res.interface.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,7 @@ | ||
import { KeyValueInterface } from './key-value.interface'; | ||
|
||
export interface ConditionValueResInterface { | ||
result: KeyValueInterface[]; | ||
total: number; | ||
message?: string; | ||
} |
7 changes: 7 additions & 0 deletions
7
...src/admin/discount-condition-value/provider/interface/condition-value-source.interface.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,7 @@ | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { ConditionValueResInterface } from './condition-value-res.interface'; | ||
|
||
export interface ConditionValueSourceInterface { | ||
findAll(user: User, filter: ListFilter): Promise<ConditionValueResInterface>; | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/e-commerce/src/admin/discount-condition-value/provider/interface/index.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,3 @@ | ||
export * from './condition-value-source.interface'; | ||
export * from './condition-value-res.interface'; | ||
export * from './key-value.interface'; |
4 changes: 4 additions & 0 deletions
4
apps/e-commerce/src/admin/discount-condition-value/provider/interface/key-value.interface.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,4 @@ | ||
export class KeyValueInterface { | ||
key: bigint; | ||
value: string; | ||
} |
39 changes: 39 additions & 0 deletions
39
apps/e-commerce/src/admin/discount-condition-value/provider/service-provider.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,39 @@ | ||
import { Module, Scope } from '@nestjs/common'; | ||
import { DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN } from './discount-condition-value.constants'; | ||
import { ServiceProviderFactory } from './factory'; | ||
import { | ||
EntityTypeMiddleService, | ||
InventoryMiddleService, | ||
ProductMiddleService, | ||
VendorMiddleService, | ||
} from './services'; | ||
import { EntityTypeModule } from '@rahino/eav/admin/entity-type/entity-type.module'; | ||
import { UserVendorModule } from '@rahino/ecommerce/user/vendor/user-vendor.module'; | ||
import { ProductModule } from '../../product/product.module'; | ||
import { UserInventoryModule } from '@rahino/ecommerce/user/inventory/user-inventory.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
EntityTypeModule, | ||
UserVendorModule, | ||
ProductModule, | ||
UserInventoryModule, | ||
], | ||
providers: [ | ||
{ | ||
provide: DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN, | ||
scope: Scope.REQUEST, | ||
useFactory(providerFactory: ServiceProviderFactory) { | ||
return providerFactory.create(); | ||
}, | ||
inject: [ServiceProviderFactory], | ||
}, | ||
ServiceProviderFactory, | ||
ProductMiddleService, | ||
EntityTypeMiddleService, | ||
InventoryMiddleService, | ||
VendorMiddleService, | ||
], | ||
exports: [DISCOUNT_CONDITION_VALUE_PROVIDER_TOKEN], | ||
}) | ||
export class ServiceProviderModule {} |
27 changes: 27 additions & 0 deletions
27
...mmerce/src/admin/discount-condition-value/provider/services/entity-type-middle.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,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
ConditionValueResInterface, | ||
ConditionValueSourceInterface, | ||
KeyValueInterface, | ||
} from '../interface'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { EntityTypeService } from '@rahino/eav/admin/entity-type/entity-type.service'; | ||
import * as _ from 'lodash'; | ||
|
||
@Injectable() | ||
export class EntityTypeMiddleService implements ConditionValueSourceInterface { | ||
constructor(private readonly entityTypeService: EntityTypeService) {} | ||
async findAll( | ||
user: User, | ||
filter: ListFilter, | ||
): Promise<ConditionValueResInterface> { | ||
const res = await this.entityTypeService.findAll(filter); | ||
return { | ||
result: res.result.map<KeyValueInterface>((item) => { | ||
return { key: BigInt(item.id), value: item.name }; | ||
}), | ||
total: res.total, | ||
}; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/e-commerce/src/admin/discount-condition-value/provider/services/index.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,4 @@ | ||
export * from './entity-type-middle.service'; | ||
export * from './inventory-middle.service'; | ||
export * from './product-middle.service'; | ||
export * from './vendor-middle.service'; |
29 changes: 29 additions & 0 deletions
29
...commerce/src/admin/discount-condition-value/provider/services/inventory-middle.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,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
ConditionValueResInterface, | ||
ConditionValueSourceInterface, | ||
KeyValueInterface, | ||
} from '../interface'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { UserInventoryService } from '@rahino/ecommerce/user/inventory/user-inventory.service'; | ||
|
||
@Injectable() | ||
export class InventoryMiddleService implements ConditionValueSourceInterface { | ||
constructor(private readonly service: UserInventoryService) {} | ||
async findAll( | ||
user: User, | ||
filter: ListFilter, | ||
): Promise<ConditionValueResInterface> { | ||
const res = await this.service.findAll(user, filter); | ||
return { | ||
result: res.result.map<KeyValueInterface>((item) => { | ||
return { | ||
key: item.id, | ||
value: item.product.title + `(شناسه موجودی: ${item.id})`, | ||
}; | ||
}), | ||
total: res.total, | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...e-commerce/src/admin/discount-condition-value/provider/services/product-middle.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,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
ConditionValueResInterface, | ||
ConditionValueSourceInterface, | ||
KeyValueInterface, | ||
} from '../interface'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { ProductService } from '@rahino/ecommerce/admin/product/product.service'; | ||
|
||
@Injectable() | ||
export class ProductMiddleService implements ConditionValueSourceInterface { | ||
constructor(private readonly service: ProductService) {} | ||
async findAll( | ||
user: User, | ||
filter: ListFilter, | ||
): Promise<ConditionValueResInterface> { | ||
const res = await this.service.findAll(user, filter); | ||
return { | ||
result: res.result.map<KeyValueInterface>((item) => { | ||
return { key: BigInt(item.id), value: item.title }; | ||
}), | ||
total: res.total, | ||
}; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../e-commerce/src/admin/discount-condition-value/provider/services/vendor-middle.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,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
ConditionValueResInterface, | ||
ConditionValueSourceInterface, | ||
KeyValueInterface, | ||
} from '../interface'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { UserVendorService } from '@rahino/ecommerce/user/vendor/user-vendor.service'; | ||
|
||
@Injectable() | ||
export class VendorMiddleService implements ConditionValueSourceInterface { | ||
constructor(private service: UserVendorService) {} | ||
async findAll( | ||
user: User, | ||
filter: ListFilter, | ||
): Promise<ConditionValueResInterface> { | ||
const res = await this.service.findAll(user, filter); | ||
return { | ||
result: res.result.map<KeyValueInterface>((item) => { | ||
return { key: BigInt(item.id), value: item.name }; | ||
}), | ||
total: res.total, | ||
}; | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
apps/e-commerce/src/user/inventory/user-inventory.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 { SequelizeModule } from '@nestjs/sequelize'; | ||
import { ECVendorUser } from '@rahino/database/models/ecommerce-eav/ec-vendor-user.entity'; | ||
import { UserInventoryService } from './user-inventory.service'; | ||
import { ECInventory } from '@rahino/database/models/ecommerce-eav/ec-inventory.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([ECVendorUser, ECInventory])], | ||
providers: [UserInventoryService], | ||
exports: [UserInventoryService], | ||
}) | ||
export class UserInventoryModule {} |
Oops, something went wrong.