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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
17
src/sms-orchestration/entities/schema/sms-text.schema.ts
Normal file
17
src/sms-orchestration/entities/schema/sms-text.schema.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
||||
import { HydratedDocument } from "mongoose";
|
||||
|
||||
@Schema({ collection: "sms-texts", timestamps: true, versionKey: false })
|
||||
export class SmsText {
|
||||
@Prop({ required: true, unique: true, index: true })
|
||||
key: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
text: string;
|
||||
|
||||
@Prop({ default: true })
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export type SmsTextDocument = HydratedDocument<SmsText>;
|
||||
export const SmsTextSchema = SchemaFactory.createForClass(SmsText);
|
||||
Reference in New Issue
Block a user