Created
January 19, 2022 15:52
-
-
Save royib/8df93b56aa5d85e2ebe29ee7968714c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, OnApplicationBootstrap } from '@nestjs/common'; | |
import { InjectModel } from '@nestjs/mongoose'; | |
import { Model } from 'mongoose'; | |
import { IDataServices } from '../../../core'; | |
import { MongoGenericRepository } from './mongo-generic-repository'; | |
import { | |
Author, | |
AuthorDocument, | |
Book, | |
BookDocument, | |
Genre, | |
GenreDocument, | |
} from './model'; | |
@Injectable() | |
export class MongoDataServices | |
implements IDataServices, OnApplicationBootstrap | |
{ | |
authors: MongoGenericRepository<Author>; | |
books: MongoGenericRepository<Book>; | |
genres: MongoGenericRepository<Genre>; | |
constructor( | |
@InjectModel(Author.name) | |
private AuthorRepository: Model<AuthorDocument>, | |
@InjectModel(Book.name) | |
private BookRepository: Model<BookDocument>, | |
@InjectModel(Genre.name) | |
private GenreRepository: Model<GenreDocument>, | |
) {} | |
onApplicationBootstrap() { | |
this.authors = new MongoGenericRepository<Author>(this.AuthorRepository); | |
this.books = new MongoGenericRepository<Book>(this.BookRepository, [ | |
'author', | |
'genre', | |
]); | |
this.genres = new MongoGenericRepository<Genre>(this.GenreRepository); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment