All Projects → nartc → nest-abstract

nartc / nest-abstract

Licence: MIT license
NestJs Abstraction Helper

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to nest-abstract

Nest Access Control
Role and Attribute based Access Control for Nestjs 🔐
Stars: ✭ 562 (+1461.11%)
Mutual labels:  helper, nestjs
Xb2XInput
XB2X: User-mode Windows driver for Xbox OG controllers, supporting both XInput and DirectInput.
Stars: ✭ 70 (+94.44%)
Mutual labels:  controller
MagicaVoxel File Writer
MagicaVoxel File Writer dependency free cpp class
Stars: ✭ 26 (-27.78%)
Mutual labels:  helper
nestjs-rest-sample
NestJS RESTful APIs Sample
Stars: ✭ 204 (+466.67%)
Mutual labels:  nestjs
Nine-chat-frontend
采用socketio打造的多人实时通讯多房间在线音乐聊天室
Stars: ✭ 54 (+50%)
Mutual labels:  nestjs
nestjs-i18n
The i18n module for nestjs.
Stars: ✭ 376 (+944.44%)
Mutual labels:  nestjs
nestjs-mercurius
NestJs module to use Mercurius as GraphQL server
Stars: ✭ 38 (+5.56%)
Mutual labels:  nestjs
stack
🥭 nxpm-stack lets you generate a complete and opinionated full-stack application in a Nx Workspace, ready to extend and deploy!
Stars: ✭ 98 (+172.22%)
Mutual labels:  nestjs
is-even
SaaS platform for checking if number is even
Stars: ✭ 66 (+83.33%)
Mutual labels:  nestjs
game-store-monorepo-app
A full-stack web app built with NestJS and ReactJS that helps you find and discover over 500,000+ video games on your device. Powered by RAWG API.
Stars: ✭ 106 (+194.44%)
Mutual labels:  nestjs
react-ecommerce
E-commerce monorepo application using NextJs, React, React-native, Design-System and Graphql with Typescript
Stars: ✭ 136 (+277.78%)
Mutual labels:  nestjs
bilrost
Kubernetes controller/operator to set up OAUTH2/OIDC security on any ingress based service
Stars: ✭ 17 (-52.78%)
Mutual labels:  controller
clock-in-out
A clock-in/out system using nestJS, PostgreSQL, TypeORM, Angular, Arduino, RxJS
Stars: ✭ 61 (+69.44%)
Mutual labels:  nestjs
nestjs-pg-notify
NestJS custom transport strategy for PostgreSQL Pub/Sub.
Stars: ✭ 53 (+47.22%)
Mutual labels:  nestjs
csshelper
CSS helper, forget traditional css frameworks approach, every class is a task-like
Stars: ✭ 14 (-61.11%)
Mutual labels:  helper
nest-rabbit-tasks
nest-rabbit-worker is a TaskQueue based upon RabbitMQ for NestJS
Stars: ✭ 29 (-19.44%)
Mutual labels:  nestjs
nestjs-otel
OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Stars: ✭ 273 (+658.33%)
Mutual labels:  nestjs
nest-keycloak-connect
keycloak-nodejs-connect module for Nest
Stars: ✭ 174 (+383.33%)
Mutual labels:  nestjs
uniauth-backend
backend service to power uniAuth
Stars: ✭ 16 (-55.56%)
Mutual labels:  nestjs
sendmessage
SendMessage is a little tool to send Windows messages to any window.
Stars: ✭ 93 (+158.33%)
Mutual labels:  helper

Nestjs Abstract

Abstraction component for NestJs.

Fair warning: This package is still in early development stage. Please give me any feedbacks if you decide to try it out and find any problems/area-for-improvements. Thank you!

Features

  • Provides Abstractions for your NestJS RESTfulAPI.
  • Includes: AbstractModule, AbstractService, and AbstractControllerFactory along with AbstractModel (mongoose) and AbstractEntity (typeorm).
  • Supports @nestjs/swagger

Motivations

I am a big fan of TypeScript and abstraction overall. One of the biggest motivations is to create a BaseController to work with Swagger's decorators that @nestjs/swagger provides which is on the todo list. Main reason is I want to roll out a version of the package that will make it work with non-swagger applications first as this is my first attempt at an npm package.

Installation

npm i nest-abstract

Usage

  1. Import AbstractModule in your AppModule

     import { Module } from '@nestjs/common';
     import { AbstractModule } from 'nest-abstract';
    
     @Module({
         imports: [AbstractModule.forRoot()],
     })
     export class AppModule {}

    By default, AbstractModule will use Mongoose. You can pass a value of ObjectMapping to the forRoot() method.

    import { Module } from '@nestjs/common';
    import { AbstractModule, ObjectMapping } from 'nest-abstract';
    
    @Module({
        imports: [AbstractModule.forRoot(ObjectMapping.TypeOrm)],
    })
    export class AppModule {}

    Note: ObjectMapping.Mongoose will require you to install mongoose and @nestjs/mongoose while ObjectMapping.TypeOrm will require you to install typeorm and @nestjs/typeorm.

    Note: I will list the usage for Mongoose from step 2 on.

  2. Create your MongooseSchema and create an interface that will extend AbstractModel. AbstractModel is an interface that has: createdAt, updatedAt and id.

    import { Schema } from 'mongoose';
    import { AbstractModel } from 'nest-abstract';
    
    const todoSchema = new Schema({
        content: {
            type: String
        }
    }, { timestamps: true });
    
    interface Todo extends AbstractModel {
        content: string;
    }

    Use your schema to initialize your Model with @nestjs/mongoose.

  3. Create your Service with AbstractMongooseService.

    import { Injectable } from '@nestjs/common';
    import { InjectModel } from '@nestjs/mongoose';
    import { AbstractMongooseService } from 'nest-abstract';
    import { Model } from 'mongoose';
    
    @Injectable()
    export class TodoService extends AbstractMongooseService<Todo> {
        constructor(@InjectModel('todo') private readonly _todoModel: Model<Todo>) {
            super(_todoModel);
        }
    }

    Use @InjectModel() from @nestjs/mongoose to inject your MongooseModel and pass that to the abstract constructor.

  4. Create your Controller with abstractControllerFactory

    import { Controller } from '@nestjs/common';
    import { abstractControllerFactory } from 'nest-abstract';
    import { Todo } from './todo.model';
    import { TodoService } from './todo.service';
    
    const BaseController = abstractControllerFactory<Todo>({model: TodoService.model});
    
    @Controller('todo')
    export class TodoController extends BaseController {
        constructor(private readonly _todoService: TodoService) {
            super(_todoService);
        }
    }
  5. Make sure you put your Service in providers array in Module and your Controller in controllers array in Module.

    Now your TodoController should have 5 pre-defined route handlers: find, findById, create, update and delete

With Authentication

To enable Authenticate on your Controllers with Passport, abstractControllerWithAuth.

You need to install passport and @nestjs/passport if you want to enable Authentication.

import { abstractControllerWithAuth } from 'nest-abstract';

const BaseController = abstractControllerWithAuth<Todo>({model: TodoService.model});

By default, auth is enabled by on all 5 CRUDs operations.

With Swagger

To enable Swagger on your Controller, use abstractControllerWithSwagger.

Authentication is "mandatory" with Swagger so you will have to have: passport, @nestjs/passport and @nestjs/swagger installed. By default, auth is enabled by on all 5 CRUDs operations. If you wish to use abstractControllerWithSwagger without auth, please pass in an object of type DefaultAuthObj and set all the properties to false.

Plans

Credit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].