From 80406ab3310fd8f7de263ab404014c8b577977c0 Mon Sep 17 00:00:00 2001 From: isra el Date: Mon, 15 Apr 2024 01:43:56 +0300 Subject: [PATCH] chore(api): update sms schema --- api/src/gateway/gateway.module.ts | 5 ++++ api/src/gateway/schemas/sms.schema.ts | 38 +++++++++++++++++++++++++-- api/src/gateway/sms-type.enum.ts | 4 +++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 api/src/gateway/sms-type.enum.ts diff --git a/api/src/gateway/gateway.module.ts b/api/src/gateway/gateway.module.ts index 34052d6..167bc67 100644 --- a/api/src/gateway/gateway.module.ts +++ b/api/src/gateway/gateway.module.ts @@ -5,6 +5,7 @@ import { GatewayController } from './gateway.controller' import { GatewayService } from './gateway.service' import { AuthModule } from '../auth/auth.module' import { UsersModule } from '../users/users.module' +import { SMS, SMSSchema } from './schemas/sms.schema' @Module({ imports: [ @@ -13,6 +14,10 @@ import { UsersModule } from '../users/users.module' name: Device.name, schema: DeviceSchema, }, + { + name: SMS.name, + schema: SMSSchema, + }, ]), AuthModule, UsersModule, diff --git a/api/src/gateway/schemas/sms.schema.ts b/api/src/gateway/schemas/sms.schema.ts index 98772ee..348c8f3 100644 --- a/api/src/gateway/schemas/sms.schema.ts +++ b/api/src/gateway/schemas/sms.schema.ts @@ -1,6 +1,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' import { Document, Types } from 'mongoose' import { Device } from './device.schema' +import { SMSType } from '../sms-type.enum' export type SMSDocument = SMS & Document @@ -8,14 +9,47 @@ export type SMSDocument = SMS & Document export class SMS { _id?: Types.ObjectId - @Prop({ type: Types.ObjectId, ref: Device.name }) + @Prop({ type: Types.ObjectId, ref: Device.name, required: true }) device: Device @Prop({ type: String, required: true }) message: string @Prop({ type: String, required: true }) - to: string + type: string + + // fields for incoming messages + @Prop({ type: String }) + sender: string + + @Prop({ type: Date, default: Date.now }) + receivedAt: Date + + // fields for outgoing messages + @Prop({ type: String }) + recipient: string + + @Prop({ type: Date, default: Date.now }) + requestedAt: Date + + @Prop({ type: Date }) + sentAt: Date + + @Prop({ type: Date }) + deliveredAt: Date + + @Prop({ type: Date }) + failedAt: Date + + // @Prop({ type: String }) + // failureReason: string + + // @Prop({ type: String }) + // status: string + + // misc metadata for debugging + @Prop({ type: Object }) + metadata: Record } export const SMSSchema = SchemaFactory.createForClass(SMS) diff --git a/api/src/gateway/sms-type.enum.ts b/api/src/gateway/sms-type.enum.ts new file mode 100644 index 0000000..7c7203b --- /dev/null +++ b/api/src/gateway/sms-type.enum.ts @@ -0,0 +1,4 @@ +export enum SMSType { + SENT = 'SENT', + RECEIVED = 'RECEIVED', +}