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 IAadhaarBody { aadhaarNo?: string; aadhaarType?: 'original'|'virtual' docUrl?: string; additionalInfo?: {[key: string]: any} } export interface IAadhaar { _id?: string; aadhaar?: { virtualId?: string; status?: string; info?: IAadhaarBody; }; } /** Sequelize Schema */ export interface AadhaarDocument extends Document { _id: string; aadhaar?: { virtualId?: string; status?: string; info?: IAadhaarBody; }; } export class AadhaarModel extends MongoModel { TABLE_NAME = "profile_users"; constructor(dbName: string) { super(dbName); } getDataModel(doc: AadhaarDocument): IAadhaar { if (!doc) { throw new LogAndError("Invalid document object"); } try { return { _id: doc._id , aadhaar: doc.aadhaar } } 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; } } }