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