{"id":15649375,"url":"https://github.com/nartc/nest-abstract","last_synced_at":"2025-04-15T05:53:09.988Z","repository":{"id":38486719,"uuid":"159275040","full_name":"nartc/nest-abstract","owner":"nartc","description":"NestJs Abstraction Helper","archived":false,"fork":false,"pushed_at":"2022-12-30T03:09:33.000Z","size":1762,"stargazers_count":39,"open_issues_count":35,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:53:00.727Z","etag":null,"topics":["abstraction","controller","helper","nestjs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nest-abstract","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nartc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-27T04:14:56.000Z","updated_at":"2024-03-19T19:24:51.000Z","dependencies_parsed_at":"2023-01-31T10:20:26.666Z","dependency_job_id":null,"html_url":"https://github.com/nartc/nest-abstract","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nartc%2Fnest-abstract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nartc%2Fnest-abstract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nartc%2Fnest-abstract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nartc%2Fnest-abstract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nartc","download_url":"https://codeload.github.com/nartc/nest-abstract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016319,"owners_count":21198832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstraction","controller","helper","nestjs","typescript"],"created_at":"2024-10-03T12:29:27.854Z","updated_at":"2025-04-15T05:53:09.967Z","avatar_url":"https://github.com/nartc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eNestjs Abstract\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eAbstraction component for NestJs.\u003c/p\u003e\n\nFair 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!\n\n## Features\n- Provides **Abstractions** for your `NestJS` **RESTfulAPI**.\n- Includes: `AbstractModule`, `AbstractService`, and `AbstractControllerFactory` along with `AbstractModel` (`mongoose`) and `AbstractEntity` (`typeorm`).\n- [x] Supports `@nestjs/swagger`\n\n## Motivations\n\nI 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.\n\n## Installation\n`npm i nest-abstract`\n\n## Usage\n\n1. Import `AbstractModule` in your `AppModule`\n   ```typescript\n    import { Module } from '@nestjs/common';\n    import { AbstractModule } from 'nest-abstract';\n\n    @Module({\n        imports: [AbstractModule.forRoot()],\n    })\n    export class AppModule {}\n   ```\n\n   \u003e By default, `AbstractModule` will use `Mongoose`. You can pass a value of `ObjectMapping` to the `forRoot()` method.\n\n    ```typescript\n    import { Module } from '@nestjs/common';\n    import { AbstractModule, ObjectMapping } from 'nest-abstract';\n\n    @Module({\n        imports: [AbstractModule.forRoot(ObjectMapping.TypeOrm)],\n    })\n    export class AppModule {}\n   ```\n   \n   \u003e Note: `ObjectMapping.Mongoose` will require you to install `mongoose` and `@nestjs/mongoose` while `ObjectMapping.TypeOrm` will require you to install `typeorm` and `@nestjs/typeorm`.\n\n    *Note: I will list the usage for Mongoose from step 2 on.*\n\n2. Create your `MongooseSchema` and create an **interface** that will extend `AbstractModel`. `AbstractModel` is an **interface** that has: `createdAt`, `updatedAt` and `id`.\n   \n   ```typescript\n   import { Schema } from 'mongoose';\n   import { AbstractModel } from 'nest-abstract';\n   \n   const todoSchema = new Schema({\n       content: {\n           type: String\n       }\n   }, { timestamps: true });\n\n   interface Todo extends AbstractModel {\n       content: string;\n   }\n   ```\n\n   \u003e Use your `schema` to initialize your `Model` with `@nestjs/mongoose`.\n\n3. Create your `Service` with `AbstractMongooseService`.\n   ```typescript\n   import { Injectable } from '@nestjs/common';\n   import { InjectModel } from '@nestjs/mongoose';\n   import { AbstractMongooseService } from 'nest-abstract';\n   import { Model } from 'mongoose';\n\n   @Injectable()\n   export class TodoService extends AbstractMongooseService\u003cTodo\u003e {\n       constructor(@InjectModel('todo') private readonly _todoModel: Model\u003cTodo\u003e) {\n           super(_todoModel);\n       }\n   }\n   ```\n   \u003e Use `@InjectModel()` from `@nestjs/mongoose` to inject your **MongooseModel** and pass that to the *abstract* constructor.\n\n4. Create your `Controller` with `abstractControllerFactory`\n    ```typescript\n    import { Controller } from '@nestjs/common';\n    import { abstractControllerFactory } from 'nest-abstract';\n    import { Todo } from './todo.model';\n    import { TodoService } from './todo.service';\n\n    const BaseController = abstractControllerFactory\u003cTodo\u003e({model: TodoService.model});\n\n    @Controller('todo')\n    export class TodoController extends BaseController {\n        constructor(private readonly _todoService: TodoService) {\n            super(_todoService);\n        }\n    }\n    ```\n\n5. Make sure you put your `Service` in `providers` array in `Module` and your `Controller` in `controllers` array in `Module`.\n   \n   \u003e Now your `TodoController` should have 5 pre-defined route handlers: `find`, `findById`, `create`, `update` and `delete`\n\n## With Authentication\n\nTo enable `Authenticate` on your `Controllers` with `Passport`, `abstractControllerWithAuth`.\n   \u003e You need to install `passport` and `@nestjs/passport` if you want to enable `Authentication`.\n   ```typescript\n   import { abstractControllerWithAuth } from 'nest-abstract';\n\n   const BaseController = abstractControllerWithAuth\u003cTodo\u003e({model: TodoService.model});\n   ```\n   \n   \u003e By default, `auth` is enabled by on all 5 CRUDs operations.\n  \n## With Swagger\n\nTo enable `Swagger` on your `Controller`, use `abstractControllerWithSwagger`.\n   \u003e `Authentication` is \"mandatory\" with `Swagger` so you will have to have: `passport`, `@nestjs/passport` and `@nestjs/swagger` installed.\n   \u003e 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`.\n\n## Plans\n\n- [x] Might break `abstractControllerFactory` out to 3 separate factories: normal, swagger and withAuth\n- Supports `Serialization` (https://docs.nestjs.com/techniques/serialization)?\n- anything? \n\n## Credit\n- @rcanessa89 and his/her repository: https://github.com/rcanessa89/nest-js-starter. rcanessa89 first raised an issue regarding a `BaseController` on my `nest-mean` repository and came up with his/her `BaseController`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnartc%2Fnest-abstract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnartc%2Fnest-abstract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnartc%2Fnest-abstract/lists"}