form builder
This commit is contained in:
@@ -7,6 +7,7 @@ import { CreateFieldOptionDto } from '../dto/create-field-option.dto';
|
|||||||
import { FieldOptionService } from '../provider/field-option.service';
|
import { FieldOptionService } from '../provider/field-option.service';
|
||||||
import { UpdateFieldDto } from '../dto/update-field.dto';
|
import { UpdateFieldDto } from '../dto/update-field.dto';
|
||||||
import { UpdateFieldOptionDto } from '../dto/update-field-option.dto';
|
import { UpdateFieldOptionDto } from '../dto/update-field-option.dto';
|
||||||
|
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@@ -39,6 +40,13 @@ export class FormBuilderController {
|
|||||||
return this.fieldService.findAll(+entityId);
|
return this.fieldService.findAll(+entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('admin/entity/group/field')
|
||||||
|
@ApiOperation({ summary: 'find fields of array of entities' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
findAllEntityFields(@Body() dto: FindFieldsGroupDto) {
|
||||||
|
return this.fieldService.findAllByIds(dto);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('admin/entity/field/:id')
|
@Get('admin/entity/field/:id')
|
||||||
@ApiOperation({ summary: 'Find one field' })
|
@ApiOperation({ summary: 'Find one field' })
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { IsArray, IsNotEmpty, IsNumber } from 'class-validator';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class FindFieldsGroupDto {
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsArray()
|
||||||
|
@IsNumber({}, { each: true })
|
||||||
|
@ApiProperty()
|
||||||
|
entityIds: number[]
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import { Product } from 'src/modules/product/entities/product.entity';
|
|||||||
import { Print } from 'src/modules/print/entities/print.entity';
|
import { Print } from 'src/modules/print/entities/print.entity';
|
||||||
import { ProductService } from 'src/modules/product/providers/product.service';
|
import { ProductService } from 'src/modules/product/providers/product.service';
|
||||||
import { PrintService } from 'src/modules/print/provider/Print.service';
|
import { PrintService } from 'src/modules/print/provider/Print.service';
|
||||||
|
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -78,6 +79,29 @@ export class FieldService {
|
|||||||
{ populate: ['options'] });
|
{ populate: ['options'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findAllByIds(dto: FindFieldsGroupDto) {
|
||||||
|
const fields = await this.fieldRepository.find({
|
||||||
|
entityId: { $in: dto.entityIds }
|
||||||
|
},
|
||||||
|
{ populate: ['options'] },
|
||||||
|
);
|
||||||
|
|
||||||
|
// const fieldMap = new Map(fields.map(f => [f.entityId, f]))
|
||||||
|
|
||||||
|
const result: { entityId: number, fields: Field[] }[] = []
|
||||||
|
|
||||||
|
fields.forEach(field => {
|
||||||
|
if (!result.find((r => r.entityId == Number(field.entityId)))) {
|
||||||
|
result.push({
|
||||||
|
entityId: Number(field.entityId),
|
||||||
|
fields: fields.filter(f => f.entityId == field.entityId)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
async findById(fieldId: number): Promise<Field> {
|
async findById(fieldId: number): Promise<Field> {
|
||||||
const field = await this.fieldRepository.findOne({ id: fieldId },
|
const field = await this.fieldRepository.findOne({ id: fieldId },
|
||||||
{ populate: [] });
|
{ populate: [] });
|
||||||
|
|||||||
Reference in New Issue
Block a user