فهرست منبع

Merge branch 'master' of http://git.izouma.com/xiongzhu/chat-api

wangqifan 2 سال پیش
والد
کامیت
1eaac74f7b

+ 1 - 1
src/aliyun/aliyun.service.ts

@@ -20,7 +20,7 @@ export class AliyunService {
     ) {}
 
     public async sendCode(data: SendCodeDto) {
-        await this.authSig(data.sessionId, data.sig, data.token)
+        //await this.authSig(data.sessionId, data.sig, data.token)
         if (!/^1[3-9]\d{9}$/.test(data.phone)) {
             throw new InternalServerErrorException('手机号码格式不正确')
         }

+ 7 - 1
src/chat-role/chat-role.controller.ts

@@ -18,6 +18,7 @@ import { PageRequest } from '../common/dto/page-request'
 import { ChatRole } from './entities/chat-role.entity'
 import { ChatRoleDto } from './dto/chat-role.dto'
 import { ChatRoleService } from './chat-role.service'
+import { Public } from 'src/auth/public.decorator'
 
 @ApiTags('chatRole')
 @Controller('/chatRole')
@@ -29,10 +30,15 @@ export class ChatRoleController {
 
     @Post()
     public async list(@Body() page: PageRequest<ChatRole>) {
-
         return await this.chatRoleService.findAll(page)
     }
 
+    @Post('/findByPlayName')
+    public async findByPlayName(@Body() chatRole: ChatRole) {
+        return await this.chatRoleService.findByPlayerName(chatRole.playerName)
+    }
+
+    @Public()
     @Get('/getRandom/:num')
     public async randomQuery(@Param('num') num: number) {
         return await this.chatRoleService.randomQuery(num)

+ 11 - 1
src/chat-role/chat-role.service.ts

@@ -23,6 +23,14 @@ export class ChatRoleService {
         return await paginate<ChatRole>(this.chatRoleRepository, req.page, req.search)
     }
 
+    async findByPlayerName(playerName: string): Promise<ChatRole> {
+        const chatRole = await this.chatRoleRepository.findOneBy({ playerName: playerName })
+        if (!chatRole) {
+            throw new NotFoundException(`Associated ChatRole ${playerName} not found`)
+        }
+        return chatRole
+    }
+
     async findMapByIds(ids: number[]): Promise<Map<number, ChatRole>> {
         const chatRoleList = await this.chatRoleRepository.createQueryBuilder('chatRole')
             .where({
@@ -51,7 +59,9 @@ export class ChatRoleService {
 
     public async create(chatRoleDto: ChatRoleDto) {
         const result = await this.chatRoleRepository.save(chatRoleDto)
-        this.labelService.addRoleLabel(result.id, chatRoleDto.labelList)
+        if (Array.isArray(chatRoleDto.labelList) && chatRoleDto.labelList.length > 0) {
+            this.labelService.addRoleLabel(result.id, chatRoleDto.labelList)
+        }
         return result;
     }
 

+ 1 - 1
src/chat-role/dto/chat-role.dto.ts

@@ -15,6 +15,6 @@ export class ChatRoleDto {
     dynamicNumber?: number = 0
 
     @IsArray()
-    labelList?: Label[]
+    labelList?: Label[] = []
 
 }

+ 3 - 0
src/chat-role/entities/chat-role.entity.ts

@@ -11,6 +11,9 @@ export class ChatRole {
     @Column()
     name: string
 
+    @Column()
+    playerName: string
+
     @Column()
     describe: string
 

+ 1 - 1
src/moments/entities/moments.entity.ts

@@ -13,7 +13,7 @@ export class Moments {
     @Column()
     title: string
 
-    @Column()
+    @Column({ type: 'text' })
     content: string
 
     @Column({ default: 0 })

+ 23 - 16
src/moments/moments.service.ts

@@ -1,11 +1,5 @@
 import {
-    Injectable,
-    NotFoundException,
-    HttpException,
-    HttpStatus,
-    BadRequestException,
-    InternalServerErrorException,
-    UnauthorizedException
+    Injectable
 } from '@nestjs/common'
 import { FindManyOptions, In, Repository, UpdateResult } from 'typeorm'
 import { InjectRepository } from '@nestjs/typeorm'
@@ -146,11 +140,13 @@ export class MomentsService {
 
         chatRoleList.forEach(async role => {
             const text = await this.chatService.sendMessage(null, role.condition)
-            const momentsDto = new MomentsDto
-            momentsDto.content = text
-            momentsDto.userId = role.id
-            momentsDto.isPush = false
-            await this.momentsRepository.save(momentsDto)
+            if (text.trim() !== '') {
+                const momentsDto = new MomentsDto
+                momentsDto.content = text
+                momentsDto.userId = role.id
+                momentsDto.isPush = false
+                await this.momentsRepository.save(momentsDto)
+            }
         })
     }
 
@@ -161,9 +157,19 @@ export class MomentsService {
             .getMany()
 
         momentsList.forEach(moments => {
-            const hours = Math.floor(Math.random() * 12)
-            const minutes = Math.floor(Math.random() * 60)
-            console.log(moments.userId + '的动态将在' + hours + '小时' + minutes + '分后发布')
+
+            const targetTime = new Date();
+            targetTime.setHours(Math.floor(Math.random() * 12) + 10);
+            targetTime.setMinutes(Math.floor(Math.random() * 60));
+
+            const now = new Date();
+            const delayTime = targetTime.getTime() - now.getTime();
+
+            console.log(moments.userId + '的动态将在' + delayTime / 1000 / 60 + '分后发布')
+
+            if (delayTime < 0) {
+                delayTime == 0
+            }
             setTimeout(async () => {
                 moments.isPush = true
                 moments.createdAt = new Date()
@@ -171,7 +177,8 @@ export class MomentsService {
                 const chatRole = await this.chatRoleRepository.findOneBy({ id: moments.userId })
                 chatRole.dynamicNumber += 1
                 await this.chatRoleRepository.save(chatRole)
-            }, hours * 60 * 60 * 1000 + minutes * 60 * 1000)
+            }, delayTime)
+
         })
     }
 

+ 7 - 4
src/sms/dto/sms.dto.ts

@@ -1,4 +1,4 @@
-import { IsString, MaxLength } from 'class-validator'
+import { IsOptional, IsString, MaxLength } from 'class-validator'
 
 export class SendCodeDto {
     @IsString()
@@ -6,13 +6,16 @@ export class SendCodeDto {
     readonly phone: string
 
     @IsString()
-    readonly sessionId: string
+    @IsOptional()
+    readonly sessionId?: string
 
     @IsString()
-    readonly sig: string
+    @IsOptional()
+    readonly sig?: string
 
     @IsString()
-    readonly token: string
+    @IsOptional()
+    readonly token?: string
 }
 
 export class VerifyCodeDto {