Created
September 18, 2021 07:15
-
-
Save hoangsetup/35b8c17a19111e42ee839baf4e612f2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/models/call-state.model.ts | |
import { Schema, Model, model, ObjectId } from 'mongoose'; | |
import CustomerModel from './customer.model'; | |
export enum CallState { | |
RINGING = 'RINGING', | |
OFFHOOK = 'OFFHOOK', | |
IDLE = 'IDLE', | |
} | |
export interface ICallState { | |
type: 'incoming'; | |
timestamp: number; | |
state: CallState; | |
customerId: ObjectId; | |
} | |
const CustomerSchema = new Schema<ICallState, Model<ICallState>, ICallState>({ | |
type: { | |
type: String, | |
required: true, | |
default: 'incoming', | |
}, | |
timestamp: { | |
type: Number, | |
required: true, | |
}, | |
state: { | |
type: String, | |
required: true, | |
enum: [CallState.IDLE, CallState.RINGING, CallState.OFFHOOK], | |
}, | |
customerId: { | |
type: Schema.Types.ObjectId, | |
ref: CustomerModel.modelName, | |
required: true, | |
index: true, | |
}, | |
}); | |
const CallStateModel = model<ICallState>('CallState', CustomerSchema, 'call-states'); | |
export default CallStateModel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment