mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-15 04:59:42 +03:00
Added post editing
This commit is contained in:
@@ -4,7 +4,7 @@ import { Admin } from 'libs/database/admin.entity';
|
||||
import { Post } from 'libs/database/post.entity';
|
||||
import { EGetAll } from 'libs/enums/getAll.enum';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ICreatePost } from './post.dto';
|
||||
import { ICreatePost, IEditPost } from './post.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PostService {
|
||||
@@ -25,13 +25,32 @@ export class PostService {
|
||||
timestamp: new Date(),
|
||||
});
|
||||
this.logger.log(`Created new post: ${result.uuid}`);
|
||||
return { status: 'ok' };
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.logger.debug(`[post.newPost] error: ${JSON.stringify(error)}`);
|
||||
throw new HttpException('No user with this id', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
async editPost(postId: string, data: IEditPost) {
|
||||
try {
|
||||
this.logger.log(`[post.editPost] data: ${JSON.stringify(data)}`);
|
||||
const post = await this.postRepository.findOne({ where: { uuid: postId } });
|
||||
if (!post) {
|
||||
throw new HttpException('Post not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if (post.text !== data.text) {
|
||||
post.text = data.text;
|
||||
post.timestamp = new Date();
|
||||
await this.postRepository.save(post);
|
||||
}
|
||||
return post;
|
||||
} catch (error) {
|
||||
this.logger.debug(`[post.editPost] error: ${JSON.stringify(error)}`);
|
||||
throw new HttpException('Post not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
async getAllPosts(status: EGetAll) {
|
||||
try {
|
||||
let obj: object;
|
||||
|
||||
Reference in New Issue
Block a user