nestjs-base-service
TypeScript icon, indicating that this package has built-in type declarations

0.11.1 • Public • Published

NestJS BaseService

An opinionated base service for NestJS

Test Coverage

Built with 💗 at Vizzuality.

Roadmap

  • [ ] Add tutorial
  • [ ] Add tests
  • [ ] Implement transaction support
  • [ ] Implement opinionated batching
  • [ ] Add support for validation (via plugin?)
  • [ ] Add support for auditing (via plugin?)
  • [ ] Add support for pagination
  • [ ] Add support for serialization
  • [ ] Add support for batching of operations

License

(C) Copyright Vizzuality 2020-2021.

Distributed under the MIT license.

Usage

Filtering on listing GET requests

  • Add the necessary decorator to your request parsing, on your controller method, like so:
import {
  FetchSpecification,
  ProcessFetchSpecification,
} from 'nestjs-base-service';

@Controller(`/api/v1/some-model`)
@ApiTags(someModelResource.className)
export class SomeModelController {
  constructor(public readonly someModelsService: SomeModelsService) {}

  @Get()
  async findAll(
    @ProcessFetchSpecification(['status'])
      fetchSpecification: FetchSpecification,
  ): Promise<SomeModel> {
    const results = await this.someModelsService.findAllPaginated(
      fetchSpecification,
    );
    return this.someModelsService.serialize(results.data, results.metadata);
  }
}
  • Ensure your service class extends the included BaseService class.
  • On your controller decorator argument, optionally pass a whitelist of filtering parameters (recommended).

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-base-service

Weekly Downloads

7

Version

0.11.1

License

MIT

Unpacked Size

429 kB

Total Files

57

Last publish

Collaborators

  • tiagojsag
  • hotzevzl
  • yulia-belyakova