feat(inventory): support line-based assignments and movements
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type Assignment,
|
||||
type ItemStatus,
|
||||
type AssetStatus,
|
||||
Prisma,
|
||||
} from "@/generated/prisma/client"
|
||||
import prisma from "@/lib/prisma"
|
||||
@@ -12,6 +11,7 @@ import { AssetService } from "@/services/asset.service"
|
||||
import { AssignmentService } from "@/services/assignment.service"
|
||||
import { ItemService } from "@/services/item.service"
|
||||
import { MovementService } from "@/services/movement.service"
|
||||
import type { Assignment } from "@/types"
|
||||
|
||||
type FieldErrors = Record<string, string[]>
|
||||
|
||||
@@ -63,8 +63,8 @@ class AssetTransitionError extends Error {
|
||||
}
|
||||
|
||||
type AssetTransitionInput = {
|
||||
previousStatus: ItemStatus
|
||||
nextStatus: ItemStatus
|
||||
previousStatus: AssetStatus
|
||||
nextStatus: AssetStatus
|
||||
previousItemId: string | null
|
||||
nextItemId: string
|
||||
activeAssignment: Assignment | null
|
||||
@@ -261,7 +261,11 @@ export async function updateAssetUseCase(
|
||||
if (transition.activeAssignment && !transition.willBeAssigned) {
|
||||
const activeAssignment = transition.activeAssignment
|
||||
const assignmentWasReturned =
|
||||
await AssignmentService.markReturnedIfActive(activeAssignment.id, tx)
|
||||
await AssignmentService.markReturnedIfActive(
|
||||
activeAssignment.id,
|
||||
actorId,
|
||||
tx,
|
||||
)
|
||||
|
||||
if (!assignmentWasReturned) {
|
||||
throw new AssetTransitionError({
|
||||
|
||||
@@ -301,6 +301,7 @@ export async function returnAssignmentUseCase(
|
||||
|
||||
const assignmentWasReturned = await AssignmentService.markReturnedIfActive(
|
||||
id,
|
||||
actorId,
|
||||
tx,
|
||||
)
|
||||
|
||||
|
||||
@@ -37,6 +37,14 @@ function isUniqueConstraintError(error: unknown) {
|
||||
)
|
||||
}
|
||||
|
||||
function buildSkuFromName(name: string) {
|
||||
return name
|
||||
.trim()
|
||||
.toUpperCase()
|
||||
.replace(/[^A-Z0-9]+/g, "-")
|
||||
.replace(/^-|-$/g, "")
|
||||
}
|
||||
|
||||
export async function createItemUseCase(
|
||||
input: CreateItemUseCaseInput,
|
||||
): Promise<ItemUseCaseResult> {
|
||||
@@ -58,7 +66,9 @@ export async function createItemUseCase(
|
||||
|
||||
const item = await ItemService.create(
|
||||
{
|
||||
sku: buildSkuFromName(name),
|
||||
name,
|
||||
trackingType: "QUANTITY",
|
||||
category: { connect: { id: categoryId } },
|
||||
stock: stock || 0,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user