Просмотр исходного кода

更新用户角色权限验证逻辑,将用户角色从 USER 调整为 PROMOTER,新增 PROMOTER 角色以支持推广相关功能,同时更新相关控制器和路由以适应新的角色权限。

wuyi 3 месяцев назад
Родитель
Сommit
2e9151c278

+ 1 - 1
src/controllers/income-records.controller.ts

@@ -91,7 +91,7 @@ export class IncomeRecordsController {
         if (team) {
           request.query.teamId = team.id
         }
-      } else if (user.role === UserRole.USER) {
+      } else if (user.role === UserRole.PROMOTER) {
         request.query.userId = user.id
       }
 

+ 1 - 1
src/controllers/promotion-link.controller.ts

@@ -47,7 +47,7 @@ export class PromotionLinkController {
       if (!user) {
         return reply.code(403).send({ message: '用户未登录' })
       }
-      if (user.role === UserRole.USER) {
+      if (user.role === UserRole.PROMOTER) {
         const teamMembers = await this.teamMembersService.findByUserId(user.id)
         request.query.teamId = teamMembers.teamId
       } else if (user.role === UserRole.TEAM) {

+ 1 - 3
src/controllers/team-members.controller.ts

@@ -44,9 +44,7 @@ export class TeamMembersController {
       if (!user) {
         return reply.code(403).send({ message: '用户未登录' })
       }
-      if (user.role === UserRole.USER) {
-        return reply.code(403).send({ message: '用户无权限' })
-      } else if (user.role === UserRole.TEAM) {
+      if (user.role === UserRole.TEAM) {
         const team = await this.teamService.findByUserId(user.id)
         request.query.teamId = team.id
       }

+ 1 - 6
src/controllers/team.controller.ts

@@ -35,9 +35,7 @@ export class TeamController {
       if (!user) {
         return reply.code(403).send({ message: '用户未登录' })
       }
-      if (user.role === UserRole.USER) {
-        return reply.code(403).send({ message: '用户无权限' })
-      } else if (user.role === UserRole.TEAM) {
+      if (user.role === UserRole.TEAM) {
         request.query.userId = user.id
       }
       const result = await this.teamService.findAll(request.query)
@@ -132,9 +130,6 @@ export class TeamController {
       if (!user) {
         return reply.code(403).send({ message: '用户未登录' })
       }
-      if (user.role === UserRole.USER) {
-        return reply.code(403).send({ message: '用户无权限' })
-      }
       const team = await this.teamService.findByUserId(user.id)
       return reply.send(team)
     } catch (error) {

+ 1 - 0
src/entities/user.entity.ts

@@ -3,6 +3,7 @@ import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateCol
 export enum UserRole {
   ADMIN = 'admin',
   TEAM = 'team',
+  PROMOTER = 'promoter',
   USER = 'user'
 }
 

+ 1 - 1
src/routes/income-records.routes.ts

@@ -22,7 +22,7 @@ export default async function incomeRecordsRoutes(fastify: FastifyInstance) {
   // 获取收入记录列表
   fastify.get<{ Querystring: ListIncomeRecordsQuery }>(
     '/',
-    { onRequest: [authenticate, hasAnyRole(UserRole.ADMIN, UserRole.TEAM, UserRole.USER)] },
+    { onRequest: [authenticate, hasAnyRole(UserRole.ADMIN, UserRole.TEAM, UserRole.PROMOTER)] },
     incomeRecordsController.findAll.bind(incomeRecordsController)
   )
 

+ 1 - 1
src/routes/promotion-link.routes.ts

@@ -23,7 +23,7 @@ export default async function promotionLinkRoutes(fastify: FastifyInstance) {
   // 获取推广链接列表
   fastify.get<{ Querystring: ListPromotionLinkQuery }>(
     '/',
-    { onRequest: [authenticate, hasAnyRole(UserRole.ADMIN, UserRole.TEAM, UserRole.USER)] },
+    { onRequest: [authenticate, hasAnyRole(UserRole.ADMIN, UserRole.TEAM, UserRole.PROMOTER)] },
     promotionLinkController.findAll.bind(promotionLinkController)
   )
 

+ 1 - 1
src/services/team-members.service.ts

@@ -25,7 +25,7 @@ export class TeamMembersService {
 
     const userPassword = password || 'password123'
     const parentId = teamUserId || creatorId
-    const createdUser = await this.userService.create(userPassword, teamMemberData.name, UserRole.USER, parentId)
+    const createdUser = await this.userService.create(userPassword, teamMemberData.name, UserRole.PROMOTER, parentId)
 
     const teamMember = this.teamMembersRepository.create({
       ...teamMemberData,