2022-07-01 07:39:52 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-07-25 04:38:48 +00:00
|
|
|
import { CommonArea, CommonAreaDocument } from 'src/schemas/common_area.schema';
|
2022-07-01 07:39:52 +00:00
|
|
|
import { InjectModel } from '@nestjs/mongoose';
|
|
|
|
import { Model } from 'mongoose';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CommonAreasService {
|
|
|
|
constructor(
|
2022-07-25 04:38:48 +00:00
|
|
|
@InjectModel(CommonArea.name)
|
|
|
|
private readonly commonAreaModel: Model<CommonAreaDocument>,
|
2022-07-01 07:39:52 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
async create(commonArea: CommonAreaDocument): Promise<CommonArea> {
|
|
|
|
return this.commonAreaModel.create(commonArea);
|
|
|
|
}
|
|
|
|
|
2022-07-25 04:38:48 +00:00
|
|
|
async findAll(): Promise<CommonArea[]> {
|
2022-07-01 07:39:52 +00:00
|
|
|
return this.commonAreaModel
|
2022-07-25 04:38:48 +00:00
|
|
|
.find()
|
|
|
|
.setOptions({ sanitizeFilter: true })
|
2022-07-01 07:39:52 +00:00
|
|
|
.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
findOne(id: string): Promise<CommonArea> {
|
|
|
|
return this.commonAreaModel.findOne({ _id: id }).exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
update(id: string, commonArea: CommonAreaDocument) {
|
|
|
|
return this.commonAreaModel.findOneAndUpdate({ _id: id }, commonArea, {
|
|
|
|
new: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async remove(id: string) {
|
2022-08-01 07:07:04 +00:00
|
|
|
return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
|
|
|
|
new: true,
|
|
|
|
});
|
|
|
|
};
|
2022-08-01 06:33:48 +00:00
|
|
|
|
|
|
|
async findByCommunity(community_id: string): Promise<CommonArea[]> {
|
|
|
|
return this.commonAreaModel.find({ community_id: community_id }).exec();
|
|
|
|
}
|
|
|
|
|
2022-07-01 07:39:52 +00:00
|
|
|
}
|