|
@@ -9,14 +9,17 @@ import {
|
|
|
import { LinkType } from '../entities/promotion-link.entity'
|
|
import { LinkType } from '../entities/promotion-link.entity'
|
|
|
import { UserRole } from '../entities/user.entity'
|
|
import { UserRole } from '../entities/user.entity'
|
|
|
import { TeamService } from '../services/team.service'
|
|
import { TeamService } from '../services/team.service'
|
|
|
|
|
+import { TeamMembersService } from '../services/team-members.service'
|
|
|
|
|
|
|
|
export class PromotionLinkController {
|
|
export class PromotionLinkController {
|
|
|
private promotionLinkService: PromotionLinkService
|
|
private promotionLinkService: PromotionLinkService
|
|
|
private teamService: TeamService
|
|
private teamService: TeamService
|
|
|
|
|
+ private teamMembersService: TeamMembersService
|
|
|
|
|
|
|
|
constructor(app: FastifyInstance) {
|
|
constructor(app: FastifyInstance) {
|
|
|
this.promotionLinkService = new PromotionLinkService(app)
|
|
this.promotionLinkService = new PromotionLinkService(app)
|
|
|
this.teamService = new TeamService(app)
|
|
this.teamService = new TeamService(app)
|
|
|
|
|
+ this.teamMembersService = new TeamMembersService(app)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async create(request: FastifyRequest<{ Body: CreatePromotionLinkBody }>, reply: FastifyReply) {
|
|
async create(request: FastifyRequest<{ Body: CreatePromotionLinkBody }>, reply: FastifyReply) {
|
|
@@ -45,7 +48,8 @@ export class PromotionLinkController {
|
|
|
return reply.code(403).send({ message: '用户未登录' })
|
|
return reply.code(403).send({ message: '用户未登录' })
|
|
|
}
|
|
}
|
|
|
if (user.role === UserRole.USER) {
|
|
if (user.role === UserRole.USER) {
|
|
|
- return reply.code(403).send({ message: '用户无权限' })
|
|
|
|
|
|
|
+ const teamMembers = await this.teamMembersService.findByUserId(user.id)
|
|
|
|
|
+ request.query.teamId = teamMembers.teamId
|
|
|
} else if (user.role === UserRole.TEAM) {
|
|
} else if (user.role === UserRole.TEAM) {
|
|
|
const team = await this.teamService.findByUserId(user.id)
|
|
const team = await this.teamService.findByUserId(user.id)
|
|
|
request.query.teamId = team.id
|
|
request.query.teamId = team.id
|