-
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.
refactor and add payment transaction module
- Loading branch information
1 parent
499da11
commit ef84bb2
Showing
21 changed files
with
736 additions
and
23 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
apps/e-commerce/src/admin/payment-gateway/payment-gateway.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,63 @@ | ||
import { | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Param, | ||
Query, | ||
UseGuards, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { GetUser } from '@rahino/auth/decorator'; | ||
import { JwtGuard } from '@rahino/auth/guard'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { PaymentGatewayService } from './payment-gateway.service'; | ||
|
||
@ApiTags('payment-gateway') | ||
@UseGuards(JwtGuard, PermissionGuard) | ||
@ApiBearerAuth() | ||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@Controller({ | ||
path: '/api/ecommerce/admin/paymentGateways', | ||
version: ['1'], | ||
}) | ||
export class PaymentGatewayController { | ||
constructor(private readonly service: PaymentGatewayService) {} | ||
|
||
// public url | ||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.paymentgateways.getall', | ||
}) | ||
@ApiOperation({ description: 'show all payment gateway' }) | ||
@Get('/') | ||
@ApiQuery({ | ||
name: 'filter', | ||
type: ListFilter, | ||
style: 'deepObject', | ||
explode: true, | ||
}) | ||
@HttpCode(HttpStatus.OK) | ||
async findAll(@GetUser() user: User, @Query() filter: ListFilter) { | ||
return await this.service.findAll(user, filter); | ||
} | ||
|
||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.paymentgateways.getone', | ||
}) | ||
@ApiOperation({ description: 'show payment gateway by given id' }) | ||
@Get('/:id') | ||
@HttpCode(HttpStatus.OK) | ||
async findById(@GetUser() user: User, @Param('id') entityId: number) { | ||
return await this.service.findById(user, entityId); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/e-commerce/src/admin/payment-gateway/payment-gateway.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,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PaymentGatewayService } from './payment-gateway.service'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
import { PaymentGatewayController } from './payment-gateway.controller'; | ||
import { ECPaymentGateway } from '@rahino/database/models/ecommerce-eav/ec-payment-gateway.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([User, Permission, ECPaymentGateway])], | ||
controllers: [PaymentGatewayController], | ||
providers: [PaymentGatewayService], | ||
}) | ||
export class PaymentGatewayModule {} |
49 changes: 49 additions & 0 deletions
49
apps/e-commerce/src/admin/payment-gateway/payment-gateway.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,49 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { ECPaymentGateway } from '@rahino/database/models/ecommerce-eav/ec-payment-gateway.entity'; | ||
import { ListFilter } from '@rahino/query-filter'; | ||
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; | ||
import { Op } from 'sequelize'; | ||
import { Sequelize } from 'sequelize'; | ||
|
||
@Injectable() | ||
export class PaymentGatewayService { | ||
constructor( | ||
@InjectModel(ECPaymentGateway) | ||
private readonly repository: typeof ECPaymentGateway, | ||
) {} | ||
async findAll(user: User, filter: ListFilter) { | ||
let queryBuilder = new QueryOptionsBuilder().filter( | ||
Sequelize.where( | ||
Sequelize.fn('isnull', Sequelize.col('ECPaymentGateway.isDeleted'), 0), | ||
{ | ||
[Op.eq]: 0, | ||
}, | ||
), | ||
); | ||
return { | ||
result: await this.repository.findAll(queryBuilder.build()), | ||
total: await this.repository.count(queryBuilder.build()), | ||
}; | ||
} | ||
async findById(user: User, entityId: number) { | ||
let queryBuilder = new QueryOptionsBuilder() | ||
.filter({ id: entityId }) | ||
.filter( | ||
Sequelize.where( | ||
Sequelize.fn( | ||
'isnull', | ||
Sequelize.col('ECPaymentGateway.isDeleted'), | ||
0, | ||
), | ||
{ | ||
[Op.eq]: 0, | ||
}, | ||
), | ||
); | ||
return { | ||
result: await this.repository.findAll(queryBuilder.build()), | ||
}; | ||
} | ||
} |
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
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
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
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
8 changes: 8 additions & 0 deletions
8
apps/e-commerce/src/report/order-query-builder/order-query-builder.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,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OrderQueryBuilderService } from './order-query-builder.service'; | ||
|
||
@Module({ | ||
providers: [OrderQueryBuilderService], | ||
exports: [OrderQueryBuilderService], | ||
}) | ||
export class OrderQueryBuilderModule {} |
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
8 changes: 8 additions & 0 deletions
8
apps/e-commerce/src/report/payment-transaction/dto/get-payment-transaction.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 { PaymentTransactionDto } from './payment-transaction.dto'; | ||
|
||
export class GetPaymentTransactionDto extends IntersectionType( | ||
PaymentTransactionDto, | ||
ListFilter, | ||
) {} |
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-payment-transaction.dto'; |
47 changes: 47 additions & 0 deletions
47
apps/e-commerce/src/report/payment-transaction/dto/payment-transaction.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,47 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { I18nTranslations } from 'apps/main/src/generated/i18n.generated'; | ||
import { Type } from 'class-transformer'; | ||
import { IsInt, IsNumber, IsOptional, IsString } from 'class-validator'; | ||
import { i18nValidationMessage } from 'nestjs-i18n'; | ||
|
||
export class PaymentTransactionDto { | ||
@ApiProperty({ | ||
required: true, | ||
type: IsString, | ||
description: 'beginDate', | ||
}) | ||
@IsString() | ||
beginDate: string; | ||
|
||
@ApiProperty({ | ||
required: true, | ||
type: IsString, | ||
description: 'endDate', | ||
}) | ||
@IsString() | ||
endDate: string; | ||
|
||
@ApiProperty({ | ||
required: false, | ||
type: IsNumber, | ||
description: 'paymentGatewayId', | ||
}) | ||
@IsOptional() | ||
@IsInt({ | ||
message: i18nValidationMessage<I18nTranslations>('validation.NUMBER'), | ||
}) | ||
@Type(() => Number) | ||
paymentGatewayId?: number; | ||
|
||
@ApiProperty({ | ||
required: false, | ||
type: IsNumber, | ||
description: 'orderId', | ||
}) | ||
@IsOptional() | ||
@IsInt({ | ||
message: i18nValidationMessage<I18nTranslations>('validation.NUMBER'), | ||
}) | ||
@Type(() => Number) | ||
orderId?: bigint; | ||
} |
Oops, something went wrong.