add comentario de comunicados
agregar methodos en api gateway, conexion a bd
This commit is contained in:
parent
06dc11e297
commit
2b6524d8b9
|
@ -220,4 +220,29 @@ export class AppController {
|
|||
) {
|
||||
return this.appService.findPost(paramPost);
|
||||
}
|
||||
|
||||
|
||||
// #==== API Comment
|
||||
|
||||
@Post('post/createComment')
|
||||
createComment(
|
||||
@Body('comment') comment: string,
|
||||
@Body('date_entry') date_entry: Date,
|
||||
@Body('user_id') user_id: string,
|
||||
@Body('post_id') post_id: string,
|
||||
) {
|
||||
return this.appService.createComment(comment, date_entry, user_id, post_id);
|
||||
}
|
||||
|
||||
@Get('post/allComments')
|
||||
allComments() {
|
||||
return this.appService.allComments();
|
||||
}
|
||||
|
||||
@Get('post/findComment/:id')
|
||||
findComment(
|
||||
@Param('id') paramComment: string
|
||||
) {
|
||||
return this.appService.findComment(paramComment);
|
||||
}
|
||||
}
|
|
@ -304,4 +304,41 @@ export class AppService {
|
|||
);
|
||||
}
|
||||
|
||||
// ====================== COMMNENT POSTS ===============================
|
||||
|
||||
//Comment parameter from API
|
||||
createComment(comment: string, date_entry: Date, user_id: string,
|
||||
post_id: string) {
|
||||
const pattern = { cmd: 'createComment' };
|
||||
const payload = {
|
||||
comment: comment, date_entry: date_entry, user_id: user_id,
|
||||
post_id: post_id
|
||||
};
|
||||
return this.clientPostApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
allComments() {
|
||||
const pattern = { cmd: 'findAllComments' };
|
||||
const payload = {};
|
||||
return this.clientPostApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
//GET parameter from API
|
||||
findComment(paramCommentId: string) {
|
||||
const pattern = { cmd: 'findOneComment' };
|
||||
const payload = { id: paramCommentId };
|
||||
return this.clientPostApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
export class CreatePostCommentDto {}
|
|
@ -1,6 +0,0 @@
|
|||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreatePostCommentDto } from './create-post-comment.dto';
|
||||
|
||||
export class UpdatePostCommentDto extends PartialType(CreatePostCommentDto) {
|
||||
id: number;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
export class PostComment {}
|
|
@ -1,20 +0,0 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PostCommentsController } from './post-comments.controller';
|
||||
import { PostCommentsService } from './post-comments.service';
|
||||
|
||||
describe('PostCommentsController', () => {
|
||||
let controller: PostCommentsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PostCommentsController],
|
||||
providers: [PostCommentsService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PostCommentsController>(PostCommentsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -1,35 +1,37 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
import { MessagePattern, Payload } from '@nestjs/microservices';
|
||||
import { PostCommentsService } from './post-comments.service';
|
||||
import { CreatePostCommentDto } from './dto/create-post-comment.dto';
|
||||
import { UpdatePostCommentDto } from './dto/update-post-comment.dto';
|
||||
import { Comment, CommentDocument } from '../schemas/post-comment.schema';
|
||||
|
||||
|
||||
@Controller()
|
||||
export class PostCommentsController {
|
||||
constructor(private readonly postCommentsService: PostCommentsService) {}
|
||||
|
||||
@MessagePattern('createPostComment')
|
||||
create(@Payload() createPostCommentDto: CreatePostCommentDto) {
|
||||
return this.postCommentsService.create(createPostCommentDto);
|
||||
@MessagePattern({ cmd: 'createComment' })
|
||||
create(@Payload() comment: CommentDocument) {
|
||||
return this.postCommentsService.create(comment);
|
||||
}
|
||||
|
||||
@MessagePattern('findAllPostComments')
|
||||
@MessagePattern({ cmd: 'findAllComments' })
|
||||
findAll() {
|
||||
return this.postCommentsService.findAll();
|
||||
}
|
||||
|
||||
@MessagePattern('findOnePostComment')
|
||||
findOne(@Payload() id: number) {
|
||||
return this.postCommentsService.findOne(id);
|
||||
@MessagePattern({cmd: 'findOneComment'})
|
||||
findOne(@Payload() id: string) {
|
||||
let _id = id['id'];
|
||||
return this.postCommentsService.findOne(_id);
|
||||
}
|
||||
|
||||
@MessagePattern('updatePostComment')
|
||||
update(@Payload() updatePostCommentDto: UpdatePostCommentDto) {
|
||||
return this.postCommentsService.update(updatePostCommentDto.id, updatePostCommentDto);
|
||||
@MessagePattern({ cmd: 'updateComment' })
|
||||
update(@Payload() comment: CommentDocument) {
|
||||
return this.postCommentsService.update(comment.id, comment);
|
||||
}
|
||||
|
||||
@MessagePattern('removePostComment')
|
||||
remove(@Payload() id: number) {
|
||||
return this.postCommentsService.remove(id);
|
||||
@MessagePattern({ cmd: 'removeComment' })
|
||||
remove(@Payload() id: string) {
|
||||
let _id = id['id'];
|
||||
return this.postCommentsService.remove(_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { PostCommentsService } from './post-comments.service';
|
||||
import { PostCommentsController } from './post-comments.controller';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Comment, CommentSchema } from '../schemas/post-comment.schema';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([{ name: Comment.name, schema: CommentSchema }]),
|
||||
],
|
||||
controllers: [PostCommentsController],
|
||||
providers: [PostCommentsService]
|
||||
})
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PostCommentsService } from './post-comments.service';
|
||||
|
||||
describe('PostCommentsService', () => {
|
||||
let service: PostCommentsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PostCommentsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PostCommentsService>(PostCommentsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -1,26 +1,41 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CreatePostCommentDto } from './dto/create-post-comment.dto';
|
||||
import { UpdatePostCommentDto } from './dto/update-post-comment.dto';
|
||||
import { Comment, CommentDocument } from '../schemas/post-comment.schema';
|
||||
import { Model } from 'mongoose';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class PostCommentsService {
|
||||
create(createPostCommentDto: CreatePostCommentDto) {
|
||||
return 'This action adds a new postComment';
|
||||
constructor(
|
||||
@InjectModel(Comment.name) private readonly commentModel: Model<CommentDocument>,
|
||||
) {}
|
||||
|
||||
async create(comment: CommentDocument): Promise<Comment> {
|
||||
return this.commentModel.create(comment);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all postComments`;
|
||||
async findAll(): Promise<Comment[]> {
|
||||
return this.commentModel
|
||||
.find()
|
||||
.setOptions({ sanitizeFilter: true })
|
||||
.exec();
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} postComment`;
|
||||
async findOne(id: string): Promise<Comment> {
|
||||
return this.commentModel.findOne({ _id: id }).exec();
|
||||
}
|
||||
|
||||
update(id: number, updatePostCommentDto: UpdatePostCommentDto) {
|
||||
return `This action updates a #${id} postComment`;
|
||||
async findOneByDNI(dni: string): Promise<Comment> {
|
||||
return this.commentModel.findOne({ dni: dni }).exec();
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} postComment`;
|
||||
async update(id: string, comment: CommentDocument) {
|
||||
return this.commentModel.findOneAndUpdate({ _id: id }, comment, {
|
||||
new: true,
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.commentModel.findByIdAndRemove({ _id: id }).exec();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, ObjectId } from 'mongoose';
|
||||
|
||||
|
||||
export type CommentDocument = Comment & Document;
|
||||
|
||||
@Schema({ collection: 'comments' })
|
||||
export class Comment {
|
||||
|
||||
@Prop()
|
||||
comment: string;
|
||||
|
||||
@Prop()
|
||||
date_entry: Date;
|
||||
|
||||
@Prop()
|
||||
user_id: string
|
||||
|
||||
@Prop()
|
||||
post_id: string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const CommentSchema = SchemaFactory.createForClass(Comment);
|
Loading…
Reference in New Issue