Skip to content

Commit

Permalink
feat: 管理员删除帖子
Browse files Browse the repository at this point in the history
  • Loading branch information
Bbbtt04 committed Dec 17, 2023
1 parent 532d044 commit 685dfba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/modules/hole/hole.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@nestjs/common';
import { IUser } from '../user/user.controller';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from 'src/entity/user/user.entity';
import { Role, User } from 'src/entity/user/user.entity';
import { Repository, FindManyOptions, Like } from 'typeorm';
import { Hole } from 'src/entity/hole/hole.entity';
import { Tags } from 'src/entity/hole/tags.entity';
Expand Down Expand Up @@ -101,11 +101,15 @@ export class HoleService {
select: { user: { studentId: true } },
});

const user = await this.userRepo.findOne({
where: { id: dto.id },
});

if (!hole) {
throw new BadRequestException('树洞不存在哦~');
}

if (hole.user.studentId !== reqUser) {
if (hole.user.studentId !== reqUser && user.role !== 'admin') {
throw new ForbiddenException('只能删除自己的树洞哦');
}

Expand Down

0 comments on commit 685dfba

Please sign in to comment.