mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
Post get by order
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
||||
import { EGetAll } from 'libs/enums/getAll.enum';
|
||||
import { ICreatePost, IEditPost } from './post.dto';
|
||||
@@ -52,6 +52,12 @@ export class PostController {
|
||||
return await this.postService.post();
|
||||
}
|
||||
|
||||
@ApiOperation({ description: 'Get post by order' })
|
||||
@Get('get-post-by-order/:order')
|
||||
async getPostByOrder(@Param('order') order: number) {
|
||||
return await this.postService.getPostByOrder(order);
|
||||
}
|
||||
|
||||
@ApiOperation({ description: 'Delete post by order' })
|
||||
@Delete('delete-post-by-order/:order')
|
||||
async deletePostByOrder(@Param('order') order: number) {
|
||||
|
||||
@@ -114,6 +114,24 @@ export class PostService {
|
||||
}
|
||||
}
|
||||
|
||||
async getPostByOrder(order: number) {
|
||||
try {
|
||||
this.logger.log(`[post.getPostByOrder] data: ${order}`);
|
||||
const posts = await this.postRepository.find({
|
||||
relations: { images: true },
|
||||
order: { timestamp: 'ASC' },
|
||||
where: { posted: false, deleted: false },
|
||||
});
|
||||
if (Math.abs(+order) > posts.length) {
|
||||
throw new HttpException('There are only ' + posts.length + ' posts.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return posts[Math.abs(+order) - 1];
|
||||
} catch (error) {
|
||||
this.logger.log(`[post.getPostByOrder] error: ${JSON.stringify(error)}`);
|
||||
throw new HttpException('No post with this id', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
async getByMediaGroup(mediaGroupId: string) {
|
||||
try {
|
||||
this.logger.log(`[post.getByMediaGroup] data: ${mediaGroupId}`);
|
||||
|
||||
Reference in New Issue
Block a user