This commit is contained in:
@@ -11,8 +11,7 @@ import { FieldOptionService } from '../provider/field-option.service';
|
||||
|
||||
@Controller('admin/print')
|
||||
@ApiBearerAuth()
|
||||
@ApiBearerAuth()
|
||||
export class PrintController {
|
||||
export class PrintController {
|
||||
constructor(
|
||||
private readonly sectionService: SectionService,
|
||||
private readonly fieldService: FieldService,
|
||||
@@ -65,35 +64,35 @@ export class PrintController {
|
||||
return this.fieldService.create(sectionId,dto);
|
||||
}
|
||||
|
||||
@Get('section/field')
|
||||
@ApiOperation({ summary: 'find all field' })
|
||||
@Get('section/:id/field')
|
||||
@ApiOperation({ summary: 'find all secion fields' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAllFileds() {
|
||||
return this.sectionService.findAll();
|
||||
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.sectionService.findById(+id);
|
||||
return this.fieldService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch('section/field/:id')
|
||||
@ApiOperation({ summary: 'Update field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
updateField(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||
return this.sectionService.update(+id, dto);
|
||||
return this.fieldService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete('section/field/:id')
|
||||
@ApiOperation({ summary: 'Renopve field' })
|
||||
@UseGuards(AdminAuthGuard)
|
||||
removeField(@Param('id') id: string) {
|
||||
return this.sectionService.remove(+id);
|
||||
return this.fieldService.remove(+id);
|
||||
}
|
||||
|
||||
/*================================ Field ========================== */
|
||||
/*================================ Field Option ========================== */
|
||||
|
||||
@Post('field/:id/option')
|
||||
@ApiOperation({ summary: 'Create field Options ' })
|
||||
|
||||
@@ -58,7 +58,10 @@ export class FieldService {
|
||||
}
|
||||
|
||||
findAll(sectionId: number) {
|
||||
return this.fieldRepository.find({ section: { id: sectionId } });
|
||||
return this.fieldRepository.find({
|
||||
section: { id: sectionId }
|
||||
},
|
||||
{ populate: ['options', 'options.value'] });
|
||||
}
|
||||
|
||||
async findById(fieldId: number): Promise<Field> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BadGatewayException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { FieldRepository } from '../repository/field.repository';
|
||||
@@ -49,12 +49,12 @@ export class SectionService {
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.sectionRepository.findAll();
|
||||
return this.sectionRepository.findAll({ populate: ['fields', 'fields.options', 'fields.options.value'] });
|
||||
}
|
||||
|
||||
async findById(attributeId: number): Promise<Section> {
|
||||
const section = await this.sectionRepository.findOne({ id: attributeId },
|
||||
{ populate: ['fields'] });
|
||||
{ populate: ['fields', 'fields.options', 'fields.options.value'] });
|
||||
|
||||
if (!section) throw new NotFoundException('Section not found');
|
||||
return section;
|
||||
|
||||
Reference in New Issue
Block a user