2022-06-29 10:12:27 +00:00
|
|
|
import { Controller } from '@nestjs/common';
|
|
|
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
|
|
|
import { CommunitiesService } from './communities.service';
|
|
|
|
import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
export class CommunitiesController {
|
|
|
|
constructor(private readonly communitiesService: CommunitiesService) {}
|
|
|
|
|
|
|
|
@MessagePattern({ cmd: 'createCommunity' })
|
|
|
|
create(@Payload() community: CommunityDocument) {
|
|
|
|
return this.communitiesService.create(community);
|
|
|
|
}
|
|
|
|
|
|
|
|
@MessagePattern({cmd: 'findAllCommunities'})
|
|
|
|
findAll() {
|
|
|
|
return this.communitiesService.findAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MessagePattern({cmd: 'findOneCommunity'})
|
|
|
|
findOne(@Payload() id: string) {
|
2022-07-01 09:10:45 +00:00
|
|
|
let _id = id['_id'];
|
|
|
|
return this.communitiesService.findOne(_id);
|
2022-06-29 10:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@MessagePattern({cmd: 'updateCommunity'})
|
|
|
|
update(@Payload() community: CommunityDocument) {
|
|
|
|
return this.communitiesService.update(community.id, community);
|
|
|
|
}
|
|
|
|
|
|
|
|
@MessagePattern({cmd: 'removeCommunity'})
|
|
|
|
remove(@Payload() id: string) {
|
2022-07-01 09:10:45 +00:00
|
|
|
let _id = id['_id'];
|
|
|
|
return this.communitiesService.remove(_id);
|
2022-06-29 10:12:27 +00:00
|
|
|
}
|
|
|
|
}
|