feat: add stock keeping units management

- Created migration to drop `type` column from `stock_keeping_units` table.
- Added `Guild` model to Prisma schema.
- Implemented `BusinessActivitiesQueryService` for querying business activities.
- Developed `GoodsSharedService` for handling goods creation and updates.
- Introduced DTOs for creating and updating stock keeping units.
- Created controller and service for managing stock keeping units.
- Implemented response DTOs for stock keeping units service.
- Established module for stock keeping units management.
This commit is contained in:
2026-05-07 20:30:24 +03:30
parent 658496320b
commit fbe7230865
77 changed files with 2065 additions and 1846 deletions
+14 -1
View File
@@ -20,7 +20,7 @@ export default {
HOUR: 'ساعت',
},
GoodPricingModel: {
STANDARD: 'استاندارد',
STANDARD: 'عمومی',
GOLD: 'طلا',
},
CustomerType: {
@@ -160,4 +160,17 @@ export default {
KARAT_21: '۲۱ عیار',
KARAT_24: '۲۴ عیار',
},
InvoiceTemplateType: {
SALE: 'فروش',
FX_SALE: 'فروش ارزی',
GOLD_JEWELRY: 'طلا و جواهر',
CONTRACT: 'پیمانکاری',
UTILITY: 'قبوض خدماتی',
AIR_TICKET: 'بلیط هواپیما',
EXPORT: 'صادرات',
BILL_OF_LADING: 'بارنامه',
PETROCHEMICAL: 'پتروشیمی',
COMMODITY_EXCHANGE: 'بورس کالا',
INSURANCE: 'بیمه',
},
}
+8 -5
View File
@@ -11,11 +11,6 @@ export enum TspProviderRequestType {
REMOVE = 'REMOVE',
}
export enum TspProviderCustomerType {
Unknown = 'Unknown',
Known = 'Known',
}
export enum SKUGuildType {
GOLD = 'GOLD',
}
@@ -27,3 +22,11 @@ export const UploadedFileTypes = {
PARTNER_LOGO: 'partner_logo',
}
export type UploadedFileTypes = (typeof UploadedFileTypes)[keyof typeof UploadedFileTypes]
export const TspProviderCustomerType = {
UNKNOWN: 'Unknown',
KNOWN: 'Known',
}
export type TspProviderCustomerType =
(typeof TspProviderCustomerType)[keyof typeof TspProviderCustomerType]
@@ -0,0 +1,51 @@
import { BusinessActivitySelect } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
@Injectable()
export class BusinessActivitiesQueryService {
constructor(private readonly prisma: PrismaService) {}
readonly baseSelect: BusinessActivitySelect = {
id: true,
name: true,
economic_code: true,
created_at: true,
partner_token: true,
fiscal_id: true,
guild: {
select: {
id: true,
code: true,
name: true,
},
},
}
findAllByConsumer(consumer_id: string, select: BusinessActivitySelect) {
return this.prisma.businessActivity.findMany({
where: { consumer_id },
select,
})
}
findOneByConsumer(
consumer_id: string,
id: string,
select: BusinessActivitySelect,
orThrow = false,
) {
if (orThrow) {
return this.prisma.businessActivity.findUniqueOrThrow({
where: { consumer_id, id },
select,
})
}
return this.prisma.businessActivity.findUnique({
where: { consumer_id, id },
select,
})
}
}
+124
View File
@@ -0,0 +1,124 @@
import { UploadedFileTypes } from '@/common/enums/enums'
import { GoodPricingModel } from '@/generated/prisma/enums'
import { GoodSelect } from '@/generated/prisma/models'
import { UploaderService } from '@/modules/uploader/uploader.service'
import { Injectable } from '@nestjs/common'
export interface CreateGoodDto {
name: string
sku_id: string
category_id: string
measure_unit_id: string
pricing_model: GoodPricingModel
description?: string
is_default_guild_good?: boolean
}
export interface UpdateGoodDto extends Partial<CreateGoodDto> {}
@Injectable()
export class GoodsSharedService {
constructor(private readonly uploaderService: UploaderService) {}
readonly defaultSelect: GoodSelect = {
id: true,
name: true,
pricing_model: true,
image_url: true,
description: true,
sku: {
select: {
id: true,
name: true,
},
},
measure_unit: {
select: {
id: true,
name: true,
},
},
category: {
select: {
id: true,
name: true,
},
},
}
async prepareCreateData(data: CreateGoodDto, file?: Express.Multer.File) {
const { category_id, measure_unit_id, sku_id, ...rest } = data
let image_url = ''
if (file) {
const uploadedUrl = await this.uploaderService.uploadFile(
file,
UploadedFileTypes.GOOD,
)
image_url = uploadedUrl || ''
}
return {
...rest,
image_url,
sku: {
connect: {
id: sku_id,
},
},
measure_unit: {
connect: {
id: measure_unit_id,
},
},
category: {
connect: {
id: category_id,
},
},
}
}
async prepareUpdateData(id: string, data: UpdateGoodDto, file?: Express.Multer.File) {
const { category_id, measure_unit_id, sku_id, ...rest } = data
let image_url = ''
if (file) {
const uploadedUrl = await this.uploaderService.uploadFile(
file,
UploadedFileTypes.GOOD,
)
image_url = uploadedUrl || ''
}
const updateData: any = {
...rest,
image_url,
}
if (sku_id) {
updateData.sku = { connect: { id: sku_id } }
}
if (measure_unit_id) {
updateData.measure_unit = { connect: { id: measure_unit_id } }
}
if (category_id) {
updateData.category = { connect: { id: category_id } }
}
return updateData
}
async handleImageUpdate(id: string, prisma: any, image_url: string) {
if (image_url) {
const prevImage = await prisma.good.findUnique({
where: { id },
select: { image_url: true },
})
if (prevImage?.image_url) {
this.uploaderService.deleteFile(prevImage.image_url, UploadedFileTypes.GOOD)
}
}
}
}
@@ -524,6 +524,6 @@ export class SharedSaleInvoiceCreateService {
posId: string,
invoiceNumber: number,
) {
return `${businessId.substring(businessId.length - 2, businessId.length)}-${complexId.substring(complexId.length - 2, complexId.length)}-${posId.substring(posId.length - 2, posId.length)}-${invoiceNumber.toString()}`
return `${businessId.substring(businessId.length - 2, businessId.length)}${complexId.substring(complexId.length - 2, complexId.length)}${posId.substring(posId.length - 2, posId.length)}${invoiceNumber.toString()}`
}
}