Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import { Typegoose } from 'typegoose';
  2. import { Database } from '@config/database';
  3. import { log } from '@config/logger';
  4.  
  5.  
  6. export async function getModel<T extends Typegoose>(Model: new (...args: any) => T) {
  7. const connection = await new Database().connect();
  8.  
  9. if (connection.readyState !== 1) {
  10. throw new Error(`Can't get model as the database connection is not active.`);
  11. }
  12.  
  13. const DomainModel = new Model().getModelForClass(Model, {
  14. existingConnection: connection,
  15. schemaOptions: {
  16. timestamps: true,
  17. },
  18. });
  19.  
  20. return DomainModel;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement