'assigned' implied a specific person always holds the item, but
createAssignment() only requires status=in_stock to hand something out --
the status value itself never guaranteed a matching Assignment row exists.
~158 of the 613 real-imported assets carry this status with no Assignment
at all (shared/unowned equipment like meeting-room gear), so "assigned"
was actively misleading for them. 'in_use' doesn't carry that implication.
DB: `ALTER TYPE "AssetItemStatus" RENAME VALUE 'assigned' TO 'in_use'`
(hand-written migration -- runs cleanly, no data migration needed, every
existing row's status just reads under the new name). Renamed across:
schema.prisma enum, src/lib/assets.ts (type union + IMPORT_STATUS_MAP,
which keeps an `assigned` key mapped to `in_use` for backward-compat with
pre-2026-08-25 exports/CSVs), src/lib/assignments.ts (the literal status
value createAssignment() sets), src/app/assets/page.tsx + api/assets/
route.ts (filter dropdown + validStatuses), src/app/maintenance-records/
page.tsx (its own copy of the status list for the "close" targetStatus
picker). maintenance-records.ts itself needed no logic change -- its
closeableTargetStatusValues was already just ["in_stock", "retired"],
"assigned" was never a valid close target, only mentioned in comments
(updated for accuracy).
Also fixes a real regression found while verifying this: tests/
assets.test.ts (a pre-existing, properly-reviewed test file, not written
this session) broke 2 commits ago when GET /api/assets's signature and
response shape changed for pagination -- it still called GET() with no
Request and expected a bare array. tsc didn't catch this until now
because this container has no dev bind mount (Dockerfile is COPY-based,
`docker exec` only reflects the last build) -- see the
ubi-dan-itam-docker-no-bind-mount memory note. Added a getRequest()
helper and updated assertions to the {items, total} shape.
Verified by actually rebuilding and running the full suite fresh (not
just tsc/lint smoke checks): 369/369 tests pass, including
assignments.test.ts and maintenance-records.test.ts, which this rename
touches directly. tsc/lint clean against the rebuilt image. Migration
applied to the real DB, data verified intact (542 in_use + 71 in_stock =
613, matches pre-rename counts exactly).
This commit is contained in:
+6
-5
@@ -4,7 +4,7 @@ import { prisma } from "./prisma";
|
||||
import { splitCsvLine, splitCsvLines, normalizeHeader, csvField } from "./csv";
|
||||
import { createOrGetArea } from "./areas";
|
||||
|
||||
export type AssetItemStatus = "in_stock" | "assigned" | "repair" | "retired" | "lost";
|
||||
export type AssetItemStatus = "in_stock" | "in_use" | "repair" | "retired" | "lost";
|
||||
|
||||
export interface AssetItemRecord {
|
||||
id: string;
|
||||
@@ -526,14 +526,15 @@ export interface ImportAssetItemsResult {
|
||||
// Maps free-text status values from a real export (e.g. ServiceNow's
|
||||
// "State" column: "In use"/"In stock") onto this app's AssetItemStatus
|
||||
// enum -- plus this app's own enum values, in case a re-exported CSV
|
||||
// round-trips one back in. "In use" -> "assigned" is a simplification: it
|
||||
// round-trips one back in. "In use" -> "in_use" is a simplification: it
|
||||
// doesn't require (or create) a matching Assignment row, just reflects
|
||||
// that the item is deployed rather than sitting in stock -- see
|
||||
// docs/asset-license-management.md's 2026-08-24 section for why linking
|
||||
// actual Employee assignments is explicitly out of scope for this import.
|
||||
const IMPORT_STATUS_MAP: Record<string, AssetItemStatus> = {
|
||||
"in use": "assigned",
|
||||
assigned: "assigned",
|
||||
"in use": "in_use",
|
||||
in_use: "in_use",
|
||||
assigned: "in_use", // backward-compat: pre-2026-08-25 exports/CSVs said "assigned"
|
||||
"in stock": "in_stock",
|
||||
in_stock: "in_stock",
|
||||
repair: "repair",
|
||||
@@ -742,7 +743,7 @@ export async function importAssetItems(rows: ImportAssetItemRow[]): Promise<Impo
|
||||
* parseAssetItemsCsv() reads -- so "export, edit in Excel, re-import" is a
|
||||
* real round trip, not just a one-way dump. `status` round-trips too as of
|
||||
* 2026-08-24 (see IMPORT_STATUS_MAP above) -- exported as this app's own
|
||||
* enum text ("in_stock"/"assigned"/...), which IMPORT_STATUS_MAP also
|
||||
* enum text ("in_stock"/"in_use"/...), which IMPORT_STATUS_MAP also
|
||||
* recognizes on the way back in.
|
||||
*/
|
||||
export async function exportAssetItemsCsv(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user