import { LogAndError } from '@birbal/common-utilities/dist/error'; import { AvatarInfoModel } from '../../Model/Demography/avatar'; import { VirtualBaseResource } from '../../Utility/Profile/virtual'; import { MongoFactory } from '@birbal/mongo-utilities/dist/mongo-factory'; import { IAadhaar } from '../../Model/Identity/aadhaar'; import { IBank } from '../../Model/Identity/bank'; import { IEmail } from '../../Model/Identity/email'; import { IMobile } from '../../Model/Identity/mobile'; import { IPan } from '../../Model/Identity/pan'; import { IUsername } from '../../Model/Identity/username'; import { IPayTM } from '../../Model/Identity/paytm'; import { IUPI } from '../../Model/Identity/upi'; import { IAvatarInfo } from '../../Model/Demography/avatar'; import { IEducationalInfo } from '../../Model/Demography/education'; import { IExperienceInfo, } from '../../Model/Demography/experience'; import { IPersonalInfo } from '../../Model/Demography/personal-info'; import { ISecondaryAddress } from '../../Model/Demography/secondary-address'; import { ISpecializationInfo } from '../../Model/Demography/specialization'; import { IPrimaryAddress } from '../../Model/Demography/primary-address'; const DEFAULT_LIMIT = 10; const DEFAULT_SKIP = 0; type TDemography = IAvatarInfo & IEducationalInfo & IExperienceInfo & IPersonalInfo & ISecondaryAddress & ISpecializationInfo & IPrimaryAddress; type TIdentity = IAadhaar & IBank & IEmail & IMobile & IPan & IUsername & IPayTM & IUPI; type TProfile = TDemography & TIdentity; export class ProfileResource extends VirtualBaseResource { protected ID_TYPE = "avatar"; constructor(dbName: string, superSecret: string) { super(dbName, superSecret); } async advancedSearch( dbName: string , userId?: string , limit?: number , skip?: number ): Promise<[number, Array]> { /** Check for madatory Inputs */ if (!this.SUPER_SECRET || !this.DATABASE_NAME) { throw new LogAndError("Invalid super secret or db name in resource-profile"); } try { let params: TProfile = {}; if (userId) { params._id = userId; } let db = await MongoFactory.getSingleton().getBirbalDatabase(dbName); let conn = await db.getDatabase(); let aInfoModel = new AvatarInfoModel(this.DATABASE_NAME) if(!limit) { limit = DEFAULT_LIMIT; } if(!skip) { skip = DEFAULT_SKIP; } let cursor = conn.collection(aInfoModel.TABLE_NAME).find(params); let count = await cursor.count(); let limitedCursor = cursor.limit(limit).skip(skip); let results = await limitedCursor.toArray(); return [count, results]; } catch (e) { throw e; } } }