mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 12:49:41 +03:00
Get post to post method
This commit is contained in:
@@ -39,4 +39,10 @@ export class PostController {
|
|||||||
async editPost(@Param('postId') postId: string, @Body() data: IEditPost) {
|
async editPost(@Param('postId') postId: string, @Body() data: IEditPost) {
|
||||||
return await this.postService.editPost(postId, data);
|
return await this.postService.editPost(postId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({ description: 'Get post to post' })
|
||||||
|
@Get('post')
|
||||||
|
async post() {
|
||||||
|
return await this.postService.post();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,23 @@ export class PostService {
|
|||||||
throw new HttpException("Can't find post with this media group id", HttpStatus.BAD_REQUEST);
|
throw new HttpException("Can't find post with this media group id", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async post() {
|
||||||
|
try {
|
||||||
|
const posts = await this.postRepository.find({ order: { timestamp: 'ASC' }, where: { posted: false }, relations: { images: true } });
|
||||||
|
if (!posts) throw new HttpException('Nothing to post', HttpStatus.NOT_FOUND);
|
||||||
|
const post = posts[0];
|
||||||
|
post.posted = true;
|
||||||
|
this.logger.log(`[post.post] Post ${post.uuid} is posted`);
|
||||||
|
await this.postRepository.save(post);
|
||||||
|
return post;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof HttpException) {
|
||||||
|
this.logger.debug('[post.post] Not found');
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
this.logger.debug(`[post.post] error: ${JSON.stringify(error)}`);
|
||||||
|
throw new HttpException('Bad data', HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user