Browse Source

chore(api): update sms schema

pull/8/head
isra el 2 years ago
parent
commit
80406ab331
  1. 5
      api/src/gateway/gateway.module.ts
  2. 38
      api/src/gateway/schemas/sms.schema.ts
  3. 4
      api/src/gateway/sms-type.enum.ts

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

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

4
api/src/gateway/sms-type.enum.ts

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