- Reordered and grouped imports consistently in backend and frontend files for better readability. - Applied indentation and formatting fixes across frontend components, services, and backend modules. - Adjusted multiline method calls and type definitions for improved clarity.
38 lines
1019 B
TypeScript
38 lines
1019 B
TypeScript
import {
|
|
ForbiddenException,
|
|
Injectable,
|
|
NotFoundException,
|
|
} from "@nestjs/common";
|
|
import type { CreateCommentDto } from "./dto/create-comment.dto";
|
|
import { CommentsRepository } from "./repositories/comments.repository";
|
|
|
|
@Injectable()
|
|
export class CommentsService {
|
|
constructor(private readonly commentsRepository: CommentsRepository) {}
|
|
|
|
async create(userId: string, contentId: string, dto: CreateCommentDto) {
|
|
return this.commentsRepository.create({
|
|
userId,
|
|
contentId,
|
|
text: dto.text,
|
|
});
|
|
}
|
|
|
|
async findAllByContentId(contentId: string) {
|
|
return this.commentsRepository.findAllByContentId(contentId);
|
|
}
|
|
|
|
async remove(userId: string, commentId: string, isAdmin = false) {
|
|
const comment = await this.commentsRepository.findOne(commentId);
|
|
if (!comment) {
|
|
throw new NotFoundException("Comment not found");
|
|
}
|
|
|
|
if (!isAdmin && comment.userId !== userId) {
|
|
throw new ForbiddenException("You cannot delete this comment");
|
|
}
|
|
|
|
await this.commentsRepository.delete(commentId);
|
|
}
|
|
}
|