fix(supply-chain): include finished product delivery service

This commit is contained in:
WuYongJie 2026-08-29 15:35:59 +08:00
parent 3409a9db50
commit e1b7683bfd

View File

@ -0,0 +1,41 @@
import { finishedProductDeliveryInputSchema, type FinishedProductDeliveryInput } from '@/lib/finished-product-progress'
import { AppError, ErrorCode } from '@/server/core/errors'
import {
finishedProductProgressRepository,
type FinishedProductProgressRepository,
} from '@/server/repositories/finished-product-progress.repository'
function parseDeliveryInput(input: unknown): FinishedProductDeliveryInput {
const parsed = finishedProductDeliveryInputSchema.safeParse(input)
if (parsed.success) return parsed.data
throw new AppError(ErrorCode.VALIDATION_FAILED, parsed.error.issues[0]?.message ?? '送货记录格式不正确')
}
export class FinishedProductDeliveryService {
constructor(private readonly repository: FinishedProductProgressRepository = finishedProductProgressRepository) {}
parse(input: unknown) {
return parseDeliveryInput(input)
}
async list(itemId: string) {
return this.repository.listDeliveryRecords(itemId)
}
async create(itemId: string, input: unknown, actor: { id: string; name: string }) {
return this.repository.createDeliveryRecord(itemId, parseDeliveryInput(input), actor)
}
async update(deliveryId: string, input: unknown, actor: { id: string; name: string }) {
const current = await this.repository.findDeliveryRecordById(deliveryId)
if (!current) return null
if (current.status === 'VOID') throw new AppError(ErrorCode.VALIDATION_FAILED, '已作废的送货记录不能修改')
return this.repository.updateDeliveryRecord(current.id, parseDeliveryInput(input), actor)
}
async void(deliveryId: string, actor: { id: string; name: string }) {
return this.repository.voidDeliveryRecord(deliveryId, actor)
}
}
export const finishedProductDeliveryService = new FinishedProductDeliveryService()