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 IVirtualStateBody{ status?: string } export interface IVirtualState { _id?: string state?: IVirtualStateBody } /** Sequelize Schema */ export interface VirtualStateDocument extends Document { _id: string state?: IVirtualStateBody } export class VirtualStateModel extends MongoModel { TABLE_NAME = "profile_virtuals"; constructor(dbName: string) { super(dbName); } getDataModel(doc: VirtualStateDocument): IVirtualState { if (!doc) { throw new LogAndError("Invalid doc object"); } try { return { _id: doc._id , state: doc.state } } catch (e) { throw e; } } async defineSchema() { try { if (!this.DATABASE_NAME || !this.TABLE_NAME) { throw new LogAndError('Invalid db name/ tbl name'); } let schema = new Schema({ _id: SchemaTypes.String }, { collection: this.TABLE_NAME }); await this.define(schema); } catch (e) { throw e; } } }