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);
|
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 { Controller } from '@nestjs/common';
|
||||||
import { MessagePattern, Payload } from '@nestjs/microservices';
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
||||||
import { PostCommentsService } from './post-comments.service';
|
import { PostCommentsService } from './post-comments.service';
|
||||||
import { CreatePostCommentDto } from './dto/create-post-comment.dto';
|
import { Comment, CommentDocument } from '../schemas/post-comment.schema';
|
||||||
import { UpdatePostCommentDto } from './dto/update-post-comment.dto';
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class PostCommentsController {
|
export class PostCommentsController {
|
||||||
constructor(private readonly postCommentsService: PostCommentsService) {}
|
constructor(private readonly postCommentsService: PostCommentsService) {}
|
||||||
|
|
||||||
@MessagePattern('createPostComment')
|
@MessagePattern({ cmd: 'createComment' })
|
||||||
create(@Payload() createPostCommentDto: CreatePostCommentDto) {
|
create(@Payload() comment: CommentDocument) {
|
||||||
return this.postCommentsService.create(createPostCommentDto);
|
return this.postCommentsService.create(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern('findAllPostComments')
|
@MessagePattern({ cmd: 'findAllComments' })
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.postCommentsService.findAll();
|
return this.postCommentsService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern('findOnePostComment')
|
@MessagePattern({cmd: 'findOneComment'})
|
||||||
findOne(@Payload() id: number) {
|
findOne(@Payload() id: string) {
|
||||||
return this.postCommentsService.findOne(id);
|
let _id = id['id'];
|
||||||
|
return this.postCommentsService.findOne(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern('updatePostComment')
|
@MessagePattern({ cmd: 'updateComment' })
|
||||||
update(@Payload() updatePostCommentDto: UpdatePostCommentDto) {
|
update(@Payload() comment: CommentDocument) {
|
||||||
return this.postCommentsService.update(updatePostCommentDto.id, updatePostCommentDto);
|
return this.postCommentsService.update(comment.id, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern('removePostComment')
|
@MessagePattern({ cmd: 'removeComment' })
|
||||||
remove(@Payload() id: number) {
|
remove(@Payload() id: string) {
|
||||||
return this.postCommentsService.remove(id);
|
let _id = id['id'];
|
||||||
|
return this.postCommentsService.remove(_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { PostCommentsService } from './post-comments.service';
|
import { PostCommentsService } from './post-comments.service';
|
||||||
import { PostCommentsController } from './post-comments.controller';
|
import { PostCommentsController } from './post-comments.controller';
|
||||||
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
import { Comment, CommentSchema } from '../schemas/post-comment.schema';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [
|
||||||
|
MongooseModule.forFeature([{ name: Comment.name, schema: CommentSchema }]),
|
||||||
|
],
|
||||||
controllers: [PostCommentsController],
|
controllers: [PostCommentsController],
|
||||||
providers: [PostCommentsService]
|
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 { Injectable } from '@nestjs/common';
|
||||||
import { CreatePostCommentDto } from './dto/create-post-comment.dto';
|
import { Comment, CommentDocument } from '../schemas/post-comment.schema';
|
||||||
import { UpdatePostCommentDto } from './dto/update-post-comment.dto';
|
import { Model } from 'mongoose';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PostCommentsService {
|
export class PostCommentsService {
|
||||||
create(createPostCommentDto: CreatePostCommentDto) {
|
constructor(
|
||||||
return 'This action adds a new postComment';
|
@InjectModel(Comment.name) private readonly commentModel: Model<CommentDocument>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async create(comment: CommentDocument): Promise<Comment> {
|
||||||
|
return this.commentModel.create(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
async findAll(): Promise<Comment[]> {
|
||||||
return `This action returns all postComments`;
|
return this.commentModel
|
||||||
|
.find()
|
||||||
|
.setOptions({ sanitizeFilter: true })
|
||||||
|
.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: number) {
|
async findOne(id: string): Promise<Comment> {
|
||||||
return `This action returns a #${id} postComment`;
|
return this.commentModel.findOne({ _id: id }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, updatePostCommentDto: UpdatePostCommentDto) {
|
async findOneByDNI(dni: string): Promise<Comment> {
|
||||||
return `This action updates a #${id} postComment`;
|
return this.commentModel.findOne({ dni: dni }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
async update(id: string, comment: CommentDocument) {
|
||||||
return `This action removes a #${id} postComment`;
|
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