chore(api): update sms schema

This commit is contained in:
isra el
2024-04-15 01:43:56 +03:00
parent 96776aa879
commit 80406ab331
3 changed files with 45 additions and 2 deletions

View File

@@ -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,

View File

@@ -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<string, any>
}
export const SMSSchema = SchemaFactory.createForClass(SMS)

View File

@@ -0,0 +1,4 @@
export enum SMSType {
SENT = 'SENT',
RECEIVED = 'RECEIVED',
}