Giter VIP home page Giter VIP logo

nestjs-mongoose-generic-repository's Introduction

Nestjs Mongoose Generic Repository

$ npm i nestjs-mongoose-generic-repository

Usage

├── cats
        ├── controller.ts
        ├── entity.ts
        ├── module.ts
        ├── repository.ts
        ├── schema.ts
--repository.ts

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Repository } from 'nestjs-mongoose-generic-repository';

import { CatDocument, Cats } from './schema';

@Injectable()
export class CatsRepository extends Repository<CatDocument> {
  constructor(@InjectModel(Cats.name) private entity: Model<CatDocument>) {
    super(entity);
  }
}
--controller.ts

import { Body, Controller, Post } from '@nestjs/common';
import { CreatedModel } from 'nestjs-mongoose-generic-repository';

import { CatsDTO } from './entity';
import { CatsRepository } from './repository';

@Controller('cats')
export class CatsController {
  constructor(private readonly catRepository: CatsRepository) {}

  @Post()
  async save(@Body() model: CatsDTO): Promise<CreatedModel> {
    const saved = await this.catRepository.create(model);
    return saved;
  }
}

Operators

  create
  find
  findById
  findAll
  remove
  updateOne
  updateMany

Lib types

import { ObjectId } from 'mongoose';

export type UpdatedModel = {
  matchedCount: number;
  modifiedCount: number;
  acknowledged: boolean;
  upsertedId: unknown | ObjectId;
  upsertedCount: number;
};

export type RemovedModel = {
  deletedCount: number;
  deleted: boolean;
};

export type CreatedModel = {
  id: string;
  created: boolean;
};

The following is a list of all the people that have contributed to nestjs-mongoose-generic-repository. Thanks for your contributions!

mikemajesty

License

It is available under the MIT license. License

nestjs-mongoose-generic-repository's People

Contributors

bug-author avatar mikemajesty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.