forked from Yara724/api
Centralized SMS services YARA-834
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { SmsText, SmsTextDocument } from "../schema/sms-text.schema";
|
||||
|
||||
@Injectable()
|
||||
export class SmsTextDbService {
|
||||
constructor(
|
||||
@InjectModel(SmsText.name)
|
||||
private readonly smsTextModel: Model<SmsTextDocument>,
|
||||
) {}
|
||||
|
||||
async findOne(filter: FilterQuery<SmsText>): Promise<SmsTextDocument | null> {
|
||||
return this.smsTextModel.findOne(filter);
|
||||
}
|
||||
|
||||
async upsert(key: string, text: string): Promise<void> {
|
||||
await this.smsTextModel.updateOne(
|
||||
{ key },
|
||||
{ $setOnInsert: { key, text, active: true } },
|
||||
{ upsert: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user