form builder module
This commit is contained in:
@@ -17,6 +17,7 @@ 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';
|
||||
import { FormBuilderModule } from './modules/form-builder/form-builder.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -41,6 +42,7 @@ import { PrintModule } from './modules/print/print.module';
|
||||
NotificationsModule,
|
||||
EventEmitterModule.forRoot(),
|
||||
PrintModule,
|
||||
FormBuilderModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||
import { FieldService } from '../provider/field.service';
|
||||
import { CreateFieldDto } from '../dto/create-field.dto';
|
||||
import { CreateFieldOptionDto } from '../dto/create-field-option.dto';
|
||||
import { FieldOptionService } from '../provider/field-option.service';
|
||||
import { UpdateFieldDto } from '../dto/update-field.dto';
|
||||
import { UpdateFieldOptionDto } from '../dto/update-field-option.dto';
|
||||
|
||||
@Controller('admin')
|
||||
@ApiBearerAuth()
|
||||
export class FormBuilderController {
|
||||
constructor(
|
||||
private readonly fieldService: FieldService,
|
||||
private readonly fieldOptionService: FieldOptionService,
|
||||
) { }
|
||||
|
||||
|
||||
/*================================ Field ========================== */
|
||||
|
||||
@Post('section/:id/field')
|
||||
@ApiOperation({ summary: 'Create field for section' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
createField(@Body() dto: CreateFieldDto, @Param('id') sectionId: string) {
|
||||
return this.fieldService.create(sectionId,dto);
|
||||
}
|
||||
|
||||
@Get('section/:id/field')
|
||||
@ApiOperation({ summary: 'find all secion fields' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAllSectionFields(@Param('id') sectionId: string) {
|
||||
return this.fieldService.findAll(+sectionId);
|
||||
}
|
||||
|
||||
@Get('section/field/:id')
|
||||
@ApiOperation({ summary: 'Find one field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findOneFiled(@Param('id') id: string) {
|
||||
return this.fieldService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('section/field/:id')
|
||||
@ApiOperation({ summary: 'Update field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
updateField(@Param('id') id: string, @Body() dto: UpdateFieldDto) {
|
||||
return this.fieldService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete('section/field/:id')
|
||||
@ApiOperation({ summary: 'Renopve field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
removeField(@Param('id') id: string) {
|
||||
return this.fieldService.remove(+id);
|
||||
}
|
||||
|
||||
/*================================ Field Option ========================== */
|
||||
|
||||
@Post('field/:id/option')
|
||||
@ApiOperation({ summary: 'Create field Options ' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
createFieldOption(@Body() dto: CreateFieldOptionDto, @Param('id') id: string) {
|
||||
return this.fieldOptionService.create(+id, dto);
|
||||
}
|
||||
|
||||
@Get('field/:id/option')
|
||||
@ApiOperation({ summary: 'find all field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAllFiledOptions(@Param('id') fieldId: string) {
|
||||
return this.fieldOptionService.findAll(+fieldId);
|
||||
}
|
||||
|
||||
@Get('field/option/:id')
|
||||
@ApiOperation({ summary: 'Find one field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findOneFiledOption(@Param('id') id: string) {
|
||||
return this.fieldOptionService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('field/option/:id')
|
||||
@ApiOperation({ summary: 'Update field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
updateFieldOption(@Param('id') id: string, @Body() dto: UpdateFieldOptionDto) {
|
||||
return this.fieldOptionService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete('field/option/:id')
|
||||
@ApiOperation({ summary: 'Renopve field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
removeFieldOption(@Param('id') id: string) {
|
||||
return this.fieldOptionService.remove(+id);
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -1,8 +1,9 @@
|
||||
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';
|
||||
import { Section } from 'src/modules/print/entities/section.entity';
|
||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
import { Product } from 'src/modules/product/entities/product.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'field' })
|
||||
@@ -13,8 +14,11 @@ export class Field extends BaseEntity {
|
||||
@OneToMany(() => FieldOption, (attrValue) => attrValue.field)
|
||||
options = new Collection<FieldOption>(this)
|
||||
|
||||
@ManyToOne(() => Section)
|
||||
section!: Section
|
||||
@ManyToOne(() => Section, { nullable: true })
|
||||
section?: Section
|
||||
|
||||
@ManyToOne(() => Product, { nullable: true })
|
||||
product?: Product
|
||||
|
||||
@Property()
|
||||
name: string;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FormBuilderController } from './controller/form-builder.controller';
|
||||
import { FieldService } from './provider/field.service';
|
||||
import { FieldOptionService } from './provider/field-option.service';
|
||||
import { PrintModule } from '../print/print.module';
|
||||
import { FieldRepository } from './repository/field.repository';
|
||||
import { FieldOptionRepository } from './repository/field-option.repository';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
@Module({
|
||||
imports: [PrintModule, JwtModule.register({})],
|
||||
controllers: [FormBuilderController],
|
||||
providers: [FieldService, FieldOptionService, FieldRepository, FieldOptionRepository],
|
||||
exports: [FieldService, FieldOptionService, FieldRepository, FieldOptionRepository],
|
||||
})
|
||||
export class FormBuilderModule { }
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum FieldType {
|
||||
text = 'text',
|
||||
textarea = 'textarea',
|
||||
number = 'number',
|
||||
select = 'select',
|
||||
radio = 'radio',
|
||||
checkbox = 'checkbox',
|
||||
date = 'date',
|
||||
}
|
||||
+3
-3
@@ -2,10 +2,10 @@ import { BadRequestException, Injectable, NotFoundException } from '@nestjs/comm
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { FieldRepository } from '../repository/field.repository';
|
||||
import { SectionRepository } from '../repository/section.repository';
|
||||
import { UpdateSectionDto } from '../dto/update-section.dto';
|
||||
import { SectionRepository } from 'src/modules/print/repository/section.repository';
|
||||
import { Field } from '../entities/field.entity';
|
||||
import { CreateFieldDto } from '../dto/create-field.dto';
|
||||
import { UpdateFieldDto } from '../dto/update-field.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -41,7 +41,7 @@ export class FieldService {
|
||||
|
||||
}
|
||||
|
||||
async update(fieldId: number, dto: UpdateSectionDto) {
|
||||
async update(fieldId: number, dto: UpdateFieldDto) {
|
||||
|
||||
const field = await this.fieldRepository.findOne({ id: fieldId })
|
||||
|
||||
@@ -129,7 +129,7 @@ export class OrderController {
|
||||
@Post('admin/orders/:orderId/invoice')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiOperation({ summary: 'Create Order invoice ' })
|
||||
createInvoice(@Param('orderId') orderId: string) {
|
||||
createInvoice(@Param('orderId') orderId: string, @Body() dto: UpdateOrderDtoAsAdmin) {
|
||||
return this.orderService.createInvoice(orderId);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,14 +74,14 @@ export class Order {
|
||||
|
||||
// @Property({ type: 'decimal', precision: 10, scale: 0, default: null, nullable: true })
|
||||
// subTotal?: number;
|
||||
@Formula(alias => `
|
||||
@Formula(alias => `
|
||||
(
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
)
|
||||
`)
|
||||
subTotal!: number;
|
||||
subTotal!: number;
|
||||
|
||||
|
||||
// @Property({ type: 'decimal', precision: 10, scale: 0, default: null, nullable: true })
|
||||
@@ -202,7 +202,7 @@ subTotal!: number;
|
||||
attachments?: string[]
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
printIds?: string[] // id of field options
|
||||
print?: { fieldId: string, value: string }[] // id of field options
|
||||
|
||||
@Property({ type: 'string', nullable: true })
|
||||
paymentMethod?: string;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { Product } from "src/modules/product/entities/product.entity"
|
||||
import { Order } from "../entities/order.entity"
|
||||
|
||||
export enum OrderStatusEnum {
|
||||
CREATED = 'created',
|
||||
|
||||
|
||||
@@ -285,10 +285,7 @@ export class OrderService {
|
||||
}
|
||||
|
||||
async createInvoice(orderId: string) {
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
await this.updateStatus(orderId, OrderStatusEnum.INVOICED)
|
||||
// await this.calculateOrder(order)
|
||||
await this.em.flush()
|
||||
}
|
||||
|
||||
async getOrderAsUser(userId: string, orderId: string) {
|
||||
|
||||
@@ -3,20 +3,13 @@ import { SectionService } from '../provider/section.service';
|
||||
import { CreateSectionDto } from '../dto/create-section.dto';
|
||||
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||
import { FieldService } from '../provider/field.service';
|
||||
import { CreateFieldDto } from '../dto/create-field.dto';
|
||||
import { CreateFieldOptionDto } from '../dto/create-field-option.dto';
|
||||
import { FieldOptionService } from '../provider/field-option.service';
|
||||
import { UpdateFieldDto } from '../dto/update-field.dto';
|
||||
import { UpdateSectionDto } from '../dto/update-section.dto';
|
||||
|
||||
@Controller('admin')
|
||||
@ApiBearerAuth()
|
||||
export class PrintController {
|
||||
export class PrintController {
|
||||
constructor(
|
||||
private readonly sectionService: SectionService,
|
||||
private readonly fieldService: FieldService,
|
||||
private readonly fieldOptionService: FieldOptionService,
|
||||
) { }
|
||||
|
||||
/*================================ Section ========================== */
|
||||
@@ -56,77 +49,4 @@ import { UpdateSectionDto } from '../dto/update-section.dto';
|
||||
return this.sectionService.remove(+id);
|
||||
}
|
||||
|
||||
/*================================ Field ========================== */
|
||||
|
||||
@Post('section/:id/field')
|
||||
@ApiOperation({ summary: 'Create field for section' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
createField(@Body() dto: CreateFieldDto, @Param('id') sectionId: string) {
|
||||
return this.fieldService.create(sectionId,dto);
|
||||
}
|
||||
|
||||
@Get('section/:id/field')
|
||||
@ApiOperation({ summary: 'find all secion fields' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAllSectionFields(@Param('id') sectionId: string) {
|
||||
return this.fieldService.findAll(+sectionId);
|
||||
}
|
||||
|
||||
@Get('section/field/:id')
|
||||
@ApiOperation({ summary: 'Find one field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findOneFiled(@Param('id') id: string) {
|
||||
return this.fieldService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('section/field/:id')
|
||||
@ApiOperation({ summary: 'Update field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
updateField(@Param('id') id: string, @Body() dto: UpdateFieldDto) {
|
||||
return this.fieldService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete('section/field/:id')
|
||||
@ApiOperation({ summary: 'Renopve field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
removeField(@Param('id') id: string) {
|
||||
return this.fieldService.remove(+id);
|
||||
}
|
||||
|
||||
/*================================ Field Option ========================== */
|
||||
|
||||
@Post('field/:id/option')
|
||||
@ApiOperation({ summary: 'Create field Options ' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
createFieldOption(@Body() dto: CreateFieldOptionDto, @Param('id') id: string) {
|
||||
return this.fieldOptionService.create(+id, dto);
|
||||
}
|
||||
|
||||
@Get('field/:id/option')
|
||||
@ApiOperation({ summary: 'find all field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAllFiledOptions(@Param('id') fieldId: string) {
|
||||
return this.fieldOptionService.findAll(+fieldId);
|
||||
}
|
||||
|
||||
@Get('field/option/:id')
|
||||
@ApiOperation({ summary: 'Find one field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findOneFiledOption(@Param('id') id: string) {
|
||||
return this.fieldOptionService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('field/option/:id')
|
||||
@ApiOperation({ summary: 'Update field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
updateFieldOption(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||
return this.fieldOptionService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete('field/option/:id')
|
||||
@ApiOperation({ summary: 'Renopve field Option' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
removeFieldOption(@Param('id') id: string) {
|
||||
return this.fieldOptionService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Cascade, Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Field } from './field.entity';
|
||||
import { Field } from 'src/modules/form-builder/entities/field.entity';
|
||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
export enum FieldType {
|
||||
text = 'text',
|
||||
textarea = 'textarea',
|
||||
number = 'number',
|
||||
select = 'select',
|
||||
radio = 'radio',
|
||||
checkbox = 'checkbox',
|
||||
date = 'date',
|
||||
}
|
||||
@@ -2,24 +2,20 @@ import { Module } from '@nestjs/common';
|
||||
import { SectionService } from './provider/section.service';
|
||||
import { PrintController } from './controller/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';
|
||||
import { FieldRepository } from './repository/field.repository';
|
||||
import { FieldOptionRepository } from './repository/field-option.repository';
|
||||
|
||||
import { SectionRepository } from './repository/section.repository';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { RolesModule } from '../roles/roles.module';
|
||||
import { FieldService } from './provider/field.service';
|
||||
import { FieldOptionService } from './provider/field-option.service';
|
||||
|
||||
|
||||
@Module({
|
||||
controllers: [PrintController],
|
||||
providers: [SectionService, FieldRepository, FieldOptionRepository,
|
||||
SectionRepository, FieldService, FieldOptionService],
|
||||
exports: [SectionService, FieldRepository, FieldOptionRepository,
|
||||
SectionRepository, FieldOptionService],
|
||||
imports: [MikroOrmModule.forFeature([Field, Section, FieldOption]),
|
||||
RolesModule, JwtModule.register({})]
|
||||
providers: [SectionService,
|
||||
SectionRepository],
|
||||
exports: [SectionService,
|
||||
SectionRepository],
|
||||
imports: [MikroOrmModule.forFeature([Section]),
|
||||
RolesModule, JwtModule.register({})]
|
||||
})
|
||||
export class PrintModule { }
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { FieldRepository } from '../repository/field.repository';
|
||||
import { SectionRepository } from '../repository/section.repository';
|
||||
import { CreateSectionDto } from '../dto/create-section.dto';
|
||||
import { Section } from '../entities/section.entity';
|
||||
@@ -13,7 +12,6 @@ export class SectionService {
|
||||
|
||||
constructor(
|
||||
private readonly sectionRepository: SectionRepository,
|
||||
private readonly fieldRepository: FieldRepository,
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { FieldType } from 'src/modules/print/interface/print';
|
||||
import { FieldType } from 'src/modules/form-builder/interface/print';
|
||||
|
||||
export class CreateAttributeDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Product } from './product.entity';
|
||||
import { Product } from './product.entity';
|
||||
import { AttributeValue } from './attribute-value.entity';
|
||||
import { FieldType } from 'src/modules/print/interface/print';
|
||||
import { FieldType } from 'src/modules/form-builder/interface/print';
|
||||
|
||||
@Entity({ tableName: 'attributes' })
|
||||
export class Attribute extends BaseEntity {
|
||||
@@ -13,10 +13,10 @@ export class Attribute extends BaseEntity {
|
||||
parent?: Attribute | null
|
||||
|
||||
@OneToMany(() => Attribute, (c) => c.parent)
|
||||
children=new Collection<Attribute>(this)
|
||||
children = new Collection<Attribute>(this)
|
||||
|
||||
@OneToMany(() => AttributeValue, (attrValue) => attrValue.attribute)
|
||||
values= new Collection<AttributeValue>(this)
|
||||
values = new Collection<AttributeValue>(this)
|
||||
|
||||
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
||||
id: bigint;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FieldType } from "src/modules/print/interface/print";
|
||||
|
||||
|
||||
export interface AttributeValueData {
|
||||
value: string;
|
||||
attributeName: string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FieldType } from "src/modules/print/interface/print";
|
||||
import { FieldType } from "src/modules/form-builder/interface/print";
|
||||
|
||||
export interface AttributeData {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user