Przeglądaj źródła

feat(users): 添加用户最大发送数功能

- 在用户实体中添加 maxSend 字段,用于限制用户单条号码最大发送数
- 在任务服务中实现根据用户最大发送数设置任务发送间隔
- 在用户控制器和服务中添加更新用户最大发送数的方法
- 实现更新用户最大发送数的操作日志记录
wui 1 rok temu
rodzic
commit
5100929dbc

+ 6 - 0
src/task/task.service.ts

@@ -154,6 +154,12 @@ export class TaskService implements OnModuleInit {
             }
             task.paid = true
         }
+
+        // 用户单条号码最大发送数
+        const users = await this.userRepository.findOneBy({ id: task.userId })
+        if (users.maxSend > 0) {
+            task.requestNumberInterval = users.maxSend
+        }
         task = await this.taskRepository.save(task)
         if (task.paid) {
             try {

+ 3 - 0
src/users/entities/users.entity.ts

@@ -75,4 +75,7 @@ export class Users {
 
     @Column({ nullable: true })
     twoFactorCode: string
+
+    @Column({ default: 0 })
+    maxSend: number
 }

+ 12 - 0
src/users/users.controller.ts

@@ -20,6 +20,7 @@ import { Public } from 'src/auth/public.decorator'
 import { OperationLogService } from '../operation-log/operation-log.service'
 import { OperationType } from '../operation-log/entities/operation-log.entity'
 import { Role } from 'src/model/role.enum'
+import Decimal from 'decimal.js'
 
 @ApiTags('users')
 @Controller('users')
@@ -103,4 +104,15 @@ export class UsersController {
     public async hasInvite(@Param('userId') userId: string) {
         return await this.usersService.hasInvite(parseInt(userId))
     }
+
+    @Get('/updateMaxSend/:userId/:maxSend')
+    public async updateMaxSend(@Req() req, @Param('userId') userId: number, @Param('maxSend') value: number) {
+        const users = await this.usersService.updateMaxSend(userId, value)
+        if (users) {
+            await this.operationLogService.create(req, users, 'Users', OperationType.UPDATE, '修改最大发送数', users.maxSend)
+            return 'update maxSend success!'
+        } else {
+            return 'update maxSend fail!'
+        }
+    }
 }

+ 7 - 3
src/users/users.service.ts

@@ -154,9 +154,7 @@ export class UsersService implements OnModuleInit {
 
                 const verified = await verifyPasscode(user.twoFactorCode, code)
                 if (!verified) {
-                    throw new UnauthorizedException(
-                        "Username or password or Authentication code doesn't match"
-                    )
+                    throw new UnauthorizedException("Username or password or Authentication code doesn't match")
                 }
             }
         }
@@ -411,4 +409,10 @@ export class UsersService implements OnModuleInit {
             hasInvite: !!user
         }
     }
+
+    public async updateMaxSend(userId: number, maxSend: number) {
+        const user = await this.userRepository.findOneBy({ id: userId })
+        user.maxSend = maxSend
+        return await this.userRepository.save(user)
+    }
 }