print module
This commit is contained in:
@@ -16,6 +16,7 @@ import { OrderModule } from './modules/order/order.module';
|
||||
import { NotificationsModule } from './modules/notification/notifications.module';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { PrintModule } from './modules/print/print.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -39,6 +40,7 @@ import { CacheModule } from '@nestjs/cache-manager';
|
||||
OrderModule,
|
||||
NotificationsModule,
|
||||
EventEmitterModule.forRoot(),
|
||||
PrintModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export class CreatePrintDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreatePrintDto } from './create-print.dto';
|
||||
|
||||
export class UpdatePrintDto extends PartialType(CreatePrintDto) {}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Entity, Property, ManyToOne, PrimaryKey, Unique } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Field } from './field.entity';
|
||||
|
||||
@Entity({ tableName: 'field_option' })
|
||||
export class FieldOption extends BaseEntity {
|
||||
@PrimaryKey({ autoincrement: true, type: 'bigint' })
|
||||
id: bigint;
|
||||
|
||||
@Property()
|
||||
value: string;
|
||||
|
||||
@ManyToOne(() => Field)
|
||||
field: Field;
|
||||
|
||||
@Property({ type: 'int', nullable: true })
|
||||
order?: number;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { FieldOption } from './field-option.entity';
|
||||
import { FieldType } from '../interface/print';
|
||||
import { Section } from './section.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'field' })
|
||||
export class Field {
|
||||
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
||||
id: bigint
|
||||
|
||||
@OneToMany(() => FieldOption, (attrValue) => attrValue.field)
|
||||
options = new Collection<FieldOption>(this)
|
||||
|
||||
@ManyToOne(() => Section)
|
||||
section: Section
|
||||
|
||||
@Property()
|
||||
name: string;
|
||||
|
||||
@Enum(() => FieldType)
|
||||
type: FieldType;
|
||||
|
||||
@Property({ type: 'boolean', default: false })
|
||||
isRequired: boolean = false;
|
||||
|
||||
@Property({ type: 'int', nullable: true })
|
||||
order?: number;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Cascade, Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Field } from './field.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'section' })
|
||||
export class Section {
|
||||
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
||||
id: bigint
|
||||
|
||||
@OneToMany(() => Field, (attrValue) => attrValue.section, { cascade: [Cascade.PERSIST, Cascade.REMOVE] })
|
||||
Fields = new Collection<Field>(this)
|
||||
|
||||
@Property()
|
||||
title: string;
|
||||
|
||||
|
||||
@Property({ type: 'int', nullable: true })
|
||||
order?: number;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum FieldType {
|
||||
text = 'text',
|
||||
textarea = 'textarea',
|
||||
number = 'number',
|
||||
select = 'select',
|
||||
radio = 'radio',
|
||||
checkbox = 'checkbox',
|
||||
date = 'date',
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { PrintService } from './print.service';
|
||||
import { CreatePrintDto } from './dto/create-print.dto';
|
||||
import { UpdatePrintDto } from './dto/update-print.dto';
|
||||
|
||||
@Controller('print')
|
||||
export class PrintController {
|
||||
constructor(private readonly printService: PrintService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createPrintDto: CreatePrintDto) {
|
||||
return this.printService.create(createPrintDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.printService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.printService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updatePrintDto: UpdatePrintDto) {
|
||||
return this.printService.update(+id, updatePrintDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.printService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrintService } from './print.service';
|
||||
import { PrintController } from './print.controller';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { Field } from './entities/field.entity';
|
||||
import { Section } from './entities/section.entity';
|
||||
import { FieldOption } from './entities/field-option.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [PrintController],
|
||||
providers: [PrintService],
|
||||
imports: [MikroOrmModule.forFeature([Field, Section, FieldOption])]
|
||||
})
|
||||
export class PrintModule { }
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreatePrintDto } from './dto/create-print.dto';
|
||||
import { UpdatePrintDto } from './dto/update-print.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PrintService {
|
||||
create(createPrintDto: CreatePrintDto) {
|
||||
return 'This action adds a new print';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all print`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} print`;
|
||||
}
|
||||
|
||||
update(id: number, updatePrintDto: UpdatePrintDto) {
|
||||
return `This action updates a #${id} print`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} print`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user