import { MongoFactory } from '@birbal/mongo-utilities/dist/mongo-factory'; import { MongoModel } from '@birbal/mongo-utilities/dist/mongo-model'; import { SearchUtility } from '@birbal/mongo-utilities/dist/mongo-search'; import { LogAndError } from '@birbal/common-utilities/dist/error'; import { Document, Schema, SchemaTypes, SchemaOptions } from 'mongoose'; export interface IPrimaryAddressBody { state?: string; country?: string; zip?: string; city?: string; additionalInfo?: { [key: string]: any }; } export interface IPrimaryAddress { _id?: string; primaryAddress?: { virtualId?: string; status?: string; info?: IPrimaryAddressBody; }; } /** Sequelize Schema */ export interface IPrimaryAddressDocument extends Document { _id: string; primaryAddress?: { virtualId?: string; status?: string; info?: IPrimaryAddressBody; }; } export class ProfilePrimaryAddress extends MongoModel { TABLE_NAME = "profile_users"; constructor(dbName: string) { super(dbName); } getDataModel(doc: IPrimaryAddressDocument): IPrimaryAddress { if (!doc) { throw new LogAndError("Invalid document object"); } try { return { _id: doc._id , primaryAddress: doc.primaryAddress } } catch (e) { throw e; } } async defineSchema() { if (!this.DATABASE_NAME || !this.TABLE_NAME) { throw new LogAndError('Invalid db name or table name'); } try { let schema = new Schema({ _id: SchemaTypes.String }, { collection: this.TABLE_NAME } ); await this.define(schema); } catch (e) { throw e; } } }