This commit is contained in:
2026-01-31 15:17:59 +03:30
parent 23cc94bb23
commit 20ea6a82dd
6 changed files with 74 additions and 74 deletions
@@ -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';
+2 -2
View File
@@ -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,
@@ -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';
+1 -1
View File
@@ -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';
@@ -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<Print> = {
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<Print> {
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<void> {
const section = await this.findOneOrFail(id);
section.deletedAt = new Date();
return await this.em.persistAndFlush(section);
}
}
@@ -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<Print> = {
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<void> {
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
}
}