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 { UpdateFieldDto } from '../dto/update-field.dto';
|
||||
import { UpdateFieldOptionDto } from '../dto/update-field-option.dto';
|
||||
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
||||
|
||||
@Controller()
|
||||
@ApiBearerAuth()
|
||||
@@ -39,6 +40,13 @@ export class FormBuilderController {
|
||||
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')
|
||||
@ApiOperation({ summary: 'Find one field' })
|
||||
@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 { ProductService } from 'src/modules/product/providers/product.service';
|
||||
import { PrintService } from 'src/modules/print/provider/Print.service';
|
||||
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -78,6 +79,29 @@ export class FieldService {
|
||||
{ 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> {
|
||||
const field = await this.fieldRepository.findOne({ id: fieldId },
|
||||
{ populate: [] });
|
||||
|
||||
Reference in New Issue
Block a user