Skip to content

Commit

Permalink
add product comment admin module
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jun 27, 2024
1 parent 324a134 commit 3b3e477
Show file tree
Hide file tree
Showing 20 changed files with 626 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ lerna-debug.log*
/profile

# qr code
/qrcode
/qrcode


# task
todo.md
2 changes: 2 additions & 0 deletions apps/e-commerce/src/admin/product-comment/constants.ts
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';
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;
}
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;
}
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,
) {}
2 changes: 2 additions & 0 deletions apps/e-commerce/src/admin/product-comment/dto/index.ts
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './score-comment.processor';
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);
}
}
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);
}
}
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 {}
Loading

0 comments on commit 3b3e477

Please sign in to comment.