1.0.84 • Published 1 year ago

@webage/controller v1.0.84

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

controller

Rest controller builder

Examples

Module

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Category, CategoryView, Sample, SampleView, Supplier, SupplierView } from '@webage/entity';
import { SampleController } from './sample.controller';
import { SampleService } from './sample.service';

@Module({
  imports: [TypeOrmModule.forFeature([Sample, SampleView, Category, CategoryView, Supplier, SupplierView])],
  controllers: [SampleController],
  providers: [SampleService],
})
export class SampleModule {}

Controller

import { PathBuilder } from '@webage/path';
import { ControllerBuilder } from '../controller-builder';
import { CreateSampleDto, Sample, QuerySampleDto, UpdateSampleDto } from '@webage/entity';
import { SampleService } from './sample.service';
import { Body, Param, ParseIntPipe, Query } from '@nestjs/common';
import { RelationDto, UnsetRelationDto } from '@webage/db';

const P = new PathBuilder('product');

const R = new ControllerBuilder({
  entity: Sample,
  createDto: CreateSampleDto,
  updateDto: UpdateSampleDto,
  pathBuilder: P,
});

@R.controller()
export class SampleController {
  constructor(protected readonly service: SampleService) {}

  @R.save()
  save(@Body() body: CreateSampleDto) {
    return this.service.saveOne(body);
  }

  @R.find()
  find(@Query() query: QuerySampleDto) {
    console.log(query);
    return this.service.findAll(query);
  }

  @R.findOneById()
  findOneByid(@Param('id', ParseIntPipe) id: number) {
    return this.service.findOneById(id);
  }

  @R.delete()
  delete(@Param('id') id: number) {
    return this.service.deleteById(id);
  }

  @R.update()
  update(@Param('id') id: number, @Body() entity: UpdateSampleDto) {
    return this.service.updateOneById(id, entity);
  }

  @R.addRelation()
  addRelation(@Body() body: RelationDto) {
    return this.service.addRelation(body);
  }

  @R.removeRelation()
  removeRelation(@Body() body: RelationDto) {
    return this.service.removeRelation(body);
  }

  @R.setRelation()
  setRelation(@Body() body: RelationDto) {
    return this.service.setRelation(body);
  }

  @R.unsetRelatin()
  unsetRelation(@Body() body: UnsetRelationDto) {
    return this.service.unsetRelation(body);
  }
}
1.0.84

1 year ago

1.0.83

1 year ago

1.0.81

1 year ago

1.0.8

1 year ago

1.0.71

1 year ago

1.0.7

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago