@luxury-presence/nestjs-jsonapi
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Description

JSON API parser for Nest based on the json api.

Installation

$ npm i --save @luxury-presence/nestjs-jsonapi

Usage

import {
  ParseJsonApiQuery,
  ParsingConfig,
  Op,
  ParsedQuery,
} from '@luxury-presence/nestjs-jsonapi';

export class MyEntity {
  firstName: string;
  lastName: string;
  email: string;
  age: number;
  hasShoes: boolean;
}
const testConfig: ParsingConfig<MyEntity> = {
  sortableColumns: ['firstName', 'age'],
  searchableColumns: ['email', 'firstName', 'lastName'],
  filterableColumns: {
    firstName: [Op.$eq, Op.$in],
    lastName: [Op.$eq, Op.$in, Op.$like],
    email: [Op.$eq],
    age: [Op.$gt, Op.$gte, Op.$lt, Op.$lte, Op.$btw],
    hasShoes: [Op.$true, Op.$false],
  },
};

@Controller('my-controller')
export class MyController {

  @Get()
  async find(
    @ParseJsonApiQuery<MyEntity>({ config: testConfig }) params: ParsedQuery<MyEntity>
  ) {
    // return parsed query
    /*
     params = {
        page: { limit: 15, on: 2 },
        sort: [ [ 'firstName', 'ASC' ], [ 'age', 'DESC' ] ],
        search: { by: 'lastName', term: 'username' },
        filter: {
          firstName: { ['$in']: [Array] },
          lastName: { ['$eq']: 'lastName' },
          email: { ['$not']: [Object] },
          address: { ['$like']: '123Avenue' },
          age: { ['$gt']: '1000000' },
          hasShoes: { ['$eq']: true },
        },
        path: 'https://localhost/api/v1/my-controller',
      }
     * 
    */
 
  }
}

Call the API

$   curl -X 'GET' 'http://localhost:8011/api/v1/agents?page.on=2&page.limit=15&sort=firstName,-age&filter.firstName=$in:user1,user2&filter.lastName=$eq:lastName&filter.hasShoes=$true

Publishing a new version

Run npm run release

This will kick off the release process which will build the project, create a tag, bump version, and create a release.

This is an interactive process so it will require input from the user to confirm each step.

Under the hood we use release-it. Learn more about how it works here.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @luxury-presence/nestjs-jsonapi

Weekly Downloads

187

Version

3.0.0

License

MIT

Unpacked Size

177 kB

Total Files

108

Last publish

Collaborators

  • dallinlp
  • gauntc
  • nscarafia
  • spencermmelo
  • elisabethgross568
  • ryanresurreccion
  • rfonseca.luxurypresence
  • antopisciolp
  • mflores17
  • vinay-lp
  • eramirez0633lux
  • bcanepa-luxurypresence
  • acarlislelp
  • galgordo
  • ghardt
  • kelios
  • aandraslp
  • luxmedina
  • janlp
  • bradfordh
  • trobertslp
  • dougngo
  • wheitor
  • erikchau
  • viktorqa
  • xueli-lp
  • augustoalegon
  • mikebsvitla
  • taraslp
  • nazariy
  • nkashtan
  • paulchamberlain
  • jwolterslp
  • freire71
  • ojizero
  • ceallaighbrian
  • nfeigenlp
  • antopiscio
  • joebalanciolp
  • nwolfflp
  • dimasc_io
  • alex_bychkov
  • minkathalp
  • dsaldanolp
  • paulomatosj
  • qwrobins
  • carcaz
  • gabycruz
  • leocorrealp
  • danielfrank
  • rifflock
  • ulysses-odysseus
  • michaellauritsch
  • dhutton
  • jacksonwolff
  • kyletnguyen
  • sergey-at-lp
  • edwardyeh
  • timoteo
  • thenickot2
  • luxurypresenceci
  • emersonlopxs
  • kevinvoduy
  • polosergio
  • azorkin
  • pedro-surf
  • andersoonluan