@andresmeidla/crud-sequelize
v5.0.1-alpha-7
Published
NestJs CRUD for RESTful APIs - Sequelize
Downloads
119
Maintainers
Readme
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
Super easy to install and start using the full-featured controllers and services :point_right:
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 andRequestQueryParser
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]