2022-06-29 10:12:27 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Model } from 'mongoose';
|
|
|
|
import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
|
|
|
import { InjectModel } from '@nestjs/mongoose';
|
|
|
|
import { Request } from 'express';
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
update(id: string, community: CommunityDocument) {
|
|
|
|
return this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
|
|
|
new: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-01 01:42:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-29 10:12:27 +00:00
|
|
|
async remove(id: string) {
|
|
|
|
return this.communityModel.findByIdAndRemove({ _id: id }).exec();
|
|
|
|
}
|
|
|
|
}
|