section
This commit is contained in:
@@ -100,6 +100,9 @@ export class Order extends BaseEntity {
|
||||
@Property({ type: 'json', nullable: true })
|
||||
attachments?: string[]
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
printIds?: string[]
|
||||
|
||||
@Property({ type: 'string', nullable: true })
|
||||
paymentMethod?: string;
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export class CreatePrintDto {}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class CreateSectionDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: ' ' })
|
||||
title: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 1 })
|
||||
order?: number;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreatePrintDto } from './create-print.dto';
|
||||
import { CreateSectionDto } from './create-section.dto';
|
||||
|
||||
export class UpdatePrintDto extends PartialType(CreatePrintDto) {}
|
||||
export class UpdatePrintDto extends PartialType(CreateSectionDto) { }
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class UpdateSectionDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: ' ' })
|
||||
title: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 1 })
|
||||
order?: number;
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
import { Cascade, Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Field } from './field.entity';
|
||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'section' })
|
||||
export class Section {
|
||||
export class Section extends BaseEntity {
|
||||
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
||||
id: bigint
|
||||
|
||||
@OneToMany(() => Field, (attrValue) => attrValue.section, { cascade: [Cascade.PERSIST, Cascade.REMOVE] })
|
||||
Fields = new Collection<Field>(this)
|
||||
fields = new Collection<Field>(this)
|
||||
|
||||
@Property()
|
||||
title: string;
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { PrintService } from './print.service';
|
||||
import { CreatePrintDto } from './dto/create-print.dto';
|
||||
import { UpdatePrintDto } from './dto/update-print.dto';
|
||||
import { SectionService } from './provider/section.service';
|
||||
import { CreateSectionDto } from './dto/create-section.dto';
|
||||
import { UpdateSectionDto } from './dto/update-section.dto';
|
||||
|
||||
@Controller('print')
|
||||
@Controller('admin/print')
|
||||
export class PrintController {
|
||||
constructor(private readonly printService: PrintService) {}
|
||||
constructor(
|
||||
private readonly sectionService: SectionService
|
||||
) { }
|
||||
|
||||
@Post()
|
||||
create(@Body() createPrintDto: CreatePrintDto) {
|
||||
return this.printService.create(createPrintDto);
|
||||
@Post('section')
|
||||
create(@Body() dto: CreateSectionDto) {
|
||||
return this.sectionService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Get('section')
|
||||
findAll() {
|
||||
return this.printService.findAll();
|
||||
return this.sectionService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Get('section/:id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.printService.findOne(+id);
|
||||
return this.sectionService.findById(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updatePrintDto: UpdatePrintDto) {
|
||||
return this.printService.update(+id, updatePrintDto);
|
||||
@Patch('section/:id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||
return this.sectionService.update(+id, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete('section/:id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.printService.remove(+id);
|
||||
return this.sectionService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrintService } from './print.service';
|
||||
import { SectionService } from './provider/section.service';
|
||||
import { PrintController } from './print.controller';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { Field } from './entities/field.entity';
|
||||
import { Section } from './entities/section.entity';
|
||||
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';
|
||||
|
||||
@Module({
|
||||
controllers: [PrintController],
|
||||
providers: [PrintService],
|
||||
providers: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository],
|
||||
exports: [SectionService, FieldRepository, FieldOptionRepository, SectionRepository],
|
||||
imports: [MikroOrmModule.forFeature([Field, Section, FieldOption])]
|
||||
})
|
||||
export class PrintModule { }
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreatePrintDto } from './dto/create-print.dto';
|
||||
import { UpdatePrintDto } from './dto/update-print.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PrintService {
|
||||
create(createPrintDto: CreatePrintDto) {
|
||||
return 'This action adds a new print';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all print`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} print`;
|
||||
}
|
||||
|
||||
update(id: number, updatePrintDto: UpdatePrintDto) {
|
||||
return `This action updates a #${id} print`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} print`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { BadGatewayException, 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';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class SectionService {
|
||||
|
||||
constructor(
|
||||
private readonly sectionRepository: SectionRepository,
|
||||
private readonly fieldRepository: FieldRepository,
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
async create(dto: CreateSectionDto) {
|
||||
|
||||
const data: RequiredEntityData<Section> = {
|
||||
title: dto.title,
|
||||
order: dto.order,
|
||||
};
|
||||
|
||||
const section = this.sectionRepository.create(data)
|
||||
|
||||
await this.em.persistAndFlush(section)
|
||||
|
||||
return section
|
||||
|
||||
}
|
||||
|
||||
async update(sectionId: number, dto: UpdateSectionDto) {
|
||||
|
||||
const section = await this.sectionRepository.findOne({ id: sectionId })
|
||||
|
||||
if (!section) {
|
||||
throw new NotFoundException('Section not found');
|
||||
}
|
||||
|
||||
this.sectionRepository.assign(section, dto)
|
||||
|
||||
this.em.persistAndFlush(section)
|
||||
|
||||
return section
|
||||
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.sectionRepository.findAll();
|
||||
}
|
||||
|
||||
async findById(attributeId: number): Promise<Section> {
|
||||
const section = await this.sectionRepository.findOne({ id: attributeId },
|
||||
{ populate: ['fields'] });
|
||||
|
||||
if (!section) throw new NotFoundException('Section not found');
|
||||
return section;
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
const section = await this.findById(id);
|
||||
|
||||
section.deletedAt = new Date();
|
||||
return await this.em.persistAndFlush(section);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { BadGatewayException, 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';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class SectionService {
|
||||
|
||||
constructor(
|
||||
private readonly sectionRepository: SectionRepository,
|
||||
private readonly fieldRepository: FieldRepository,
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
async create(dto: CreateSectionDto) {
|
||||
|
||||
const data: RequiredEntityData<Section> = {
|
||||
title: dto.title,
|
||||
order: dto.order,
|
||||
};
|
||||
|
||||
const section = this.sectionRepository.create(data)
|
||||
|
||||
await this.em.persistAndFlush(section)
|
||||
|
||||
return section
|
||||
|
||||
}
|
||||
|
||||
async update(sectionId: number, dto: UpdateSectionDto) {
|
||||
|
||||
const section = await this.sectionRepository.findOne({ id: sectionId })
|
||||
|
||||
if (!section) {
|
||||
throw new NotFoundException('Section not found');
|
||||
}
|
||||
|
||||
this.sectionRepository.assign(section, dto)
|
||||
|
||||
this.em.persistAndFlush(section)
|
||||
|
||||
return section
|
||||
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.sectionRepository.findAll();
|
||||
}
|
||||
|
||||
async findById(attributeId: number): Promise<Section> {
|
||||
const section = await this.sectionRepository.findOne({ id: attributeId },
|
||||
{ populate: ['fields'] });
|
||||
|
||||
if (!section) throw new NotFoundException('Section not found');
|
||||
return section;
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
const section = await this.findById(id);
|
||||
|
||||
section.deletedAt = new Date();
|
||||
return await this.em.persistAndFlush(section);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { FieldOption } from '../entities/field-option.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class FieldOptionRepository extends EntityRepository<FieldOption> {
|
||||
constructor(readonly em: EntityManager) {
|
||||
super(em, FieldOption);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { Field } from '../entities/field.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class FieldRepository extends EntityRepository<Field> {
|
||||
constructor(readonly em: EntityManager) {
|
||||
super(em, Field);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { Section } from '../entities/section.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class SectionRepository extends EntityRepository<Section> {
|
||||
constructor(readonly em: EntityManager) {
|
||||
super(em, Section);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user