Skip to content

Instantly share code, notes, and snippets.

View GR-new-db-model.ts
import { Module } from '@nestjs/common';
import { NewAndTrendyDbModule } from '../../frameworks/data-services/mongo/NewAndTrendy-data-services.module';
@Module({
imports: [NewAndTrendyDbModule],
exports: [NewAndTrendyDbModule],
})
export class DataServicesModule {}
View GR-books-services.ts
import { Injectable } from '@nestjs/common';
import { Book } from '../../../core/entities';
import { IDataServices, ICrmServices } from '../../../core/abstracts';
@Injectable()
export class BookServices {
constructor(
private dataServices: IDataServices,
private crmServices: ICrmServices,
) {}
View GR-app-module.ts
import { Module } from '@nestjs/common';
import {
BookController,
AuthorController,
GenreController,
} from './controllers';
import { DataServicesModule } from './services/data-services/data-services.module';
import { BookServicesModule } from './services/use-cases/book/book-services.module';
@Module({
View GR-data-services-module.ts
import { Module } from '@nestjs/common';
import { MongoDataServicesModule } from '../../frameworks/data-services/mongo/mongo-data-services.module';
@Module({
imports: [MongoDataServicesModule],
exports: [MongoDataServicesModule],
})
export class DataServicesModule {}
View GR-mongo-module.ts
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { IDataServices } from '../../../core';
import { DATA_BASE_CONFIGURATION } from '../../../configuration';
import {
Author,
AuthorSchema,
Book,
BookSchema,
Genre,
View GR-mongo-data-services.ts
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,
View GR-mongo-generic-repository.ts
import { Model } from 'mongoose';
import { IGenericRepository } from '../../../core';
export class MongoGenericRepository<T> implements IGenericRepository<T> {
private _repository: Model<T>;
private _populateOnFind: string[];
constructor(repository: Model<T>, populateOnFind: string[] = []) {
this._repository = repository;
this._populateOnFind = populateOnFind;
View GR-mongo-entities-book.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';
import { Author, Genre } from './';
export type BookDocument = Book & Document;
@Schema()
export class Book {
View GR-mongo-entities-genre.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
export type GenreDocument = Genre & Document;
@Schema()
export class Genre {
@Prop({ required: true, unique: true })
name: string;
}
View GR-mongo-entities-author.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
export type AuthorDocument = Author & Document;
@Schema()
export class Author {
@Prop()
firstName: string;
@Prop()