Skip to content

Instantly share code, notes, and snippets.

@hoangsetup
Created September 18, 2021 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoangsetup/35b8c17a19111e42ee839baf4e612f2e to your computer and use it in GitHub Desktop.
Save hoangsetup/35b8c17a19111e42ee839baf4e612f2e to your computer and use it in GitHub Desktop.
// 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