@open-mercato/core 0.10.1-develop.7708.1.5a5c248637 → 0.10.1-develop.7714.1.9dbb8200d8
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 +2 -2
- package/dist/generated/entities/asn/index.js +19 -0
- package/dist/generated/entities/asn/index.js.map +7 -0
- package/dist/generated/entities/putaway_task/index.js +25 -0
- package/dist/generated/entities/putaway_task/index.js.map +7 -0
- package/dist/generated/entities/receiving_line/index.js +21 -0
- package/dist/generated/entities/receiving_line/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +4 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +34 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/communication_channels/lib/sanitize-channel-html.js +22 -3
- package/dist/modules/communication_channels/lib/sanitize-channel-html.js.map +2 -2
- package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js +40 -11
- package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js.map +2 -2
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js +13 -2
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js.map +2 -2
- package/dist/modules/wms/acl.js +2 -0
- package/dist/modules/wms/acl.js.map +2 -2
- package/dist/modules/wms/api/asns/[id]/complete/route.js +61 -0
- package/dist/modules/wms/api/asns/[id]/complete/route.js.map +7 -0
- package/dist/modules/wms/api/asns/[id]/receive/route.js +68 -0
- package/dist/modules/wms/api/asns/[id]/receive/route.js.map +7 -0
- package/dist/modules/wms/api/asns/route.js +197 -0
- package/dist/modules/wms/api/asns/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/helpers.js +42 -34
- package/dist/modules/wms/api/inventory/helpers.js.map +2 -2
- package/dist/modules/wms/api/inventory/receive/route.js +1 -1
- package/dist/modules/wms/api/inventory/receive/route.js.map +2 -2
- package/dist/modules/wms/api/listEnrichers.js +23 -0
- package/dist/modules/wms/api/listEnrichers.js.map +2 -2
- package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js +65 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js +51 -0
- package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/route.js +192 -0
- package/dist/modules/wms/api/putaway-tasks/route.js.map +7 -0
- package/dist/modules/wms/api/receiving-lines/route.js +180 -0
- package/dist/modules/wms/api/receiving-lines/route.js.map +7 -0
- package/dist/modules/wms/api/scan/putaway/route.js +104 -0
- package/dist/modules/wms/api/scan/putaway/route.js.map +7 -0
- package/dist/modules/wms/api/scan/receive/route.js +109 -0
- package/dist/modules/wms/api/scan/receive/route.js.map +7 -0
- package/dist/modules/wms/api/scan/resolve-location/route.js +89 -0
- package/dist/modules/wms/api/scan/resolve-location/route.js.map +7 -0
- package/dist/modules/wms/api/scan/resolve-lot/route.js +89 -0
- package/dist/modules/wms/api/scan/resolve-lot/route.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.js +9 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/page.js +9 -0
- package/dist/modules/wms/backend/wms/asns/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/asns/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/putaway/page.js +9 -0
- package/dist/modules/wms/backend/wms/putaway/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/putaway/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/putaway/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/receiving/page.js +8 -0
- package/dist/modules/wms/backend/wms/receiving/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/receiving/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/receiving/page.meta.js.map +7 -0
- package/dist/modules/wms/ce.js +27 -0
- package/dist/modules/wms/ce.js.map +2 -2
- package/dist/modules/wms/commands/asn.js +1746 -0
- package/dist/modules/wms/commands/asn.js.map +7 -0
- package/dist/modules/wms/commands/index.js +2 -0
- package/dist/modules/wms/commands/index.js.map +2 -2
- package/dist/modules/wms/commands/inventory-actions.js +347 -243
- package/dist/modules/wms/commands/inventory-actions.js.map +2 -2
- package/dist/modules/wms/commands/putaway.js +945 -0
- package/dist/modules/wms/commands/putaway.js.map +7 -0
- package/dist/modules/wms/commands/shared.js +51 -0
- package/dist/modules/wms/commands/shared.js.map +2 -2
- package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js +278 -0
- package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js +327 -0
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/CreateAsnDialog.js +404 -0
- package/dist/modules/wms/components/backend/CreateAsnDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js +16 -3
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +2 -2
- package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js +476 -0
- package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +2 -2
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsAsnDetailPage.js +524 -0
- package/dist/modules/wms/components/backend/WmsAsnDetailPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsAsnsListPage.js +339 -0
- package/dist/modules/wms/components/backend/WmsAsnsListPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +14 -10
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js +598 -0
- package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js +32 -0
- package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js.map +7 -0
- package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js +36 -0
- package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js.map +7 -0
- package/dist/modules/wms/components/backend/inboundStatusUi.js +106 -0
- package/dist/modules/wms/components/backend/inboundStatusUi.js.map +7 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +17 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +2 -2
- package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js +14 -0
- package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js.map +7 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +4 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +2 -2
- package/dist/modules/wms/data/enrichers.js +117 -12
- package/dist/modules/wms/data/enrichers.js.map +2 -2
- package/dist/modules/wms/data/entities.js +150 -1
- package/dist/modules/wms/data/entities.js.map +2 -2
- package/dist/modules/wms/data/validators.js +214 -0
- package/dist/modules/wms/data/validators.js.map +2 -2
- package/dist/modules/wms/events.js +12 -1
- package/dist/modules/wms/events.js.map +2 -2
- package/dist/modules/wms/extension-points.js +3 -1
- package/dist/modules/wms/extension-points.js.map +2 -2
- package/dist/modules/wms/lib/asnReceiving.js +124 -0
- package/dist/modules/wms/lib/asnReceiving.js.map +7 -0
- package/dist/modules/wms/lib/asnVendor.js +52 -0
- package/dist/modules/wms/lib/asnVendor.js.map +7 -0
- package/dist/modules/wms/lib/flashMutationError.js +4 -0
- package/dist/modules/wms/lib/flashMutationError.js.map +2 -2
- package/dist/modules/wms/lib/inventoryDisplayUi.js +24 -0
- package/dist/modules/wms/lib/inventoryDisplayUi.js.map +2 -2
- package/dist/modules/wms/lib/inventoryPolicy.js +17 -0
- package/dist/modules/wms/lib/inventoryPolicy.js.map +2 -2
- package/dist/modules/wms/lib/loadOperationalDashboard.js +67 -1
- package/dist/modules/wms/lib/loadOperationalDashboard.js.map +2 -2
- package/dist/modules/wms/lib/putaway.js +141 -0
- package/dist/modules/wms/lib/putaway.js.map +7 -0
- package/dist/modules/wms/lib/roleFeatures.js +3 -1
- package/dist/modules/wms/lib/roleFeatures.js.map +2 -2
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +99 -1
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +2 -2
- package/dist/modules/wms/lib/scanResolve.js +147 -0
- package/dist/modules/wms/lib/scanResolve.js.map +7 -0
- package/dist/modules/wms/lib/wmsIntegrationToggles.js +1 -1
- package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +2 -2
- package/dist/modules/wms/migrations/Migration20260812120000.js +43 -0
- package/dist/modules/wms/migrations/Migration20260812120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260812130000.js +30 -0
- package/dist/modules/wms/migrations/Migration20260812130000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260822120000.js +17 -0
- package/dist/modules/wms/migrations/Migration20260822120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260822130000.js +17 -0
- package/dist/modules/wms/migrations/Migration20260822130000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20261029120000.js +13 -0
- package/dist/modules/wms/migrations/Migration20261029120000.js.map +7 -0
- package/dist/modules/wms/search.js +85 -0
- package/dist/modules/wms/search.js.map +2 -2
- package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js +14 -0
- package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js.map +7 -0
- package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js +12 -0
- package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js.map +7 -0
- package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js +163 -0
- package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js.map +7 -0
- package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js +14 -0
- package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js.map +7 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +37 -8
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +78 -51
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/activity-registry.js.map +2 -2
- package/dist/modules/workflows/lib/activity-types.js +4 -1
- package/dist/modules/workflows/lib/activity-types.js.map +2 -2
- package/dist/modules/workflows/lib/activity-worker-handler.js +1 -1
- package/dist/modules/workflows/lib/activity-worker-handler.js.map +2 -2
- package/generated/entities/asn/index.ts +8 -0
- package/generated/entities/putaway_task/index.ts +11 -0
- package/generated/entities/receiving_line/index.ts +9 -0
- package/generated/entities.ids.generated.ts +4 -1
- package/generated/entity-fields-registry.ts +34 -0
- package/package.json +7 -7
- package/src/modules/auth/i18n/de.json +2 -0
- package/src/modules/auth/i18n/en.json +2 -0
- package/src/modules/auth/i18n/es.json +2 -0
- package/src/modules/auth/i18n/ko.json +2 -0
- package/src/modules/auth/i18n/pl.json +2 -0
- package/src/modules/communication_channels/i18n/de.json +2 -0
- package/src/modules/communication_channels/i18n/en.json +2 -0
- package/src/modules/communication_channels/i18n/es.json +2 -0
- package/src/modules/communication_channels/i18n/ko.json +2 -0
- package/src/modules/communication_channels/i18n/pl.json +2 -0
- package/src/modules/communication_channels/lib/sanitize-channel-html.ts +23 -3
- package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.tsx +44 -12
- package/src/modules/customers/components/calendar/CalendarEventEditor.tsx +16 -2
- package/src/modules/wms/acl.ts +2 -0
- package/src/modules/wms/api/asns/[id]/complete/route.ts +62 -0
- package/src/modules/wms/api/asns/[id]/receive/route.ts +74 -0
- package/src/modules/wms/api/asns/route.ts +200 -0
- package/src/modules/wms/api/inventory/helpers.ts +57 -34
- package/src/modules/wms/api/inventory/receive/route.ts +2 -1
- package/src/modules/wms/api/listEnrichers.ts +38 -0
- package/src/modules/wms/api/putaway-tasks/[id]/assign/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/[id]/cancel/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/[id]/complete/route.ts +66 -0
- package/src/modules/wms/api/putaway-tasks/[id]/start/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/create-from-balance/route.ts +50 -0
- package/src/modules/wms/api/putaway-tasks/route.ts +199 -0
- package/src/modules/wms/api/receiving-lines/route.ts +180 -0
- package/src/modules/wms/api/scan/putaway/route.ts +108 -0
- package/src/modules/wms/api/scan/receive/route.ts +118 -0
- package/src/modules/wms/api/scan/resolve-location/route.ts +92 -0
- package/src/modules/wms/api/scan/resolve-lot/route.ts +92 -0
- package/src/modules/wms/backend/wms/asns/[id]/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/asns/[id]/page.tsx +5 -0
- package/src/modules/wms/backend/wms/asns/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/asns/page.tsx +5 -0
- package/src/modules/wms/backend/wms/putaway/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/putaway/page.tsx +5 -0
- package/src/modules/wms/backend/wms/receiving/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/receiving/page.tsx +5 -0
- package/src/modules/wms/ce.ts +27 -0
- package/src/modules/wms/commands/asn.ts +2122 -0
- package/src/modules/wms/commands/index.ts +2 -0
- package/src/modules/wms/commands/inventory-actions.ts +413 -243
- package/src/modules/wms/commands/putaway.ts +1169 -0
- package/src/modules/wms/commands/shared.ts +51 -0
- package/src/modules/wms/components/backend/AssignPutawayTaskDialog.tsx +328 -0
- package/src/modules/wms/components/backend/CompletePutawayTaskDialog.tsx +366 -0
- package/src/modules/wms/components/backend/CreateAsnDialog.tsx +427 -0
- package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +20 -2
- package/src/modules/wms/components/backend/ReceiveAsnLineDialog.tsx +535 -0
- package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +2 -2
- package/src/modules/wms/components/backend/WmsAsnDetailPage.tsx +647 -0
- package/src/modules/wms/components/backend/WmsAsnsListPage.tsx +407 -0
- package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +12 -8
- package/src/modules/wms/components/backend/WmsPutawayQueuePage.tsx +677 -0
- package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/asnCompleteOptimisticLock.ts +52 -0
- package/src/modules/wms/components/backend/asnReceivingLinesLoader.ts +83 -0
- package/src/modules/wms/components/backend/inboundStatusUi.ts +154 -0
- package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +20 -0
- package/src/modules/wms/components/backend/putawayQueueOptimisticLock.ts +20 -0
- package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +4 -0
- package/src/modules/wms/data/enrichers.ts +175 -13
- package/src/modules/wms/data/entities.ts +155 -0
- package/src/modules/wms/data/validators.ts +256 -0
- package/src/modules/wms/events.ts +11 -0
- package/src/modules/wms/extension-points.ts +2 -0
- package/src/modules/wms/i18n/de.json +205 -3
- package/src/modules/wms/i18n/en.json +205 -3
- package/src/modules/wms/i18n/es.json +205 -3
- package/src/modules/wms/i18n/ko.json +205 -3
- package/src/modules/wms/i18n/pl.json +205 -3
- package/src/modules/wms/lib/asnReceiving.ts +226 -0
- package/src/modules/wms/lib/asnVendor.ts +80 -0
- package/src/modules/wms/lib/flashMutationError.ts +4 -0
- package/src/modules/wms/lib/inventoryDisplayUi.ts +46 -0
- package/src/modules/wms/lib/inventoryPolicy.ts +31 -1
- package/src/modules/wms/lib/loadOperationalDashboard.ts +89 -1
- package/src/modules/wms/lib/putaway.ts +210 -0
- package/src/modules/wms/lib/roleFeatures.ts +2 -0
- package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +150 -1
- package/src/modules/wms/lib/scanResolve.ts +185 -0
- package/src/modules/wms/lib/wmsIntegrationToggles.ts +2 -1
- package/src/modules/wms/migrations/.snapshot-open-mercato.json +1000 -0
- package/src/modules/wms/migrations/Migration20260812120000.ts +43 -0
- package/src/modules/wms/migrations/Migration20260812130000.ts +28 -0
- package/src/modules/wms/migrations/Migration20260822120000.ts +17 -0
- package/src/modules/wms/migrations/Migration20260822130000.ts +15 -0
- package/src/modules/wms/migrations/Migration20261029120000.ts +11 -0
- package/src/modules/wms/search.ts +95 -0
- package/src/modules/wms/subscribers/asn-line-received-reevaluate-reservations.ts +21 -0
- package/src/modules/wms/subscribers/invalidate-enricher-cache-asn.ts +12 -0
- package/src/modules/wms/subscribers/procurement-goods-receipt-created.ts +238 -0
- package/src/modules/wms/subscribers/putaway-completed-reevaluate-reservations.ts +21 -0
- package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +63 -13
- package/src/modules/workflows/lib/activity-executor.ts +89 -58
- package/src/modules/workflows/lib/activity-registry.ts +1 -0
- package/src/modules/workflows/lib/activity-types.ts +4 -1
- package/src/modules/workflows/lib/activity-worker-handler.ts +2 -2
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
|
|
3
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
4
|
+
import { parseScopedCommandInput, resolveCrudRecordId } from '@open-mercato/shared/lib/api/scoped'
|
|
5
|
+
import { E } from '#generated/entities.ids.generated'
|
|
6
|
+
import { ReceivingLine } from '../../data/entities'
|
|
7
|
+
import { receivingLineCreateSchema, receivingLineUpdateSchema } from '../../data/validators'
|
|
8
|
+
import { assertReceivingLineLifecycleFieldsForbidden } from '../../lib/asnReceiving'
|
|
9
|
+
import { createPagedListResponseSchema, createWmsCrudOpenApi, defaultOkResponseSchema } from '../openapi'
|
|
10
|
+
|
|
11
|
+
const F = {
|
|
12
|
+
id: 'id',
|
|
13
|
+
organization_id: 'organization_id',
|
|
14
|
+
tenant_id: 'tenant_id',
|
|
15
|
+
asn_id: 'asn_id',
|
|
16
|
+
catalog_variant_id: 'catalog_variant_id',
|
|
17
|
+
expected_qty: 'expected_qty',
|
|
18
|
+
received_qty: 'received_qty',
|
|
19
|
+
lot_number: 'lot_number',
|
|
20
|
+
serial_numbers: 'serial_numbers',
|
|
21
|
+
qc_status: 'qc_status',
|
|
22
|
+
target_staging_location_id: 'target_staging_location_id',
|
|
23
|
+
rejection_reason: 'rejection_reason',
|
|
24
|
+
created_at: 'created_at',
|
|
25
|
+
updated_at: 'updated_at',
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
const routeMetadata = {
|
|
29
|
+
GET: { requireAuth: true, requireFeatures: ['wms.view'] },
|
|
30
|
+
POST: { requireAuth: true, requireFeatures: ['wms.manage_asn'] },
|
|
31
|
+
PUT: { requireAuth: true, requireFeatures: ['wms.manage_asn'] },
|
|
32
|
+
DELETE: { requireAuth: true, requireFeatures: ['wms.manage_asn'] },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const metadata = routeMetadata
|
|
36
|
+
|
|
37
|
+
const rawBodySchema = z.object({}).passthrough()
|
|
38
|
+
|
|
39
|
+
const listSchema = z.object({
|
|
40
|
+
page: z.coerce.number().min(1).default(1),
|
|
41
|
+
pageSize: z.coerce.number().min(1).max(100).default(25),
|
|
42
|
+
ids: z.string().optional(),
|
|
43
|
+
asnId: z.string().uuid().optional(),
|
|
44
|
+
catalogVariantId: z.string().uuid().optional(),
|
|
45
|
+
qcStatus: z.enum(['pending', 'passed', 'failed']).optional(),
|
|
46
|
+
sortField: z.string().optional(),
|
|
47
|
+
sortDir: z.enum(['asc', 'desc']).optional(),
|
|
48
|
+
}).passthrough()
|
|
49
|
+
|
|
50
|
+
const crud = makeCrudRoute({
|
|
51
|
+
metadata: routeMetadata,
|
|
52
|
+
orm: {
|
|
53
|
+
entity: ReceivingLine,
|
|
54
|
+
idField: 'id',
|
|
55
|
+
orgField: 'organizationId',
|
|
56
|
+
tenantField: 'tenantId',
|
|
57
|
+
softDeleteField: 'deletedAt',
|
|
58
|
+
},
|
|
59
|
+
indexer: { entityType: E.wms.receiving_line },
|
|
60
|
+
list: {
|
|
61
|
+
schema: listSchema,
|
|
62
|
+
disableListCache: true,
|
|
63
|
+
entityId: E.wms.receiving_line,
|
|
64
|
+
fields: [
|
|
65
|
+
F.id,
|
|
66
|
+
F.organization_id,
|
|
67
|
+
F.tenant_id,
|
|
68
|
+
F.asn_id,
|
|
69
|
+
F.catalog_variant_id,
|
|
70
|
+
F.expected_qty,
|
|
71
|
+
F.received_qty,
|
|
72
|
+
F.lot_number,
|
|
73
|
+
F.serial_numbers,
|
|
74
|
+
F.qc_status,
|
|
75
|
+
F.target_staging_location_id,
|
|
76
|
+
F.rejection_reason,
|
|
77
|
+
F.created_at,
|
|
78
|
+
F.updated_at,
|
|
79
|
+
],
|
|
80
|
+
sortFieldMap: {
|
|
81
|
+
expectedQty: F.expected_qty,
|
|
82
|
+
receivedQty: F.received_qty,
|
|
83
|
+
qcStatus: F.qc_status,
|
|
84
|
+
createdAt: F.created_at,
|
|
85
|
+
updatedAt: F.updated_at,
|
|
86
|
+
},
|
|
87
|
+
buildFilters: async (query) => {
|
|
88
|
+
const filters: Record<string, unknown> = {}
|
|
89
|
+
if (typeof query.ids === 'string' && query.ids.trim().length > 0) {
|
|
90
|
+
filters[F.id] = {
|
|
91
|
+
$in: query.ids.split(',').map((value) => value.trim()).filter((value) => value.length > 0),
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (typeof query.asnId === 'string' && query.asnId.length > 0) {
|
|
95
|
+
filters[F.asn_id] = { $eq: query.asnId }
|
|
96
|
+
}
|
|
97
|
+
if (typeof query.catalogVariantId === 'string' && query.catalogVariantId.length > 0) {
|
|
98
|
+
filters[F.catalog_variant_id] = { $eq: query.catalogVariantId }
|
|
99
|
+
}
|
|
100
|
+
if (typeof query.qcStatus === 'string' && query.qcStatus.length > 0) {
|
|
101
|
+
filters[F.qc_status] = { $eq: query.qcStatus }
|
|
102
|
+
}
|
|
103
|
+
return filters
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
actions: {
|
|
107
|
+
create: {
|
|
108
|
+
commandId: 'wms.receiving-lines.create',
|
|
109
|
+
schema: rawBodySchema,
|
|
110
|
+
mapInput: async ({ raw, ctx }) => {
|
|
111
|
+
const { translate } = await resolveTranslations()
|
|
112
|
+
return parseScopedCommandInput(receivingLineCreateSchema, raw ?? {}, ctx, translate)
|
|
113
|
+
},
|
|
114
|
+
response: ({ result }) => ({ id: result?.lineId ?? null }),
|
|
115
|
+
status: 201,
|
|
116
|
+
},
|
|
117
|
+
update: {
|
|
118
|
+
commandId: 'wms.receiving-lines.update',
|
|
119
|
+
schema: rawBodySchema,
|
|
120
|
+
mapInput: async ({ raw, ctx }) => {
|
|
121
|
+
const { translate } = await resolveTranslations()
|
|
122
|
+
assertReceivingLineLifecycleFieldsForbidden(raw)
|
|
123
|
+
return parseScopedCommandInput(receivingLineUpdateSchema, raw ?? {}, ctx, translate)
|
|
124
|
+
},
|
|
125
|
+
response: () => ({ ok: true }),
|
|
126
|
+
},
|
|
127
|
+
delete: {
|
|
128
|
+
commandId: 'wms.receiving-lines.delete',
|
|
129
|
+
schema: rawBodySchema,
|
|
130
|
+
mapInput: async ({ parsed, ctx }) => {
|
|
131
|
+
const { translate } = await resolveTranslations()
|
|
132
|
+
return { id: resolveCrudRecordId(parsed, ctx, translate) }
|
|
133
|
+
},
|
|
134
|
+
response: () => ({ ok: true }),
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export const GET = crud.GET
|
|
140
|
+
export const POST = crud.POST
|
|
141
|
+
export const PUT = crud.PUT
|
|
142
|
+
export const DELETE = crud.DELETE
|
|
143
|
+
|
|
144
|
+
const receivingLineListItemSchema = z.object({
|
|
145
|
+
id: z.string().uuid().nullable().optional(),
|
|
146
|
+
organization_id: z.string().uuid().nullable().optional(),
|
|
147
|
+
tenant_id: z.string().uuid().nullable().optional(),
|
|
148
|
+
asn_id: z.string().uuid().nullable().optional(),
|
|
149
|
+
catalog_variant_id: z.string().uuid().nullable().optional(),
|
|
150
|
+
expected_qty: z.union([z.string(), z.number()]).nullable().optional(),
|
|
151
|
+
received_qty: z.union([z.string(), z.number()]).nullable().optional(),
|
|
152
|
+
lot_number: z.string().nullable().optional(),
|
|
153
|
+
serial_numbers: z.array(z.string()).nullable().optional(),
|
|
154
|
+
qc_status: z.string().nullable().optional(),
|
|
155
|
+
target_staging_location_id: z.string().uuid().nullable().optional(),
|
|
156
|
+
rejection_reason: z.string().nullable().optional(),
|
|
157
|
+
created_at: z.string().nullable().optional(),
|
|
158
|
+
updated_at: z.string().nullable().optional(),
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
export const openApi = createWmsCrudOpenApi({
|
|
162
|
+
resourceName: 'ReceivingLine',
|
|
163
|
+
pluralName: 'Receiving lines',
|
|
164
|
+
querySchema: listSchema,
|
|
165
|
+
listResponseSchema: createPagedListResponseSchema(receivingLineListItemSchema),
|
|
166
|
+
create: {
|
|
167
|
+
schema: receivingLineCreateSchema,
|
|
168
|
+
description: 'Creates a receiving line against an ASN.',
|
|
169
|
+
},
|
|
170
|
+
update: {
|
|
171
|
+
schema: receivingLineUpdateSchema,
|
|
172
|
+
responseSchema: defaultOkResponseSchema,
|
|
173
|
+
description: 'Updates a receiving line by id.',
|
|
174
|
+
},
|
|
175
|
+
del: {
|
|
176
|
+
schema: z.object({ id: z.string().uuid() }),
|
|
177
|
+
responseSchema: defaultOkResponseSchema,
|
|
178
|
+
description: 'Soft-deletes a receiving line by id.',
|
|
179
|
+
},
|
|
180
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
7
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
8
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
9
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
10
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
11
|
+
import { putawayTaskCompleteSchema, scanPutawaySchema } from '../../../data/validators'
|
|
12
|
+
import { resolveScanPutawayCommandInput } from '../../../lib/scanResolve'
|
|
13
|
+
import { executeWmsCustomPostRoute } from '../../inventory/helpers'
|
|
14
|
+
|
|
15
|
+
const logger = createLogger('wms')
|
|
16
|
+
|
|
17
|
+
export const metadata = {
|
|
18
|
+
// Same floor ACL as putaway-tasks/:id/complete (command enforces manage vs assignee).
|
|
19
|
+
POST: { requireAuth: true, requireFeatures: ['wms.adjust_inventory'] },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const successSchema = z.object({
|
|
23
|
+
ok: z.literal(true),
|
|
24
|
+
movementId: z.string().uuid(),
|
|
25
|
+
})
|
|
26
|
+
const errorSchema = z.object({ error: z.string() })
|
|
27
|
+
|
|
28
|
+
export async function POST(request: Request) {
|
|
29
|
+
try {
|
|
30
|
+
const container = await createRequestContainer()
|
|
31
|
+
const auth = await getAuthFromRequest(request)
|
|
32
|
+
if (!auth?.tenantId) {
|
|
33
|
+
throw new CrudHttpError(401, { error: 'Unauthorized' })
|
|
34
|
+
}
|
|
35
|
+
const organizationScope = await resolveOrganizationScopeForRequest({
|
|
36
|
+
container,
|
|
37
|
+
auth,
|
|
38
|
+
request,
|
|
39
|
+
})
|
|
40
|
+
const organizationId = organizationScope?.selectedId ?? auth.orgId ?? null
|
|
41
|
+
if (!organizationId) {
|
|
42
|
+
throw new CrudHttpError(400, { error: 'organization_scope_required' })
|
|
43
|
+
}
|
|
44
|
+
const body = await readJsonSafe<Record<string, unknown>>(request, {})
|
|
45
|
+
const parsed = scanPutawaySchema.parse(body)
|
|
46
|
+
if (parsed.tenantId !== auth.tenantId && !auth.isSuperAdmin) {
|
|
47
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
48
|
+
}
|
|
49
|
+
// Scope organization from auth/session — never trust body organizationId for
|
|
50
|
+
// task/location resolve (same contract as scan/receive and resolve-location/lot).
|
|
51
|
+
const scoped = {
|
|
52
|
+
...parsed,
|
|
53
|
+
tenantId: auth.tenantId,
|
|
54
|
+
organizationId,
|
|
55
|
+
}
|
|
56
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
57
|
+
const commandInput = await resolveScanPutawayCommandInput(em, scoped)
|
|
58
|
+
const scopedRequest = new Request(request.url, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: request.headers,
|
|
61
|
+
body: JSON.stringify(commandInput),
|
|
62
|
+
})
|
|
63
|
+
return executeWmsCustomPostRoute({
|
|
64
|
+
request: scopedRequest,
|
|
65
|
+
routePath: 'wms/scan/putaway',
|
|
66
|
+
inputSchema: putawayTaskCompleteSchema,
|
|
67
|
+
commandId: 'wms.putaway-tasks.complete',
|
|
68
|
+
describeResource: (input) => ({
|
|
69
|
+
resourceKind: 'wms.putawayTask',
|
|
70
|
+
resourceId: input.id,
|
|
71
|
+
}),
|
|
72
|
+
mapSuccess: (result: { movementId: string }) => ({
|
|
73
|
+
ok: true,
|
|
74
|
+
movementId: result.movementId,
|
|
75
|
+
}),
|
|
76
|
+
})
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof CrudHttpError) {
|
|
79
|
+
return NextResponse.json(error.body, { status: error.status })
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof z.ZodError) {
|
|
82
|
+
return NextResponse.json({ error: 'Validation failed', details: error.issues }, { status: 400 })
|
|
83
|
+
}
|
|
84
|
+
logger.error('scan putaway failed', { err: error })
|
|
85
|
+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const openApi: OpenApiRouteDoc = {
|
|
90
|
+
tag: 'WMS',
|
|
91
|
+
summary: 'Scan-assisted putaway complete',
|
|
92
|
+
methods: {
|
|
93
|
+
POST: {
|
|
94
|
+
summary: 'Complete putaway from scanned target location code',
|
|
95
|
+
description:
|
|
96
|
+
'Resolves the scanned target location code, then executes the same command path as POST /api/wms/putaway-tasks/:id/complete. Organization is taken from the authenticated session scope, not the request body. Requires `wms.adjust_inventory`; managers with `wms.manage_putaway` may complete any task, operators only when assigned.',
|
|
97
|
+
requestBody: { contentType: 'application/json', schema: scanPutawaySchema },
|
|
98
|
+
responses: [{ status: 200, description: 'Putaway completed', schema: successSchema }],
|
|
99
|
+
errors: [
|
|
100
|
+
{ status: 400, description: 'Validation failed', schema: errorSchema },
|
|
101
|
+
{ status: 401, description: 'Unauthorized', schema: errorSchema },
|
|
102
|
+
{ status: 404, description: 'Task or location not found', schema: errorSchema },
|
|
103
|
+
{ status: 409, description: 'Invalid putaway state or insufficient stock', schema: errorSchema },
|
|
104
|
+
{ status: 422, description: 'Invalid or inactive location', schema: errorSchema },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
7
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
8
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
9
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
10
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
11
|
+
import { asnReceiveLineSchema, scanReceiveSchema } from '../../../data/validators'
|
|
12
|
+
import { resolveScanReceiveCommandInput } from '../../../lib/scanResolve'
|
|
13
|
+
import { executeWmsCustomPostRoute } from '../../inventory/helpers'
|
|
14
|
+
|
|
15
|
+
const logger = createLogger('wms')
|
|
16
|
+
|
|
17
|
+
export const metadata = {
|
|
18
|
+
POST: { requireAuth: true, requireFeatures: ['wms.receive_inventory'] },
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const successSchema = z.object({
|
|
22
|
+
ok: z.literal(true),
|
|
23
|
+
movementIds: z.array(z.string().uuid()),
|
|
24
|
+
putawayTaskIds: z.array(z.string().uuid()),
|
|
25
|
+
receivedQty: z.number().optional(),
|
|
26
|
+
asnUpdatedAt: z.string().datetime().optional(),
|
|
27
|
+
})
|
|
28
|
+
const errorSchema = z.object({ error: z.string() })
|
|
29
|
+
|
|
30
|
+
export async function POST(request: Request) {
|
|
31
|
+
try {
|
|
32
|
+
const container = await createRequestContainer()
|
|
33
|
+
const auth = await getAuthFromRequest(request)
|
|
34
|
+
if (!auth?.tenantId) {
|
|
35
|
+
throw new CrudHttpError(401, { error: 'Unauthorized' })
|
|
36
|
+
}
|
|
37
|
+
const organizationScope = await resolveOrganizationScopeForRequest({
|
|
38
|
+
container,
|
|
39
|
+
auth,
|
|
40
|
+
request,
|
|
41
|
+
})
|
|
42
|
+
const organizationId = organizationScope?.selectedId ?? auth.orgId ?? null
|
|
43
|
+
if (!organizationId) {
|
|
44
|
+
throw new CrudHttpError(400, { error: 'organization_scope_required' })
|
|
45
|
+
}
|
|
46
|
+
const body = await readJsonSafe<Record<string, unknown>>(request, {})
|
|
47
|
+
const parsed = scanReceiveSchema.parse(body)
|
|
48
|
+
if (parsed.tenantId !== auth.tenantId && !auth.isSuperAdmin) {
|
|
49
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
50
|
+
}
|
|
51
|
+
// Scope organization from auth/session — never trust body organizationId for
|
|
52
|
+
// ASN/location resolve (same contract as resolve-location / resolve-lot).
|
|
53
|
+
const scoped = {
|
|
54
|
+
...parsed,
|
|
55
|
+
tenantId: auth.tenantId,
|
|
56
|
+
organizationId,
|
|
57
|
+
}
|
|
58
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
59
|
+
const commandInput = await resolveScanReceiveCommandInput(em, scoped)
|
|
60
|
+
const scopedRequest = new Request(request.url, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: request.headers,
|
|
63
|
+
body: JSON.stringify(commandInput),
|
|
64
|
+
})
|
|
65
|
+
return executeWmsCustomPostRoute({
|
|
66
|
+
request: scopedRequest,
|
|
67
|
+
routePath: 'wms/scan/receive',
|
|
68
|
+
inputSchema: asnReceiveLineSchema,
|
|
69
|
+
commandId: 'wms.asns.receive-line',
|
|
70
|
+
describeResource: (input) => ({
|
|
71
|
+
resourceKind: 'wms.asn',
|
|
72
|
+
resourceId: input.asnId,
|
|
73
|
+
}),
|
|
74
|
+
mapSuccess: (result: {
|
|
75
|
+
movementIds: string[]
|
|
76
|
+
putawayTaskIds: string[]
|
|
77
|
+
receivedQty?: number
|
|
78
|
+
asnUpdatedAt?: string
|
|
79
|
+
}) => ({
|
|
80
|
+
ok: true,
|
|
81
|
+
movementIds: result.movementIds,
|
|
82
|
+
putawayTaskIds: result.putawayTaskIds,
|
|
83
|
+
receivedQty: result.receivedQty,
|
|
84
|
+
asnUpdatedAt: result.asnUpdatedAt,
|
|
85
|
+
}),
|
|
86
|
+
})
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof CrudHttpError) {
|
|
89
|
+
return NextResponse.json(error.body, { status: error.status })
|
|
90
|
+
}
|
|
91
|
+
if (error instanceof z.ZodError) {
|
|
92
|
+
return NextResponse.json({ error: 'Validation failed', details: error.issues }, { status: 400 })
|
|
93
|
+
}
|
|
94
|
+
logger.error('scan receive failed', { err: error })
|
|
95
|
+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const openApi: OpenApiRouteDoc = {
|
|
100
|
+
tag: 'WMS',
|
|
101
|
+
summary: 'Scan-assisted ASN receive',
|
|
102
|
+
methods: {
|
|
103
|
+
POST: {
|
|
104
|
+
summary: 'Receive ASN line from scanned location/lot codes',
|
|
105
|
+
description:
|
|
106
|
+
'Resolves scanned location (and optional lot) codes, then executes the same command path as POST /api/wms/asns/:id/receive. Organization is taken from the authenticated session scope, not the request body. Both QC-pass and QC-fail require absolute targetReceivedQty for retry-safe attempts (optional idempotencyKey is an extra stabilizer only).',
|
|
107
|
+
requestBody: { contentType: 'application/json', schema: scanReceiveSchema },
|
|
108
|
+
responses: [{ status: 200, description: 'ASN line received', schema: successSchema }],
|
|
109
|
+
errors: [
|
|
110
|
+
{ status: 400, description: 'Validation failed', schema: errorSchema },
|
|
111
|
+
{ status: 401, description: 'Unauthorized', schema: errorSchema },
|
|
112
|
+
{ status: 404, description: 'ASN or location not found', schema: errorSchema },
|
|
113
|
+
{ status: 409, description: 'Invalid receipt state', schema: errorSchema },
|
|
114
|
+
{ status: 422, description: 'Tracking or QC transition invalid', schema: errorSchema },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
7
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
8
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
9
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
10
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
11
|
+
import { scanResolveLocationSchema } from '../../../data/validators'
|
|
12
|
+
import { resolveLocationByCode } from '../../../lib/scanResolve'
|
|
13
|
+
|
|
14
|
+
const logger = createLogger('wms')
|
|
15
|
+
|
|
16
|
+
export const metadata = {
|
|
17
|
+
POST: { requireAuth: true, requireFeatures: ['wms.view'] },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const successSchema = z.object({
|
|
21
|
+
ok: z.literal(true),
|
|
22
|
+
locationId: z.string().uuid(),
|
|
23
|
+
code: z.string(),
|
|
24
|
+
type: z.string(),
|
|
25
|
+
})
|
|
26
|
+
const errorSchema = z.object({ error: z.string() })
|
|
27
|
+
|
|
28
|
+
export async function POST(request: Request) {
|
|
29
|
+
try {
|
|
30
|
+
const container = await createRequestContainer()
|
|
31
|
+
const auth = await getAuthFromRequest(request)
|
|
32
|
+
if (!auth?.tenantId) {
|
|
33
|
+
throw new CrudHttpError(401, { error: 'Unauthorized' })
|
|
34
|
+
}
|
|
35
|
+
const organizationScope = await resolveOrganizationScopeForRequest({
|
|
36
|
+
container,
|
|
37
|
+
auth,
|
|
38
|
+
request,
|
|
39
|
+
})
|
|
40
|
+
const organizationId = organizationScope?.selectedId ?? auth.orgId ?? null
|
|
41
|
+
if (!organizationId) {
|
|
42
|
+
throw new CrudHttpError(400, { error: 'organization_scope_required' })
|
|
43
|
+
}
|
|
44
|
+
const body = await readJsonSafe<Record<string, unknown>>(request, {})
|
|
45
|
+
const parsed = scanResolveLocationSchema.parse(body)
|
|
46
|
+
if (parsed.tenantId !== auth.tenantId && !auth.isSuperAdmin) {
|
|
47
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
48
|
+
}
|
|
49
|
+
// Scope organization from auth/session — never trust body organizationId for cross-org reads.
|
|
50
|
+
const scoped = {
|
|
51
|
+
...parsed,
|
|
52
|
+
tenantId: auth.tenantId,
|
|
53
|
+
organizationId,
|
|
54
|
+
}
|
|
55
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
56
|
+
const resolved = await resolveLocationByCode(em, scoped)
|
|
57
|
+
return NextResponse.json({
|
|
58
|
+
ok: true as const,
|
|
59
|
+
locationId: resolved.locationId,
|
|
60
|
+
code: resolved.code,
|
|
61
|
+
type: resolved.type,
|
|
62
|
+
})
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof CrudHttpError) {
|
|
65
|
+
return NextResponse.json(error.body, { status: error.status })
|
|
66
|
+
}
|
|
67
|
+
if (error instanceof z.ZodError) {
|
|
68
|
+
return NextResponse.json({ error: 'Validation failed', details: error.issues }, { status: 400 })
|
|
69
|
+
}
|
|
70
|
+
logger.error('scan resolve-location failed', { err: error })
|
|
71
|
+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const openApi: OpenApiRouteDoc = {
|
|
76
|
+
tag: 'WMS',
|
|
77
|
+
summary: 'Resolve scanned location code',
|
|
78
|
+
methods: {
|
|
79
|
+
POST: {
|
|
80
|
+
summary: 'Resolve location by warehouse + barcode/code',
|
|
81
|
+
description:
|
|
82
|
+
'Returns the canonical location id and type for a scanned warehouse location code. Organization is taken from the authenticated session scope, not the request body.',
|
|
83
|
+
requestBody: { contentType: 'application/json', schema: scanResolveLocationSchema },
|
|
84
|
+
responses: [{ status: 200, description: 'Location resolved', schema: successSchema }],
|
|
85
|
+
errors: [
|
|
86
|
+
{ status: 400, description: 'Validation failed', schema: errorSchema },
|
|
87
|
+
{ status: 401, description: 'Unauthorized', schema: errorSchema },
|
|
88
|
+
{ status: 404, description: 'Location not found', schema: errorSchema },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
7
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
8
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
9
|
+
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
10
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
11
|
+
import { scanResolveLotSchema } from '../../../data/validators'
|
|
12
|
+
import { resolveLotByNumber } from '../../../lib/scanResolve'
|
|
13
|
+
|
|
14
|
+
const logger = createLogger('wms')
|
|
15
|
+
|
|
16
|
+
export const metadata = {
|
|
17
|
+
POST: { requireAuth: true, requireFeatures: ['wms.view'] },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const successSchema = z.object({
|
|
21
|
+
ok: z.literal(true),
|
|
22
|
+
lotId: z.string().uuid(),
|
|
23
|
+
lotNumber: z.string(),
|
|
24
|
+
expiresAt: z.string().nullable(),
|
|
25
|
+
})
|
|
26
|
+
const errorSchema = z.object({ error: z.string() })
|
|
27
|
+
|
|
28
|
+
export async function POST(request: Request) {
|
|
29
|
+
try {
|
|
30
|
+
const container = await createRequestContainer()
|
|
31
|
+
const auth = await getAuthFromRequest(request)
|
|
32
|
+
if (!auth?.tenantId) {
|
|
33
|
+
throw new CrudHttpError(401, { error: 'Unauthorized' })
|
|
34
|
+
}
|
|
35
|
+
const organizationScope = await resolveOrganizationScopeForRequest({
|
|
36
|
+
container,
|
|
37
|
+
auth,
|
|
38
|
+
request,
|
|
39
|
+
})
|
|
40
|
+
const organizationId = organizationScope?.selectedId ?? auth.orgId ?? null
|
|
41
|
+
if (!organizationId) {
|
|
42
|
+
throw new CrudHttpError(400, { error: 'organization_scope_required' })
|
|
43
|
+
}
|
|
44
|
+
const body = await readJsonSafe<Record<string, unknown>>(request, {})
|
|
45
|
+
const parsed = scanResolveLotSchema.parse(body)
|
|
46
|
+
if (parsed.tenantId !== auth.tenantId && !auth.isSuperAdmin) {
|
|
47
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
48
|
+
}
|
|
49
|
+
// Scope organization from auth/session — never trust body organizationId for cross-org reads.
|
|
50
|
+
const scoped = {
|
|
51
|
+
...parsed,
|
|
52
|
+
tenantId: auth.tenantId,
|
|
53
|
+
organizationId,
|
|
54
|
+
}
|
|
55
|
+
const em = (container.resolve('em') as EntityManager).fork()
|
|
56
|
+
const resolved = await resolveLotByNumber(em, scoped)
|
|
57
|
+
return NextResponse.json({
|
|
58
|
+
ok: true as const,
|
|
59
|
+
lotId: resolved.lotId,
|
|
60
|
+
lotNumber: resolved.lotNumber,
|
|
61
|
+
expiresAt: resolved.expiresAt,
|
|
62
|
+
})
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof CrudHttpError) {
|
|
65
|
+
return NextResponse.json(error.body, { status: error.status })
|
|
66
|
+
}
|
|
67
|
+
if (error instanceof z.ZodError) {
|
|
68
|
+
return NextResponse.json({ error: 'Validation failed', details: error.issues }, { status: 400 })
|
|
69
|
+
}
|
|
70
|
+
logger.error('scan resolve-lot failed', { err: error })
|
|
71
|
+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const openApi: OpenApiRouteDoc = {
|
|
76
|
+
tag: 'WMS',
|
|
77
|
+
summary: 'Resolve scanned lot number',
|
|
78
|
+
methods: {
|
|
79
|
+
POST: {
|
|
80
|
+
summary: 'Resolve lot by catalog variant + lot number',
|
|
81
|
+
description:
|
|
82
|
+
'Returns the canonical lot id and expiry for a scanned lot number. Organization is taken from the authenticated session scope, not the request body.',
|
|
83
|
+
requestBody: { contentType: 'application/json', schema: scanResolveLotSchema },
|
|
84
|
+
responses: [{ status: 200, description: 'Lot resolved', schema: successSchema }],
|
|
85
|
+
errors: [
|
|
86
|
+
{ status: 400, description: 'Validation failed', schema: errorSchema },
|
|
87
|
+
{ status: 401, description: 'Unauthorized', schema: errorSchema },
|
|
88
|
+
{ status: 404, description: 'Lot not found', schema: errorSchema },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['wms.view'],
|
|
4
|
+
pageTitle: 'ASN detail',
|
|
5
|
+
pageTitleKey: 'wms.backend.asns.detail.nav.title',
|
|
6
|
+
pageGroup: 'WMS',
|
|
7
|
+
pageGroupKey: 'wms.nav.group',
|
|
8
|
+
navHidden: true,
|
|
9
|
+
breadcrumb: [
|
|
10
|
+
{ label: 'WMS', labelKey: 'wms.backend.nav.title', href: '/backend/wms' },
|
|
11
|
+
{ label: 'ASNs', labelKey: 'wms.backend.asns.nav.title', href: '/backend/wms/asns' },
|
|
12
|
+
{ label: 'ASN', labelKey: 'wms.backend.asns.detail.nav.title' },
|
|
13
|
+
],
|
|
14
|
+
} as const
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['wms.view'],
|
|
4
|
+
pageTitle: 'ASNs',
|
|
5
|
+
pageTitleKey: 'wms.backend.asns.nav.title',
|
|
6
|
+
pageGroup: 'WMS',
|
|
7
|
+
pageGroupKey: 'wms.nav.group',
|
|
8
|
+
pageOrder: 90,
|
|
9
|
+
breadcrumb: [
|
|
10
|
+
{ label: 'WMS', labelKey: 'wms.backend.nav.title', href: '/backend/wms' },
|
|
11
|
+
{ label: 'ASNs', labelKey: 'wms.backend.asns.nav.title' },
|
|
12
|
+
],
|
|
13
|
+
icon: 'clipboard-list',
|
|
14
|
+
} as const
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['wms.view'],
|
|
4
|
+
pageTitle: 'Putaway',
|
|
5
|
+
pageTitleKey: 'wms.backend.putaway.nav.title',
|
|
6
|
+
pageGroup: 'WMS',
|
|
7
|
+
pageGroupKey: 'wms.nav.group',
|
|
8
|
+
pageOrder: 95,
|
|
9
|
+
breadcrumb: [
|
|
10
|
+
{ label: 'WMS', labelKey: 'wms.backend.nav.title', href: '/backend/wms' },
|
|
11
|
+
{ label: 'Putaway', labelKey: 'wms.backend.putaway.nav.title' },
|
|
12
|
+
],
|
|
13
|
+
icon: 'package',
|
|
14
|
+
} as const
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['wms.view'],
|
|
4
|
+
pageTitle: 'Receiving',
|
|
5
|
+
pageTitleKey: 'wms.backend.receiving.nav.title',
|
|
6
|
+
pageGroup: 'WMS',
|
|
7
|
+
pageGroupKey: 'wms.nav.group',
|
|
8
|
+
pageOrder: 92,
|
|
9
|
+
breadcrumb: [
|
|
10
|
+
{ label: 'WMS', labelKey: 'wms.backend.nav.title', href: '/backend/wms' },
|
|
11
|
+
{ label: 'Receiving', labelKey: 'wms.backend.receiving.nav.title' },
|
|
12
|
+
],
|
|
13
|
+
icon: 'inbox',
|
|
14
|
+
} as const
|