Created
September 20, 2022 16:41
-
-
Save newerton/55469346e119ba682fb5b51b59a7cf4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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