New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

nestjs-methodset

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-methodset

**MethodSet** is an abstract controller that when extended will provide: - All the required `GET`/`DELETE`/`POST`/`UPDATE` endpoints for the TypeORM repository. - List endpoint contains: pagination, order, search, filter options. - filter options contains

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

nestjs-methodset

MethodSet is an abstract controller that when extended will provide:

  • All the required GET/DELETE/POST/UPDATE endpoints for the TypeORM repository.
  • List endpoint contains: pagination, order, search, filter options.
  • filter options contains: =, gt, gte, lt, lte

nestjs-methodSet is influenced by ViewSet in Django Rest Framework

semantic-release

Installation

npm i nestjs-methodset

in main.ts add following to the app:

import { ValidationPipe } from '@nestjs/common';
...
  app.useGlobalPipes(new ValidationPipe({ transform: true }));

Code

  • Simply extends MethodSet in your controller and you done. Make sure to have the repository in your controller dependencies!
import { MethodSet } from 'nestjs-methodset';

@Controller({ path: 'article' })
export class ArticleController extends MethodSet<ArticleEntity> {
	constructor(
		@InjectRepository(ArticleEntity)
		protected readonly repository: Repository<ArticleEntity>
	) {
		super();
	}
}
  • Now your API has the following implemented functions:
    • get: GET /article/<id>
    • list: GET /article
    • post: POST /article
    • update: UPDATE /article/<id>
    • delete: DELETE /article/<id>

List URL Params:

the list endpoint contains different options as following:

  • page & pageSize: ?&page=1&pageSize=3
  • orderBy & sortOrder(default: DESC): ?orderBy=timestamp&sortOrder=ASC
  • search : ?search=test
    • Must specify search fields in the controller, ie:
    searchFields: SearchFields<ArticleEntity> = ['body', 'title'];
    
  • filter[]:
    • separate conditions by , ie: ?filter=price__lte=10,total=2,
    • Or can be written: ?filter[]=price__lte=10&filter[]=total=2

All Filter Valid Options:

  • <field>=<value>, equals, ie: ?filter=price=10
  • <field>__gt=<value>, greater than, ie: filter=price__lte=10
  • <field>__gte=<value> greater than or equal
  • <field>__lt=<value> less than
  • <field>__lte=<value> less than or equal

Keywords

nestjs

FAQs

Package last updated on 31 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts