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 IUsernameBody { username?: string; } export interface IUsername { _id?: string; username?: { virtualId?: string; status?: string; info?: IUsernameBody; }; } /** Sequelize Schema */ export interface UsernameDocument extends Document { _id: string; username?: { virtualId?: string; status?: string; info?: IUsernameBody; }; } export class UsernameModel extends MongoModel { TABLE_NAME = "profile_users"; constructor(dbName: string) { super(dbName); } getDataModel(doc: UsernameDocument): IUsername { if (!doc) { throw new LogAndError("Invalid document object"); } try { return { _id: doc._id , username: doc.username } } 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; } } }