bex-twn/src/resident/resident.service.ts

28 lines
881 B
TypeScript
Raw Normal View History

2022-12-06 12:26:39 +00:00
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
2022-12-06 16:29:27 +00:00
import { takeMongoObject } from 'src/utility';
2022-12-06 12:26:39 +00:00
import { Resident, ResidentDocument } from './schemas/Resident.schema';
@Injectable()
export class ResidentService {
constructor(
@InjectModel(Resident.name) private residentModel: Model<ResidentDocument>,
) {}
public async createResident(resident: Partial<Resident>): Promise<Resident> {
const createdResident = new this.residentModel(resident);
return createdResident.save();
}
2022-12-06 15:47:52 +00:00
public async getResidentBySub(sub: string): Promise<Resident> {
2022-12-07 07:10:04 +00:00
return this.residentModel.findOne({ sub }).exec();
2022-12-06 15:47:52 +00:00
}
2022-12-06 16:29:27 +00:00
public async save(resident: Partial<Resident>): Promise<Resident> {
2022-12-07 07:10:04 +00:00
return this.residentModel
.findOneAndUpdate({ sub: resident.sub }, resident)
.exec();
2022-12-06 16:29:27 +00:00
}
2022-12-06 12:26:39 +00:00
}