JSON API parser for Nest based on the json api.
$ npm i --save @luxury-presence/nestjs-jsonapi
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
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.