@open-mercato/core 0.10.1-develop.7787.1.96c7cfc66f → 0.10.1-develop.7793.1.9e0c43fdde
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js +4 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/redo/route.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/undo/route.js +3 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/undo/route.js.map +3 -3
- package/dist/modules/entities/cli.js +146 -90
- package/dist/modules/entities/cli.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +14 -1
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/warranty_claims/commands/claims.js +13 -4
- package/dist/modules/warranty_claims/commands/claims.js.map +2 -2
- package/dist/modules/warranty_claims/lib/replacementOrderUndo.js +50 -0
- package/dist/modules/warranty_claims/lib/replacementOrderUndo.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/audit_logs/api/audit-logs/actions/redo/route.ts +4 -4
- package/src/modules/audit_logs/api/audit-logs/actions/undo/route.ts +3 -6
- package/src/modules/entities/cli.ts +193 -96
- package/src/modules/sales/commands/documents.ts +15 -1
- package/src/modules/warranty_claims/commands/claims.ts +16 -3
- package/src/modules/warranty_claims/lib/replacementOrderUndo.ts +67 -0
|
@@ -9,6 +9,8 @@ import { invalidateCrudCache } from "@open-mercato/shared/lib/crud/cache";
|
|
|
9
9
|
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
10
10
|
import { findOneWithDecryption, findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
11
11
|
import { readSafeDecryptedString } from "../lib/decryptionSafety.js";
|
|
12
|
+
import { isInitialReplacementOrderApproval } from "../lib/replacementOrderUndo.js";
|
|
13
|
+
import { OPTIMISTIC_LOCK_HEADER_NAME } from "@open-mercato/shared/lib/crud/optimistic-lock-headers";
|
|
12
14
|
import { E } from "../../../generated/entities.ids.generated.js";
|
|
13
15
|
import {
|
|
14
16
|
WarrantyClaim,
|
|
@@ -2298,19 +2300,26 @@ const SALES_ORDER_LINE_KINDS = /* @__PURE__ */ new Set(["product", "service", "s
|
|
|
2298
2300
|
function readSalesOrderLineKind(value) {
|
|
2299
2301
|
return typeof value === "string" && SALES_ORDER_LINE_KINDS.has(value) ? value : null;
|
|
2300
2302
|
}
|
|
2301
|
-
async function dispatchSalesOrderDelete(ctx, scope, replacementOrderId) {
|
|
2303
|
+
async function dispatchSalesOrderDelete(ctx, scope, replacementOrderId, expectedUpdatedAt) {
|
|
2302
2304
|
const commandBus = ctx.container.resolve("commandBus");
|
|
2305
|
+
const dispatchContext = scrubbedDispatchContext(ctx);
|
|
2306
|
+
if (expectedUpdatedAt) {
|
|
2307
|
+
dispatchContext.request = new Request(ctx.request?.url ?? "http://localhost", {
|
|
2308
|
+
headers: { [OPTIMISTIC_LOCK_HEADER_NAME]: expectedUpdatedAt }
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2303
2311
|
await commandBus.execute(
|
|
2304
2312
|
"sales.orders.delete",
|
|
2305
2313
|
{
|
|
2306
2314
|
input: { id: replacementOrderId, tenantId: scope.tenantId, organizationId: scope.organizationId },
|
|
2307
|
-
ctx:
|
|
2315
|
+
ctx: dispatchContext
|
|
2308
2316
|
}
|
|
2309
2317
|
);
|
|
2310
2318
|
}
|
|
2311
2319
|
const createReplacementOrderCommand = {
|
|
2312
2320
|
id: "warranty_claims.claim.create_replacement_order",
|
|
2313
2321
|
isUndoable: true,
|
|
2322
|
+
redo: ({ input, ctx }) => createReplacementOrderCommand.execute({ ...input, updatedAt: void 0 }, ctx),
|
|
2314
2323
|
prepare: async (rawInput, ctx) => {
|
|
2315
2324
|
const input = parseCommandInput(claimCreateReplacementOrderSchema, rawInput);
|
|
2316
2325
|
const scope = resolveScope(ctx, input);
|
|
@@ -2548,10 +2557,10 @@ const createReplacementOrderCommand = {
|
|
|
2548
2557
|
}
|
|
2549
2558
|
if (currentRow) {
|
|
2550
2559
|
const currentUpdatedAt = currentRow.updated_at ? new Date(currentRow.updated_at).toISOString() : null;
|
|
2551
|
-
if (!replacementOrder.updatedAt || !currentUpdatedAt || currentUpdatedAt !== replacementOrder.updatedAt) {
|
|
2560
|
+
if (!replacementOrder.updatedAt || !currentUpdatedAt || currentUpdatedAt !== replacementOrder.updatedAt && !await isInitialReplacementOrderApproval(ctx, scope, replacementOrder.id, replacementOrder.updatedAt, currentUpdatedAt)) {
|
|
2552
2561
|
throw new CrudHttpError(409, { error: "warranty_claims.errors.replacementOrderChangedUndoAborted" });
|
|
2553
2562
|
}
|
|
2554
|
-
await dispatchSalesOrderDelete(ctx, scope, replacementOrder.id);
|
|
2563
|
+
await dispatchSalesOrderDelete(ctx, scope, replacementOrder.id, currentUpdatedAt);
|
|
2555
2564
|
} else {
|
|
2556
2565
|
replacementOrderBridgeLogger.info("warranty_claims.claim.create_replacement_order undo found replacement order already absent", {
|
|
2557
2566
|
claimId: before.id,
|