Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Typegoose } from 'typegoose';
- import { Database } from '@config/database';
- import { log } from '@config/logger';
- export async function getModel<T extends Typegoose>(Model: new (...args: any) => T) {
- const connection = await new Database().connect();
- if (connection.readyState !== 1) {
- throw new Error(`Can't get model as the database connection is not active.`);
- }
- const DomainModel = new Model().getModelForClass(Model, {
- existingConnection: connection,
- schemaOptions: {
- timestamps: true,
- },
- });
- return DomainModel;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement