mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
Post editing by its order num
This commit is contained in:
@@ -40,6 +40,12 @@ export class PostController {
|
|||||||
return await this.postService.editPost(postId, data);
|
return await this.postService.editPost(postId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({ description: 'Editing post text by its order num' })
|
||||||
|
@Post('edit-post-by-order-num/:order')
|
||||||
|
async editPostByOrderNum(@Param('order') order: string, @Body() data: IEditPost) {
|
||||||
|
return await this.postService.editPostByOrderNum(order, data);
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation({ description: 'Get post to post' })
|
@ApiOperation({ description: 'Get post to post' })
|
||||||
@Get('post')
|
@Get('post')
|
||||||
async post() {
|
async post() {
|
||||||
|
|||||||
@@ -52,6 +52,30 @@ export class PostService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async editPostByOrderNum(order: string, data: IEditPost) {
|
||||||
|
try {
|
||||||
|
this.logger.log(`[post.editPostByOrderNum] data: ${JSON.stringify(data)}`);
|
||||||
|
const posts = await this.postRepository.find({ where: { posted: false }, order: { timestamp: 'ASC' } });
|
||||||
|
if (Math.abs(+order) > posts.length) {
|
||||||
|
throw new HttpException('There are only ' + posts.length + ' unsent messages.', HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
const post = posts[Math.abs(+order) - 1];
|
||||||
|
if (post.text !== data.text) {
|
||||||
|
post.text = data.text;
|
||||||
|
post.edit_timestamp = new Date();
|
||||||
|
await this.postRepository.save(post);
|
||||||
|
}
|
||||||
|
return post;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof HttpException) {
|
||||||
|
this.logger.debug(`[post.editPostByOrderNum] Order: ${order} is bad`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
this.logger.debug(`[post.editPostByOrderNum] Bad data. Order: ${order}. Data: ${JSON.stringify(data)}`);
|
||||||
|
throw new HttpException('Server error', HttpStatus.BAD_GATEWAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getAllPosts(status: EGetAll) {
|
async getAllPosts(status: EGetAll) {
|
||||||
try {
|
try {
|
||||||
let obj: object;
|
let obj: object;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ services:
|
|||||||
container_name: neuro_db_dev
|
container_name: neuro_db_dev
|
||||||
image: postgres:alpine
|
image: postgres:alpine
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=${DATABASE_USER}
|
- POSTGRES_USERNAME=${DATABASE_USERNAME}
|
||||||
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
||||||
- POSTGRES_DB=${DATABASE_NAME}
|
- POSTGRES_DB=${DATABASE_NAME}
|
||||||
- PGDATA=/var/lib/postgresql/data/pgdata
|
- PGDATA=/var/lib/postgresql/data/pgdata
|
||||||
|
|||||||
Reference in New Issue
Block a user