From 20ea6a82ddf7c74a8d29d71ce1cb2edc961c6478 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 31 Jan 2026 15:17:59 +0330 Subject: [PATCH] print --- .../form-builder/provider/field.service.ts | 2 +- src/modules/order/dto/create-order.dto.ts | 4 +- .../print/controller/print.controller.ts | 2 +- src/modules/print/print.module.ts | 2 +- src/modules/print/provider/Print.service.ts | 69 ------------------- src/modules/print/provider/print.service.ts | 69 +++++++++++++++++++ 6 files changed, 74 insertions(+), 74 deletions(-) delete mode 100644 src/modules/print/provider/Print.service.ts create mode 100644 src/modules/print/provider/print.service.ts diff --git a/src/modules/form-builder/provider/field.service.ts b/src/modules/form-builder/provider/field.service.ts index 2c85010..16efcc1 100644 --- a/src/modules/form-builder/provider/field.service.ts +++ b/src/modules/form-builder/provider/field.service.ts @@ -9,7 +9,7 @@ import { EntityType } from '../interface/print'; import { Product } from 'src/modules/product/entities/product.entity'; import { Print } from 'src/modules/print/entities/print.entity'; import { ProductService } from 'src/modules/product/providers/product.service'; -import { PrintService } from 'src/modules/print/provider/Print.service'; +import { PrintService } from 'src/modules/print/provider/print.service'; import { FindFieldsGroupDto } from '../dto/find-field-group.dto'; diff --git a/src/modules/order/dto/create-order.dto.ts b/src/modules/order/dto/create-order.dto.ts index d0e77e5..e33e6e3 100644 --- a/src/modules/order/dto/create-order.dto.ts +++ b/src/modules/order/dto/create-order.dto.ts @@ -98,8 +98,8 @@ export class CreateOrderAsAdminDto { { productId: 1, designerId: '', - print: [{ fieldId: '', value: '' }], - printAttachments: [{ url: '', type: '' }], + // print: [{ fieldId: '', value: '' }], + // printAttachments: [{ url: '', type: '' }], quantity: 100, attributes: [], unitPrice:150000, diff --git a/src/modules/print/controller/print.controller.ts b/src/modules/print/controller/print.controller.ts index 084dcec..10f80f5 100644 --- a/src/modules/print/controller/print.controller.ts +++ b/src/modules/print/controller/print.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { PrintService } from '../provider/Print.service'; +import { PrintService } from '../provider/print.service'; import { CreateSectionDto } from '../dto/create-section.dto'; import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard'; diff --git a/src/modules/print/print.module.ts b/src/modules/print/print.module.ts index d4709fa..be94003 100644 --- a/src/modules/print/print.module.ts +++ b/src/modules/print/print.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { PrintService } from './provider/Print.service'; +import { PrintService } from './provider/print.service'; import { PrintController } from './controller/print.controller'; import { MikroOrmModule } from '@mikro-orm/nestjs'; import { Print } from './entities/print.entity'; diff --git a/src/modules/print/provider/Print.service.ts b/src/modules/print/provider/Print.service.ts deleted file mode 100644 index 6ad2378..0000000 --- a/src/modules/print/provider/Print.service.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Injectable, NotFoundException } from '@nestjs/common'; -import { EntityManager } from '@mikro-orm/postgresql'; -import { RequiredEntityData } from '@mikro-orm/core'; -import { PrintRepository } from '../repository/print.repository'; -import { CreateSectionDto } from '../dto/create-section.dto'; -import { Print } from '../entities/print.entity'; -import { UpdateSectionDto } from '../dto/update-section.dto'; - - -@Injectable() -export class PrintService { - - constructor( - private readonly sectionRepository: PrintRepository, - private readonly em: EntityManager, - ) { } - - async create(dto: CreateSectionDto) { - - const data: RequiredEntityData = { - 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('Print not found'); - } - - this.sectionRepository.assign(section, dto) - - this.em.persistAndFlush(section) - - return section - - } - - findAll() { - return this.sectionRepository.findAll({ populate: ['fields', 'fields.options', 'fields.options.value'] }); - } - - async findOneOrFail(attributeId: number): Promise { - const section = await this.sectionRepository.findOne({ id: attributeId }, - { populate: ['fields', 'fields.options', 'fields.options.value'] }); - - if (!section) throw new NotFoundException('Print not found'); - return section; - } - - async remove(id: number): Promise { - const section = await this.findOneOrFail(id); - - section.deletedAt = new Date(); - return await this.em.persistAndFlush(section); - - } - -} diff --git a/src/modules/print/provider/print.service.ts b/src/modules/print/provider/print.service.ts new file mode 100644 index 0000000..d94f3b4 --- /dev/null +++ b/src/modules/print/provider/print.service.ts @@ -0,0 +1,69 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { EntityManager } from '@mikro-orm/postgresql'; +import { RequiredEntityData } from '@mikro-orm/core'; +import { PrintRepository } from '../repository/print.repository'; +import { CreateSectionDto } from '../dto/create-section.dto'; +import { Print } from '../entities/print.entity'; +import { UpdateSectionDto } from '../dto/update-section.dto'; + + +@Injectable() +export class PrintService { + + constructor( + private readonly printRepository: PrintRepository, + private readonly em: EntityManager, + ) { } + + async create(dto: CreateSectionDto) { + + const data: RequiredEntityData = { + title: dto.title, + order: dto.order, + }; + + const print = this.printRepository.create(data) + + await this.em.persistAndFlush(print) + + return print + + } + + async update(sectionId: number, dto: UpdateSectionDto) { + + const print = await this.finOrFail(sectionId) + + this.printRepository.assign(print, dto) + + this.em.persistAndFlush(print) + + return print + + } + + findAll() { + return this.printRepository.findAll(); + } + + + async remove(id: number): Promise { + const print = await this.finOrFail(id); + + print.deletedAt = new Date(); + + return await this.em.persistAndFlush(print); + + } + + // ============== Helpers ========== + async finOrFail(printId: number) { + const printSection = await this.printRepository.findOne({ id: printId }) + + if (!printSection) { + throw new NotFoundException('printSection not found'); + } + + return printSection + } +}