@andresmeidla/crud-sequelize
TypeScript icon, indicating that this package has built-in type declarations

5.0.1-alpha-7 • Public • Published

CRUD (@nestjsx/crud-sequelize)

for RESTful APIs built with NestJs


We believe that everyone who's working with NestJs and building some RESTful services and especially some CRUD functionality will find @nestjsx/crud microframework very useful.

Features

CRUD usage

  • Super easy to install and start using the full-featured controllers and services 👉

  • DB and service agnostic extendable CRUD controllers

  • Reach query parsing with filtering, pagination, sorting, relations, nested relations, cache, etc.

  • Framework agnostic package with query builder for a frontend usage

  • Query, path params and DTOs validation included

  • Overriding controller methods with ease

  • Tiny config (including globally)

  • Additional helper decorators

  • Swagger documentation

Install

npm i @nestjsx/crud-typeorm @nestjs/typeorm typeorm

To use it with sequelize:

npm i @nestjsx/crud-sequelize @nestjs/sequelize sequelize sequelize-typescript @types/sequelize
Note on using sequelize:

class-transcforment doesn't work well with sequelize classes so in order to user validations you have to supply a ClassDTO to the Crud decorator, or you can set validations: false and use sequelize-typescript validators or even your own.

Example:
In the following example we are use the UserDTO to the crud controller:
users.controller.ts

import { Controller } from '@nestjs/common';
import {
  Crud,
  CrudController,
} from '@nestjsx/crud';

import { UserDto } from './user.dto';
import User from './user.model';
import { UsersService } from './users.service';

@Crud({
  model: {
    type: UserDto,
  }
})
@Controller('/companies/:companyId/users')
export class UsersController implements CrudController<User> {
  constructor(public service: UsersService) {}
}

user.dto.ts

import { CrudValidationGroups } from '@nestjsx/crud';
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator';
import { UserProfile } from '../../crud-typeorm/users-profiles';
const { CREATE, UPDATE } = CrudValidationGroups;

export class UserDto {
  @IsOptional({ groups: [UPDATE] })
  @IsNotEmpty({ groups: [CREATE] })
  @IsString({ always: true })
  @MaxLength(255, { always: true })
  @IsEmail({ require_tld: false }, { always: true })
  email: string;

  @IsOptional({ groups: [UPDATE] })
  @IsNotEmpty({ groups: [CREATE] })
  @IsBoolean({ always: true })
  isActive: boolean;

  profileId?: number;

  companyId?: number;

  @IsOptional({ groups: [UPDATE] })
  @IsNotEmpty({ groups: [CREATE] })
  @ValidateNested({ always: true })
  profile: UserProfile
}

Packages

  • @nestjsx/crud - core package which provides @Crud() decorator for endpoints generation, global configuration, validation, helper decorators (docs)
  • @nestjsx/crud-request - request builder/parser package which provides RequestQueryBuilder class for a frontend usage and RequestQueryParser that is being used internaly for handling and validating query/path params on a backend side (docs)
  • @nestjsx/crud-typeorm - TypeORM package which provides base TypeOrmCrudService with methods for CRUD database operations (docs)
  • @nestjsx/crud-sequelize - Sequelize package which provides base SequelizeCrudService with methods for CRUD database operations

Documentation

Support

Any support is welcome. At least you can give us a star.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

MIT

Package Sidebar

Install

npm i @andresmeidla/crud-sequelize

Weekly Downloads

4

Version

5.0.1-alpha-7

License

MIT

Unpacked Size

76.2 kB

Total Files

13

Last publish

Collaborators

  • andresmeidla