WIP: Unified Housekeeping rebuild / Gecombineerde Housekeeping-herbouw #53

Closed
Simo wants to merge 68 commits from codex/housekeeping-rebuild-stepwise into main
pull from: codex/housekeeping-rebuild-stepwise
5 changed files with 651 additions and 125 deletions
Showing only changes of commit 184052fbce - Show all commits

No files matched your search

File diff suppressed because it is too large. Load diff
+141 -118
View File
File diff suppressed because it is too large. Load diff
@@ -71,7 +71,7 @@ export function EditItemDialog({ roomId, item, open, onOpenChange }: Props) {
extraData,
};
run(() => updateRoomItem(payload), {
successMessage: "Item updated and room reloaded",
successMessage: "Item updated successfully.",
onSuccess: () => onOpenChange(false),
});
}
@@ -1,7 +1,7 @@
import "server-only";
import { randomBytes } from "node:crypto";
import { and, eq, inArray } from "drizzle-orm";
import { and, asc, eq, inArray } from "drizzle-orm";
import { z } from "zod";
import type {
HotelMutationContext,
@@ -253,7 +253,8 @@ async function executeRoomMutation(
.select()
.from(Rooms)
.where(eq(Rooms.id, value.id))
.limit(1);
.limit(1)
.for("update");
requireFound(before);
const { id, ...changes } = value;
await database.update(Rooms).set(changes).where(eq(Rooms.id, id));
@@ -268,7 +269,8 @@ async function executeRoomMutation(
.select()
.from(Rooms)
.where(eq(Rooms.id, value.id))
.limit(1);
.limit(1)
.for("update");
requireFound(before);
await database.delete(Rooms).where(eq(Rooms.id, value.id));
return { before: snapshotRow(before), after: null };
@@ -279,7 +281,8 @@ async function executeRoomMutation(
.select()
.from(Items)
.where(and(eq(Items.id, value.itemId), eq(Items.roomId, value.roomId)))
.limit(1);
.limit(1)
.for("update");
requireFound(before);
const { itemId, roomId: _roomId, ...changes } = value;
await database
@@ -297,7 +300,8 @@ async function executeRoomMutation(
.select()
.from(Items)
.where(and(eq(Items.id, value.itemId), eq(Items.roomId, value.roomId)))
.limit(1);
.limit(1)
.for("update");
requireFound(before);
await database
.delete(Items)
@@ -309,7 +313,9 @@ async function executeRoomMutation(
const before = await database
.select()
.from(Items)
.where(and(eq(Items.roomId, value.roomId), inArray(Items.id, itemIds)));
.where(and(eq(Items.roomId, value.roomId), inArray(Items.id, itemIds)))
.orderBy(asc(Items.id))
.for("update");
if (before.length !== itemIds.length) {
throw new HotelMutationFailure("NOT_FOUND", "errors.housekeeping.notFound");
}
@@ -80,6 +80,7 @@ export class HotelMutationFailure extends Error {
readonly code: HousekeepingErrorCode,
readonly messageKey: string,
readonly fieldErrors?: Readonly<Record<string, readonly string[]>>,
readonly correlationId?: string,
) {
super(messageKey);
this.name = "HotelMutationFailure";
@@ -187,12 +188,15 @@ export async function executeLegacyHotelMutation(
result.error.code,
result.error.messageKey,
result.error.fieldErrors,
result.correlationId,
);
}
if (result.completion?.external === "failed") {
throw new HotelMutationFailure(
"DEPENDENCY_UNAVAILABLE",
"errors.housekeeping.dependencyUnavailable",
undefined,
result.correlationId,
);
}
return result.data;