How to use @nestjsx/crud - 10 common examples

To help you get started, we’ve selected a few @nestjsx/crud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nestjsx / crud / integration / crud-typeorm / main.ts View on Github external
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { CrudConfigService } from '@nestjsx/crud';
import { USER_REQUEST_KEY } from './constants';

// Important: load config before (!!!) you import AppModule
// https://github.com/nestjsx/crud/wiki/Controllers#global-options
CrudConfigService.load({
  auth: {
    property: USER_REQUEST_KEY,
  },
  routes: {
    // exclude: ['createManyBase'],
  },
});

import { HttpExceptionFilter } from '../shared/https-exception.filter';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalFilters(new HttpExceptionFilter());
github oracle-quickstart / oci-cloudnative / src / user / src / config / crud.ts View on Github external
import { CrudConfigService } from '@nestjsx/crud';

/**
 * Configure CRUD defaults
 */
CrudConfigService.load({
  query: {
    limit: 25,
    maxLimit: 250,
  },
  routes: {
    // exclude /bulk
    exclude: ['createManyBase'],
  },
  params: {
    id: {
      field: 'id',
      type: 'uuid',
      primary: true,
    },
  },
});
github oracle-quickstart / oci-cloudnative / src / user / src / services / user / user.address.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { Crud } from '@nestjsx/crud';

import { ROUTE } from '../../config/constants';
import { UserAddress } from './address/address.entity';
import { AddressService } from './address/address.service';
import { BaseAddressController } from './address/address.base.controller';

/**
 * User/address relation controller
 * /customers/:userId/addresses
 */
@Crud({
  model: {
    type: UserAddress,
  },
  params: {
    userId: {
      field: 'userId',
      type: 'uuid',
    },
  },
})
@Controller(`/${ROUTE.USERS}/:userId/${ROUTE.ADDRESSES}`)
export class UserAddressController extends BaseAddressController {
  constructor(public service: AddressService) {
    super(service);
  }
}
github nestjsx / crud / integration / crud-typeorm / devices / devices.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Crud } from '@nestjsx/crud';

import { Device } from './device.entity';
import { DevicesService } from './devices.service';
import { serialize } from './response';

@Crud({
  model: { type: Device },
  serialize,
  params: {
    deviceKey: {
      field: 'deviceKey',
      type: 'uuid',
      primary: true,
    },
  },
  routes: {
    deleteOneBase: {
      returnDeleted: true,
    },
  },
})
@ApiTags('devices')
github nestjsx / crud / integration / crud-typeorm / projects / my-projects.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Crud, CrudAuth } from '@nestjsx/crud';

import { User } from '../users/user.entity';
import { UserProject } from './user-project.entity';
import { UserProjectsService } from './user-projects.service';

@Crud({
  model: {
    type: UserProject,
  },
  params: {
    projectId: {
      field: 'projectId',
      type: 'number',
      primary: true,
    },
  },
  query: {
    join: {
      project: {
        eager: true,
      },
    },
github devonfw / devon4node / samples / employee / src / app / employee / controllers / employee.crud.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { Crud } from '@nestjsx/crud';
import { CrudType } from '@devon4node/common/serializer';
import { Employee } from '../model';
import { EmployeeCrudService } from '../services';
import { ApiUseTags } from '@nestjs/swagger';

@Crud({
  model: {
    type: Employee,
  },
})
@CrudType(Employee)
@Controller('employee/employees')
@ApiUseTags('employee')
export class EmployeeCrudController {
  constructor(public service: EmployeeCrudService) {}
}
github nestjsx / crud / integration / typeorm / src / users / users.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { ApiUseTags } from '@nestjs/swagger';
import { Crud, CrudController, RestfulOptions } from '@nestjsx/crud';

import { User } from './user.entity';
import { UsersService } from './users.service';

@Crud(User, {
  options: {
    exclude: ['password'],
    join: {
      profile: {
        allow: ['firstName', 'lastName'],
      },
    },
    maxLimit: 10,
    cache: 3000,
  },
  params: ['companyId'],
  validation: {
    validationError: {
      target: false,
      value: false,
    },
github nestjsx / crud / integration / typeorm / src / heroes / heroes-crud.controller.ts View on Github external
import { Controller, Body } from '@nestjs/common';
import { Crud, CrudController, RestfulOptions, Feature } from '@nestjsx/crud';

import { Hero } from './hero.entity';
import { HeroesService } from './heroes.service';

@Crud(Hero)
@Controller('heroes')
export class HeroesCrudController implements CrudController {
  paramsFilter = [];
  options: RestfulOptions = {};

  constructor(public service: HeroesService) {}

  get base(): CrudController {
    return this;
  }
}
github nestjsx / crud / integration / typeorm / src / companies / companies.controller.ts View on Github external
CrudController,
  CrudOptions,
  Override,
  ParsedQuery,
  ParsedOptions,
  ParsedParams,
  ParsedBody,
  EntitiesBulk,
  UsePathInterceptors,
  RestfulParamsDto,
} from '@nestjsx/crud';

import { Company } from './company.entity';
import { CompaniesService } from './companies.service';

@Crud(Company, {
  params: {},
  routes: {},
  options: {
    join: {
      users: {
        exclude: ['password'],
      },
    },
    sort: [{ field: 'id', order: 'DESC' }],
    maxLimit: 5,
    cache: 10000,
  },
})
@ApiUseTags('companies')
@Controller('companies')
export class CompaniesController {
github nestjsx / crud / integration / crud-typeorm / companies / companies.controller.ts View on Github external
import { Controller } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Crud } from '@nestjsx/crud';

import { Company } from './company.entity';
import { CompaniesService } from './companies.service';
import { dto } from './dto';
import { serialize } from './response';

@Crud({
  model: {
    type: Company,
  },
  dto,
  serialize,
  query: {
    alwaysPaginate: true,
    join: {
      users: {},
      projects: {},
    },
  },
})
@ApiTags('companies')
@Controller('companies')
export class CompaniesController {