import { MongoModel } from '@birbal/mongo-utilities/dist/mongo-model'; import { LogAndError } from '@birbal/common-utilities/dist/error'; import { Document, Schema, SchemaTypes } from 'mongoose'; export interface IEmailBody { emailId?: string; } export interface IEmail { _id?: string; email?: { virtualId?: string; status?: string; info?: IEmailBody; }; } /** Sequelize Schema */ export interface EmailDocument extends Document { _id: string; email?: { virtualId?: string; status?: string; info?: IEmailBody; }; } export class EmailModel extends MongoModel { TABLE_NAME = "profile_users"; constructor(dbName: string) { super(dbName); } getDataModel(doc: EmailDocument): IEmail { if (!doc) { throw new LogAndError("Invalid document object"); } try { return { _id: doc._id , email: doc.email } } catch (e) { throw e; } } async defineSchema() { try { if (!this.DATABASE_NAME || !this.TABLE_NAME) { throw new LogAndError('Invalid database name or table name'); } let schema = new Schema({ _id: SchemaTypes.String }, { collection: this.TABLE_NAME } ); await this.define(schema); } catch (e) { throw e; } } }