katoikia-app/servicio-comunidad-viviendas/src/communities/communities.service.ts

41 lines
1.1 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { Model } from 'mongoose';
import { Community, CommunityDocument } from 'src/schemas/community.schema';
import { InjectModel } from '@nestjs/mongoose';
@Injectable()
export class CommunitiesService {
constructor(
@InjectModel(Community.name) private readonly communityModel: Model<CommunityDocument>,
) {}
async create(community: CommunityDocument): Promise<Community> {
return this.communityModel.create(community);
}
async findAll(): Promise<Community[]> {
return this.communityModel
.find()
.setOptions({ sanitizeFilter: true })
.exec();
}
findOne(id: string): Promise<Community> {
return this.communityModel.findOne({ _id: id }).exec();
}
findOneName(id: string): Promise<Community> {
return this.communityModel.findOne({ _id: "62be68215692582bbfd77134" }).exec();
}
update(id: string, community: CommunityDocument) {
return this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true,
});
}
async remove(id: string) {
return this.communityModel.findByIdAndRemove({ _id: id }).exec();
}
}