bug
This commit is contained in:
@@ -9,8 +9,9 @@ export class CreateFieldDto {
|
|||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
sectionId: string;
|
sectionId!: string;
|
||||||
|
|
||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
|||||||
@@ -1,36 +1,92 @@
|
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||||
import { SectionService } from './provider/section.service';
|
import { SectionService } from './provider/section.service';
|
||||||
import { CreateSectionDto } from './dto/create-section.dto';
|
import { CreateSectionDto } from './dto/create-section.dto';
|
||||||
import { UpdateSectionDto } from './dto/update-section.dto';
|
import { UpdateSectionDto } from './dto/update-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';
|
||||||
|
|
||||||
@Controller('admin/print')
|
@Controller('admin/print')
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiBearerAuth()
|
||||||
export class PrintController {
|
export class PrintController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly sectionService: SectionService
|
private readonly sectionService: SectionService,
|
||||||
|
private readonly fieldService: FieldService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
/*================================ Section ========================== */
|
||||||
|
|
||||||
@Post('section')
|
@Post('section')
|
||||||
|
@ApiOperation({ summary: 'Create section' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
create(@Body() dto: CreateSectionDto) {
|
create(@Body() dto: CreateSectionDto) {
|
||||||
return this.sectionService.create(dto);
|
return this.sectionService.create(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('section')
|
@Get('section')
|
||||||
|
@ApiOperation({ summary: 'find all section' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.sectionService.findAll();
|
return this.sectionService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('section/:id')
|
@Get('section/:id')
|
||||||
|
@ApiOperation({ summary: 'Find one section' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
return this.sectionService.findById(+id);
|
return this.sectionService.findById(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch('section/:id')
|
@Patch('section/:id')
|
||||||
|
@ApiOperation({ summary: 'Update section' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
update(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||||
return this.sectionService.update(+id, dto);
|
return this.sectionService.update(+id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('section/:id')
|
@Delete('section/:id')
|
||||||
|
@ApiOperation({ summary: 'Renopve section' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
return this.sectionService.remove(+id);
|
return this.sectionService.remove(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*================================ Field ========================== */
|
||||||
|
|
||||||
|
@Post('field')
|
||||||
|
@ApiOperation({ summary: 'Create field' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
createField(@Body() dto: CreateFieldDto) {
|
||||||
|
return this.fieldService.create(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('field')
|
||||||
|
@ApiOperation({ summary: 'find all field' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
findAllFileds() {
|
||||||
|
return this.sectionService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('field/:id')
|
||||||
|
@ApiOperation({ summary: 'Find one field' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
findOneFiled(@Param('id') id: string) {
|
||||||
|
return this.sectionService.findById(+id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch('field/:id')
|
||||||
|
@ApiOperation({ summary: 'Update field' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
updateField(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||||
|
return this.sectionService.update(+id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete('field/:id')
|
||||||
|
@ApiOperation({ summary: 'Renopve field' })
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
removeField(@Param('id') id: string) {
|
||||||
|
return this.sectionService.remove(+id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ import { FieldOption } from './entities/field-option.entity';
|
|||||||
import { FieldRepository } from './repository/field.repository';
|
import { FieldRepository } from './repository/field.repository';
|
||||||
import { FieldOptionRepository } from './repository/field-option.repository';
|
import { FieldOptionRepository } from './repository/field-option.repository';
|
||||||
import { SectionRepository } from './repository/section.repository';
|
import { SectionRepository } from './repository/section.repository';
|
||||||
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
import { RolesModule } from '../roles/roles.module';
|
||||||
|
import { FieldService } from './provider/field.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [PrintController],
|
controllers: [PrintController],
|
||||||
providers: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository],
|
providers: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository,FieldService],
|
||||||
exports: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository],
|
exports: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository],
|
||||||
imports: [MikroOrmModule.forFeature([Field, Section, FieldOption])]
|
imports: [MikroOrmModule.forFeature([Field, Section, FieldOption]),RolesModule,JwtModule.register({})]
|
||||||
})
|
})
|
||||||
export class PrintModule { }
|
export class PrintModule { }
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import { BadGatewayException, BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, 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';
|
||||||
import { SectionRepository } from '../repository/section.repository';
|
import { SectionRepository } from '../repository/section.repository';
|
||||||
import { CreateSectionDto } from '../dto/create-section.dto';
|
|
||||||
import { Section } from '../entities/section.entity';
|
|
||||||
import { UpdateSectionDto } from '../dto/update-section.dto';
|
import { UpdateSectionDto } from '../dto/update-section.dto';
|
||||||
import { Field } from '../entities/field.entity';
|
import { Field } from '../entities/field.entity';
|
||||||
import { CreateFieldDto } from '../dto/create-field.dto';
|
import { CreateFieldDto } from '../dto/create-field.dto';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SectionService {
|
export class FieldService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly sectionRepository: SectionRepository,
|
private readonly sectionRepository: SectionRepository,
|
||||||
@@ -19,8 +17,8 @@ export class SectionService {
|
|||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(sectionId: number, dto: CreateFieldDto) {
|
async create(dto: CreateFieldDto) {
|
||||||
const section = await this.sectionRepository.findOne({ id: sectionId })
|
const section = await this.sectionRepository.findOne({ id: dto.sectionId })
|
||||||
|
|
||||||
if (!section) {
|
if (!section) {
|
||||||
throw new BadRequestException("Section not found !")
|
throw new BadRequestException("Section not found !")
|
||||||
@@ -73,7 +71,7 @@ export class SectionService {
|
|||||||
async remove(id: number): Promise<void> {
|
async remove(id: number): Promise<void> {
|
||||||
const field = await this.findById(id);
|
const field = await this.findById(id);
|
||||||
|
|
||||||
// field.deletedAt = new Date();
|
field.deletedAt = new Date();
|
||||||
return await this.em.persistAndFlush(field);
|
return await this.em.persistAndFlush(field);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user