@arsendoman/book-publisher-store
Version:
A Nest.js package for book publishing and storing
155 lines (147 loc) • 4.7 kB
text/typescript
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Request,
SerializeOptions,
UseGuards,
} from '@nestjs/common';
import { Roles } from '../../database/mongo/schemas';
import { AllowedRoles } from 'src/application/decorators/roles.decorator';
import { PermissionGuard } from 'src/application/guards/auth.guard';
import { JwtAuthGuard } from '../../application/guards/jwt.auth.guard';
import { ApiBearerAuth, ApiHeader, ApiParam, ApiQuery } from '@nestjs/swagger';
import { BooksCommentsService } from '../../application/services/books/comments/book.comments.service';
import { BookCommentCreateDto } from '../../application/dtos/request/comment/comment.create.dto';
import { BookCommentResponseDto } from '../../application/dtos/response/book/comments/book.comment.response.dto';
import { RequestInterface } from '../../application/auth/types/request.auth';
import { BookCommentUpdateDto } from '../../application/dtos/request/comment/comment.update.dto';
import { PaginationParams } from '../../application/decorators/pagination.decorator';
import { IPagination } from '../../core/interfaces/pagination.interface';
import { SortingParams } from '../../application/decorators/sort.decorator';
import { PaginatedResponseDto } from '../../application/dtos/response/paginatedResponse.dto';
import { BookCommentActionDto } from '../../application/dtos/request/comment/comment.action.dto';
export class BookCommentsController {
constructor(private readonly commentsService: BooksCommentsService) {}
createComment(
bookId: string,
createCommentDto: BookCommentCreateDto,
req: RequestInterface,
): Promise<BookCommentResponseDto> {
return this.commentsService.createComment(
bookId,
req.user.username,
createCommentDto,
);
}
updateComment(
bookId: string,
commentId: string,
bookCommentUpdateDto: BookCommentUpdateDto,
req: RequestInterface,
): Promise<BookCommentResponseDto> {
return this.commentsService.updateComment(
bookId,
commentId,
req.user.username,
bookCommentUpdateDto,
);
}
fetchCommentsList(
bookId: string,
pagination: IPagination,
sorting,
): Promise<PaginatedResponseDto<BookCommentResponseDto>> {
return this.commentsService.fetchCommentsList(pagination, sorting, bookId);
}
performCommentAction(
bookId: string,
commentId: string,
action: BookCommentActionDto,
req: RequestInterface,
): Promise<BookCommentResponseDto> {
return this.commentsService.performCommentAction(
commentId,
req.user.id,
action,
);
}
deleteAllBookComments( bookId: string) {
this.commentsService.deleteAllBookComments(bookId);
}
}