rename module
This commit is contained in:
@@ -63,7 +63,7 @@ Current modules:
|
|||||||
- **invoice** — Invoicing
|
- **invoice** — Invoicing
|
||||||
- **order** — Order lifecycle
|
- **order** — Order lifecycle
|
||||||
- **payment** — Online payments (Zarinpal)
|
- **payment** — Online payments (Zarinpal)
|
||||||
- **print** — Print-related admin operations
|
- **print-form** — Print form sections and PDF generation
|
||||||
- **ticket** — Support tickets
|
- **ticket** — Support tickets
|
||||||
- **chat** — Order/chat messaging
|
- **chat** — Order/chat messaging
|
||||||
- **notification** — SMS, push, WebSocket notifications
|
- **notification** — SMS, push, WebSocket notifications
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ import { PaymentModule } from './modules/payment/payments.module';
|
|||||||
import { NotificationsModule } from './modules/notification/notifications.module';
|
import { NotificationsModule } from './modules/notification/notifications.module';
|
||||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||||
import { CacheModule } from '@nestjs/cache-manager';
|
import { CacheModule } from '@nestjs/cache-manager';
|
||||||
import { PrintModule } from './modules/print/print.module';
|
import { PrintFormModule } from './modules/print-form/print-form.module';
|
||||||
import { FormBuilderModule } from './modules/form-builder/form-builder.module';
|
import { FormBuilderModule } from './modules/form-builder/form-builder.module';
|
||||||
import { RequestModule } from './modules/request/request.module';
|
import { RequestModule } from './modules/request/request.module';
|
||||||
import { InvoiceModule } from './modules/invoice/invoice.module';
|
import { InvoiceModule } from './modules/invoice/invoice.module';
|
||||||
@@ -48,7 +48,7 @@ import { cacheConfig } from './config/cache.config';
|
|||||||
PaymentModule,
|
PaymentModule,
|
||||||
NotificationsModule,
|
NotificationsModule,
|
||||||
EventEmitterModule.forRoot(),
|
EventEmitterModule.forRoot(),
|
||||||
PrintModule,
|
PrintFormModule,
|
||||||
FormBuilderModule,
|
FormBuilderModule,
|
||||||
RequestModule,
|
RequestModule,
|
||||||
InvoiceModule,
|
InvoiceModule,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class Field extends BaseEntity {
|
|||||||
options = new Collection<FieldOption>(this)
|
options = new Collection<FieldOption>(this)
|
||||||
|
|
||||||
// Discriminator column
|
// Discriminator column
|
||||||
@Enum(() => EntityType) // Product , Print
|
@Enum(() => EntityType) // Product , PrintForm
|
||||||
entityType: EntityType;
|
entityType: EntityType;
|
||||||
|
|
||||||
// Foreign key based on entityType
|
// Foreign key based on entityType
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { forwardRef, Module } from '@nestjs/common';
|
|||||||
import { FormBuilderController } from './controller/form-builder.controller';
|
import { FormBuilderController } from './controller/form-builder.controller';
|
||||||
import { FieldService } from './provider/field.service';
|
import { FieldService } from './provider/field.service';
|
||||||
import { FieldOptionService } from './provider/field-option.service';
|
import { FieldOptionService } from './provider/field-option.service';
|
||||||
import { PrintModule } from '../print/print.module';
|
import { PrintFormModule } from '../print-form/print-form.module';
|
||||||
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 { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
@@ -14,7 +14,7 @@ import { FieldOption } from './entities/field-option.entity';
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
MikroOrmModule.forFeature([Field, FieldOption]),
|
MikroOrmModule.forFeature([Field, FieldOption]),
|
||||||
PrintModule,
|
PrintFormModule,
|
||||||
JwtModule.register({}),
|
JwtModule.register({}),
|
||||||
forwardRef(() => ProductModule),
|
forwardRef(() => ProductModule),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ export enum FieldType {
|
|||||||
|
|
||||||
export enum EntityType {
|
export enum EntityType {
|
||||||
product = 'product',
|
product = 'product',
|
||||||
print = 'print',
|
printForm = 'print',
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@ import { CreateFieldDto } from '../dto/create-field.dto';
|
|||||||
import { UpdateFieldDto } from '../dto/update-field.dto';
|
import { UpdateFieldDto } from '../dto/update-field.dto';
|
||||||
import { EntityType } from '../interface/print';
|
import { EntityType } from '../interface/print';
|
||||||
import { Product } from 'src/modules/product/entities/product.entity';
|
import { Product } from 'src/modules/product/entities/product.entity';
|
||||||
import { Print } from 'src/modules/print/entities/print.entity';
|
import { PrintForm } from 'src/modules/print-form/entities/print-form.entity';
|
||||||
import { ProductService } from 'src/modules/product/providers/product.service';
|
import { ProductService } from 'src/modules/product/providers/product.service';
|
||||||
import { PrintService } from 'src/modules/print/provider/print.service';
|
import { PrintFormService } from 'src/modules/print-form/provider/print-form.service';
|
||||||
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
import { FindFieldsGroupDto } from '../dto/find-field-group.dto';
|
||||||
|
|
||||||
|
|
||||||
@@ -19,19 +19,19 @@ export class FieldService {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly fieldRepository: FieldRepository,
|
private readonly fieldRepository: FieldRepository,
|
||||||
private readonly productService: ProductService,
|
private readonly productService: ProductService,
|
||||||
private readonly printService: PrintService,
|
private readonly printFormService: PrintFormService,
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(entityId: string, dto: CreateFieldDto) {
|
async create(entityId: string, dto: CreateFieldDto) {
|
||||||
const { entityType, isRequired, multiple, name, type, order } = dto
|
const { entityType, isRequired, multiple, name, type, order } = dto
|
||||||
|
|
||||||
let entity: null | Product | Print = null
|
let entity: null | Product | PrintForm = null
|
||||||
|
|
||||||
if (entityType == EntityType.product) {
|
if (entityType == EntityType.product) {
|
||||||
entity = await this.productService.findOneOrFail(entityId)
|
entity = await this.productService.findOneOrFail(entityId)
|
||||||
} else if (entityType == EntityType.print) {
|
} else if (entityType == EntityType.printForm) {
|
||||||
entity = await this.printService.finOrFail(entityId)
|
entity = await this.printFormService.finOrFail(entityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
|
|||||||
+9
-9
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Res } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Res } from '@nestjs/common';
|
||||||
import { PrintService } from '../provider/print.service';
|
import { PrintFormService } from '../provider/print-form.service';
|
||||||
import { CreateSectionDto } from '../dto/create-section.dto';
|
import { CreateSectionDto } from '../dto/create-section.dto';
|
||||||
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||||
@@ -12,9 +12,9 @@ import type { FastifyReply } from 'fastify';
|
|||||||
@Controller('admin')
|
@Controller('admin')
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
export class PrintController {
|
export class PrintFormController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly printService: PrintService,
|
private readonly printFormService: PrintFormService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
/*================================ Section ========================== */
|
/*================================ Section ========================== */
|
||||||
@@ -23,35 +23,35 @@ export class PrintController {
|
|||||||
@Permissions(PermissionEnum.VIEW_PRINT)
|
@Permissions(PermissionEnum.VIEW_PRINT)
|
||||||
@ApiOperation({ summary: 'Create section' })
|
@ApiOperation({ summary: 'Create section' })
|
||||||
create(@Body() dto: CreateSectionDto) {
|
create(@Body() dto: CreateSectionDto) {
|
||||||
return this.printService.create(dto);
|
return this.printFormService.create(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('section')
|
@Get('section')
|
||||||
@ApiOperation({ summary: 'find all section' })
|
@ApiOperation({ summary: 'find all section' })
|
||||||
@Permissions(PermissionEnum.VIEW_PRINT)
|
@Permissions(PermissionEnum.VIEW_PRINT)
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.printService.findAll();
|
return this.printFormService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('section/:id')
|
@Get('section/:id')
|
||||||
@ApiOperation({ summary: 'Find one section' })
|
@ApiOperation({ summary: 'Find one section' })
|
||||||
@Permissions(PermissionEnum.VIEW_PRINT)
|
@Permissions(PermissionEnum.VIEW_PRINT)
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
return this.printService.finOrFail(id);
|
return this.printFormService.finOrFail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch('section/:id')
|
@Patch('section/:id')
|
||||||
@Permissions(PermissionEnum.VIEW_PRINT)
|
@Permissions(PermissionEnum.VIEW_PRINT)
|
||||||
@ApiOperation({ summary: 'Update section' })
|
@ApiOperation({ summary: 'Update section' })
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
update(@Param('id') id: string, @Body() dto: UpdateSectionDto) {
|
||||||
return this.printService.update(id, dto);
|
return this.printFormService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('section/:id')
|
@Delete('section/:id')
|
||||||
@Permissions(PermissionEnum.VIEW_PRINT)
|
@Permissions(PermissionEnum.VIEW_PRINT)
|
||||||
@ApiOperation({ summary: 'Remove section' })
|
@ApiOperation({ summary: 'Remove section' })
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
return this.printService.remove(id);
|
return this.printFormService.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// front end must send form with its selected fields
|
/// front end must send form with its selected fields
|
||||||
@@ -68,7 +68,7 @@ export class PrintController {
|
|||||||
</html>
|
</html>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const pdfBuffer = await this.printService.generatePdf(html);
|
const pdfBuffer = await this.printFormService.generatePdf(html);
|
||||||
|
|
||||||
res
|
res
|
||||||
.header('Content-Type', 'application/pdf')
|
.header('Content-Type', 'application/pdf')
|
||||||
+1
-1
@@ -3,7 +3,7 @@ import { BaseEntity } from 'src/common/entities/base.entity';
|
|||||||
|
|
||||||
|
|
||||||
@Entity({ tableName: 'print' })
|
@Entity({ tableName: 'print' })
|
||||||
export class Print extends BaseEntity {
|
export class PrintForm extends BaseEntity {
|
||||||
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { Field } from "src/modules/form-builder/entities/field.entity";
|
||||||
|
import { PrintForm } from "../entities/print-form.entity";
|
||||||
|
|
||||||
|
export interface PrintFormWithFields extends PrintForm {
|
||||||
|
fields: Field[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { forwardRef, Module } from '@nestjs/common';
|
||||||
|
import { PrintFormService } from './provider/print-form.service';
|
||||||
|
import { PrintFormController } from './controller/print-form.controller';
|
||||||
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||||
|
import { PrintForm } from './entities/print-form.entity';
|
||||||
|
import { PrintFormRepository } from './repository/print-form.repository';
|
||||||
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
import { RolesModule } from '../roles/roles.module';
|
||||||
|
import { FormBuilderModule } from '../form-builder/form-builder.module';
|
||||||
|
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [PrintFormController],
|
||||||
|
providers: [PrintFormService,
|
||||||
|
PrintFormRepository],
|
||||||
|
exports: [PrintFormService,
|
||||||
|
PrintFormRepository],
|
||||||
|
imports: [
|
||||||
|
forwardRef(()=>FormBuilderModule),
|
||||||
|
MikroOrmModule.forFeature([PrintForm]),
|
||||||
|
RolesModule, JwtModule.register({}),
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class PrintFormModule { }
|
||||||
+23
-23
@@ -1,20 +1,20 @@
|
|||||||
import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
import { forwardRef, Inject, 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 { PrintRepository } from '../repository/print.repository';
|
import { PrintFormRepository } from '../repository/print-form.repository';
|
||||||
import { CreateSectionDto } from '../dto/create-section.dto';
|
import { CreateSectionDto } from '../dto/create-section.dto';
|
||||||
import { Print } from '../entities/print.entity';
|
import { PrintForm } from '../entities/print-form.entity';
|
||||||
import { UpdateSectionDto } from '../dto/update-section.dto';
|
import { UpdateSectionDto } from '../dto/update-section.dto';
|
||||||
import { FieldService } from 'src/modules/form-builder/provider/field.service';
|
import { FieldService } from 'src/modules/form-builder/provider/field.service';
|
||||||
import { PrintWithFields } from '../interface/print';
|
import { PrintFormWithFields } from '../interface/print-form';
|
||||||
// import * as puppeteer from 'puppeteer';
|
// import * as puppeteer from 'puppeteer';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrintService {
|
export class PrintFormService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly printRepository: PrintRepository,
|
private readonly printFormRepository: PrintFormRepository,
|
||||||
@Inject(forwardRef(() => FieldService))
|
@Inject(forwardRef(() => FieldService))
|
||||||
private readonly fieldService: FieldService,
|
private readonly fieldService: FieldService,
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
@@ -22,33 +22,33 @@ export class PrintService {
|
|||||||
|
|
||||||
async create(dto: CreateSectionDto) {
|
async create(dto: CreateSectionDto) {
|
||||||
|
|
||||||
const data: RequiredEntityData<Print> = {
|
const data: RequiredEntityData<PrintForm> = {
|
||||||
title: dto.title,
|
title: dto.title,
|
||||||
order: dto.order,
|
order: dto.order,
|
||||||
};
|
};
|
||||||
|
|
||||||
const print = this.printRepository.create(data)
|
const printForm = this.printFormRepository.create(data)
|
||||||
|
|
||||||
await this.em.persistAndFlush(print)
|
await this.em.persistAndFlush(printForm)
|
||||||
|
|
||||||
return print
|
return printForm
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(sectionId: string, dto: UpdateSectionDto) {
|
async update(sectionId: string, dto: UpdateSectionDto) {
|
||||||
|
|
||||||
const print = await this.finOrFail(sectionId)
|
const printForm = await this.finOrFail(sectionId)
|
||||||
|
|
||||||
this.printRepository.assign(print, dto)
|
this.printFormRepository.assign(printForm, dto)
|
||||||
|
|
||||||
this.em.persistAndFlush(print)
|
this.em.persistAndFlush(printForm)
|
||||||
|
|
||||||
return print
|
return printForm
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<PrintWithFields[]> {
|
async findAll(): Promise<PrintFormWithFields[]> {
|
||||||
const sections = await this.printRepository.findAll({ orderBy: { order: 'ASC' } });
|
const sections = await this.printFormRepository.findAll({ orderBy: { order: 'ASC' } });
|
||||||
|
|
||||||
const promises = sections.map(async (section) => {
|
const promises = sections.map(async (section) => {
|
||||||
const fields = await this.fieldService.findAll(section.id)
|
const fields = await this.fieldService.findAll(section.id)
|
||||||
@@ -63,23 +63,23 @@ export class PrintService {
|
|||||||
|
|
||||||
|
|
||||||
async remove(id: string): Promise<void> {
|
async remove(id: string): Promise<void> {
|
||||||
const print = await this.finOrFail(id);
|
const printForm = await this.finOrFail(id);
|
||||||
|
|
||||||
print.deletedAt = new Date();
|
printForm.deletedAt = new Date();
|
||||||
|
|
||||||
return await this.em.persistAndFlush(print);
|
return await this.em.persistAndFlush(printForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============== Helpers ==========
|
// ============== Helpers ==========
|
||||||
async finOrFail(printId: string) {
|
async finOrFail(printFormId: string) {
|
||||||
const printSection = await this.printRepository.findOne({ id: printId })
|
const printFormSection = await this.printFormRepository.findOne({ id: printFormId })
|
||||||
|
|
||||||
if (!printSection) {
|
if (!printFormSection) {
|
||||||
throw new NotFoundException('printSection not found');
|
throw new NotFoundException('printFormSection not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return printSection
|
return printFormSection
|
||||||
}
|
}
|
||||||
|
|
||||||
async generatePdf(html: string): Promise<Buffer> {
|
async generatePdf(html: string): Promise<Buffer> {
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||||
import { Print } from '../entities/print.entity';
|
import { PrintForm } from '../entities/print-form.entity';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrintRepository extends EntityRepository<Print> {
|
export class PrintFormRepository extends EntityRepository<PrintForm> {
|
||||||
constructor(readonly em: EntityManager) {
|
constructor(readonly em: EntityManager) {
|
||||||
super(em, Print);
|
super(em, PrintForm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { Field } from "src/modules/form-builder/entities/field.entity";
|
|
||||||
import { Print } from "../entities/print.entity";
|
|
||||||
|
|
||||||
export interface PrintWithFields extends Print {
|
|
||||||
fields: Field[];
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { forwardRef, Module } from '@nestjs/common';
|
|
||||||
import { PrintService } from './provider/print.service';
|
|
||||||
import { PrintController } from './controller/print.controller';
|
|
||||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
||||||
import { Print } from './entities/print.entity';
|
|
||||||
import { PrintRepository } from './repository/print.repository';
|
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
|
||||||
import { RolesModule } from '../roles/roles.module';
|
|
||||||
import { FormBuilderModule } from '../form-builder/form-builder.module';
|
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [PrintController],
|
|
||||||
providers: [PrintService,
|
|
||||||
PrintRepository],
|
|
||||||
exports: [PrintService,
|
|
||||||
PrintRepository],
|
|
||||||
imports: [
|
|
||||||
forwardRef(()=>FormBuilderModule),
|
|
||||||
MikroOrmModule.forFeature([Print]),
|
|
||||||
RolesModule, JwtModule.register({}),
|
|
||||||
]
|
|
||||||
})
|
|
||||||
export class PrintModule { }
|
|
||||||
Reference in New Issue
Block a user