|
|
@@ -7,12 +7,16 @@ import {
|
|
|
PromotionLinkParams
|
|
|
} from '../dto/promotion-link.dto'
|
|
|
import { LinkType } from '../entities/promotion-link.entity'
|
|
|
+import { UserRole } from '../entities/user.entity'
|
|
|
+import { TeamService } from '../services/team.service'
|
|
|
|
|
|
export class PromotionLinkController {
|
|
|
private promotionLinkService: PromotionLinkService
|
|
|
+ private teamService: TeamService
|
|
|
|
|
|
constructor(app: FastifyInstance) {
|
|
|
this.promotionLinkService = new PromotionLinkService(app)
|
|
|
+ this.teamService = new TeamService(app)
|
|
|
}
|
|
|
|
|
|
async create(request: FastifyRequest<{ Body: CreatePromotionLinkBody }>, reply: FastifyReply) {
|
|
|
@@ -36,6 +40,16 @@ export class PromotionLinkController {
|
|
|
|
|
|
async findAll(request: FastifyRequest<{ Querystring: ListPromotionLinkQuery }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
+ const user = request.user
|
|
|
+ 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) {
|
|
|
+ const team = await this.teamService.findByUserId(user.id)
|
|
|
+ request.query.teamId = team.id
|
|
|
+ }
|
|
|
const result = await this.promotionLinkService.findAll(request.query)
|
|
|
return reply.send(result)
|
|
|
} catch (error) {
|
|
|
@@ -43,11 +57,14 @@ export class PromotionLinkController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async update(request: FastifyRequest<{ Params: PromotionLinkParams; Body: UpdatePromotionLinkBody }>, reply: FastifyReply) {
|
|
|
+ async update(
|
|
|
+ request: FastifyRequest<{ Params: PromotionLinkParams; Body: UpdatePromotionLinkBody }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { id } = request.params
|
|
|
const updateData = { ...request.body, id }
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
await this.promotionLinkService.findById(id)
|
|
|
} catch (error) {
|
|
|
@@ -64,7 +81,7 @@ export class PromotionLinkController {
|
|
|
async delete(request: FastifyRequest<{ Params: PromotionLinkParams }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
const { id } = request.params
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
await this.promotionLinkService.findById(id)
|
|
|
} catch (error) {
|