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