-
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
324a134
commit 3b3e477
Showing
20 changed files
with
626 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -48,4 +48,8 @@ lerna-debug.log* | |
/profile | ||
|
||
# qr code | ||
/qrcode | ||
/qrcode | ||
|
||
|
||
# task | ||
todo.md |
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 SCORE_COMMENT_QUEUE = 'SCORE_COMMENT_QUEUE'; | ||
export const SCORE_COMMENT_JOB = 'SCORE_COMMENT_JOB'; |
19 changes: 19 additions & 0 deletions
19
apps/e-commerce/src/admin/product-comment/dto/comment-status.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,19 @@ | ||
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 CommentStatusDto { | ||
@ApiProperty({ | ||
required: false, | ||
type: IsNumber, | ||
description: 'commentStatusId', | ||
}) | ||
@IsOptional() | ||
@IsInt({ | ||
message: i18nValidationMessage<I18nTranslations>('validation.NUMBER'), | ||
}) | ||
@Type(() => Number) | ||
commentStatusId?: number; | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/e-commerce/src/admin/product-comment/dto/confirm-comment.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,7 @@ | ||
import { IsOptional, IsString } from 'class-validator'; | ||
|
||
export class ConfirmCommentDto { | ||
@IsString() | ||
@IsOptional() | ||
description?: string; | ||
} |
8 changes: 8 additions & 0 deletions
8
apps/e-commerce/src/admin/product-comment/dto/get-product-comment.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 { CommentStatusDto } from './comment-status.dto'; | ||
|
||
export class GetProductCommentDto extends IntersectionType( | ||
ListFilter, | ||
CommentStatusDto, | ||
) {} |
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 * from './confirm-comment.dto'; | ||
export * from './get-product-comment.dto'; |
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 './score-comment.processor'; |
29 changes: 29 additions & 0 deletions
29
apps/e-commerce/src/admin/product-comment/processor/score-comment.processor.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 { Processor, WorkerHost } from '@nestjs/bullmq'; | ||
import { Job } from 'bullmq'; | ||
import { SCORE_COMMENT_QUEUE } from '../constants'; | ||
import { DBLogger } from '@rahino/logger'; | ||
import { CalculateCommentScoreService } from '../services'; | ||
|
||
@Processor(SCORE_COMMENT_QUEUE) | ||
export class ScoreCommentProcessor extends WorkerHost { | ||
constructor( | ||
private readonly logger: DBLogger, | ||
private readonly calculateCommentScoreService: CalculateCommentScoreService, | ||
) { | ||
super(); | ||
} | ||
|
||
async process(job: Job<any, any, any>, token?: string): Promise<any> { | ||
if (!job.data.commentId) { | ||
return Promise.reject('commentId not provided!'); | ||
} | ||
|
||
const commentId = job.data.commentId; | ||
try { | ||
await this.calculateCommentScoreService.calculateCommentScore(commentId); | ||
} catch (error) { | ||
Promise.reject(error.message); | ||
} | ||
return Promise.resolve(commentId); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
apps/e-commerce/src/admin/product-comment/product-comment.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,92 @@ | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { | ||
Body, | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Param, | ||
Patch, | ||
Query, | ||
UseGuards, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { JwtGuard } from '@rahino/auth/guard'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { GetUser } from '@rahino/auth/decorator'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { PermissionGuard } from '@rahino/permission-checker/guard'; | ||
import { CheckPermission } from '@rahino/permission-checker/decorator'; | ||
import { ConfirmCommentDto, GetProductCommentDto } from './dto'; | ||
import { ProductCommentService } from './product-comment.service'; | ||
|
||
@ApiTags('Product-Comment') | ||
@UseGuards(JwtGuard, PermissionGuard) | ||
@ApiBearerAuth() | ||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@Controller({ | ||
path: '/api/ecommerce/admin/productComments', | ||
version: ['1'], | ||
}) | ||
export class ProductCommentController { | ||
constructor(private readonly service: ProductCommentService) {} | ||
|
||
@ApiOperation({ description: 'show all product comments' }) | ||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.productcomments.getall', | ||
}) | ||
@Get('/') | ||
@ApiQuery({ | ||
name: 'filter', | ||
type: GetProductCommentDto, | ||
style: 'deepObject', | ||
explode: true, | ||
}) | ||
@HttpCode(HttpStatus.OK) | ||
async findAll(@GetUser() user: User, @Query() filter: GetProductCommentDto) { | ||
return await this.service.findAll(user, filter); | ||
} | ||
|
||
@ApiOperation({ description: 'show postage orders by given id' }) | ||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.productcomments.getone', | ||
}) | ||
@Get('/:id') | ||
@HttpCode(HttpStatus.OK) | ||
async findById(@Param('id') entityId: bigint, @GetUser() user: User) { | ||
return await this.service.findById(entityId, user); | ||
} | ||
|
||
@ApiOperation({ description: 'confirm comment by id' }) | ||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.productcomments.condfirmcomment', | ||
}) | ||
@Patch('/confirmComment/:id') | ||
@HttpCode(HttpStatus.OK) | ||
async confirmComment( | ||
@Param('id') commentId: bigint, | ||
@GetUser() user: User, | ||
@Body() dto: ConfirmCommentDto, | ||
) { | ||
return await this.service.confirmComment(commentId, user, dto); | ||
} | ||
|
||
@ApiOperation({ description: 'reject comment by id' }) | ||
@CheckPermission({ | ||
permissionSymbol: 'ecommerce.admin.productcomments.rejectcomment', | ||
}) | ||
@Patch('/rejectComment/:id') | ||
@HttpCode(HttpStatus.OK) | ||
async rejectComment( | ||
@Param('id') commentId: bigint, | ||
@GetUser() user: User, | ||
@Body() dto: ConfirmCommentDto, | ||
) { | ||
return await this.service.rejectComment(commentId, user, dto); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
apps/e-commerce/src/admin/product-comment/product-comment.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,46 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { User } from '@rahino/database/models/core/user.entity'; | ||
import { Permission } from '@rahino/database/models/core/permission.entity'; | ||
import { ECProductComment } from '@rahino/database/models/ecommerce-eav/ec-product-comment.entity'; | ||
import { ProductCommentController } from './product-comment.controller'; | ||
import { ProductCommentService } from './product-comment.service'; | ||
import { BullModule } from '@nestjs/bullmq'; | ||
import { SCORE_COMMENT_QUEUE } from './constants'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { CalculateCommentScoreService } from './services'; | ||
import { ScoreCommentProcessor } from './processor'; | ||
import { ECProductCommentFactor } from '@rahino/database/models/ecommerce-eav/ec-product-comment-factor.entity'; | ||
import { ECProduct } from '@rahino/database/models/ecommerce-eav/ec-product.entity'; | ||
import { DBLoggerModule } from '@rahino/logger'; | ||
|
||
@Module({ | ||
imports: [ | ||
BullModule.registerQueueAsync({ | ||
name: SCORE_COMMENT_QUEUE, | ||
inject: [ConfigService], | ||
useFactory: (config: ConfigService) => ({ | ||
connection: { | ||
host: config.get<string>('REDIS_ADDRESS'), | ||
port: config.get<number>('REDIS_PORT'), | ||
password: config.get<string>('REDIS_PASSWORD'), | ||
}, | ||
}), | ||
}), | ||
SequelizeModule.forFeature([ | ||
User, | ||
Permission, | ||
ECProductComment, | ||
ECProductCommentFactor, | ||
ECProduct, | ||
]), | ||
DBLoggerModule, | ||
], | ||
controllers: [ProductCommentController], | ||
providers: [ | ||
ProductCommentService, | ||
CalculateCommentScoreService, | ||
ScoreCommentProcessor, | ||
], | ||
}) | ||
export class AdminProductCommentModule {} |
Oops, something went wrong.