@open-mercato/core 0.6.7-develop.6553.1.2ec7246e04 → 0.6.7-develop.6566.1.15385fa179
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/attachments/api/partitions/route.js.map +1 -1
- package/dist/modules/attachments/lib/reconcileOrganization.js +9 -7
- package/dist/modules/attachments/lib/reconcileOrganization.js.map +2 -2
- package/dist/modules/catalog/api/products/route.js.map +1 -1
- package/dist/modules/customers/api/companies/[id]/people/route.js +2 -2
- package/dist/modules/customers/api/companies/[id]/people/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/companies/route.js +2 -2
- package/dist/modules/customers/api/deals/[id]/companies/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/people/route.js +2 -2
- package/dist/modules/customers/api/deals/[id]/people/route.js.map +2 -2
- package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js +4 -4
- package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/entity-roles-factory.js +3 -3
- package/dist/modules/customers/api/entity-roles-factory.js.map +2 -2
- package/dist/modules/customers/api/labels/assign/route.js +2 -2
- package/dist/modules/customers/api/labels/assign/route.js.map +2 -2
- package/dist/modules/customers/api/labels/unassign/route.js +2 -2
- package/dist/modules/customers/api/labels/unassign/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js +3 -7
- package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/context.js +3 -3
- package/dist/modules/customers/api/people/[id]/companies/context.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/enriched/route.js +2 -2
- package/dist/modules/customers/api/people/[id]/companies/enriched/route.js.map +2 -2
- package/dist/modules/customers/api/todos/route.js +2 -2
- package/dist/modules/customers/api/todos/route.js.map +2 -2
- package/dist/modules/customers/commands/addresses.js +3 -3
- package/dist/modules/customers/commands/addresses.js.map +2 -2
- package/dist/modules/customers/commands/comments.js +3 -3
- package/dist/modules/customers/commands/comments.js.map +2 -2
- package/dist/modules/customers/commands/companies.js +2 -2
- package/dist/modules/customers/commands/companies.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +3 -3
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/commands/dictionaries.js +3 -3
- package/dist/modules/customers/commands/dictionaries.js.map +2 -2
- package/dist/modules/customers/commands/entity-roles.js +3 -3
- package/dist/modules/customers/commands/entity-roles.js.map +2 -2
- package/dist/modules/customers/commands/interactions.js +6 -6
- package/dist/modules/customers/commands/interactions.js.map +2 -2
- package/dist/modules/customers/commands/labels.js +7 -7
- package/dist/modules/customers/commands/labels.js.map +2 -2
- package/dist/modules/customers/commands/people.js +3 -3
- package/dist/modules/customers/commands/people.js.map +2 -2
- package/dist/modules/customers/commands/personCompanyLinks.js +6 -6
- package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
- package/dist/modules/customers/commands/pipeline-stages.js +3 -3
- package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
- package/dist/modules/customers/commands/pipelines.js +3 -3
- package/dist/modules/customers/commands/pipelines.js.map +2 -2
- package/dist/modules/customers/commands/shared.js +3 -3
- package/dist/modules/customers/commands/shared.js.map +2 -2
- package/dist/modules/customers/commands/tags.js +7 -7
- package/dist/modules/customers/commands/tags.js.map +2 -2
- package/dist/modules/customers/commands/todos.js +3 -3
- package/dist/modules/customers/commands/todos.js.map +2 -2
- package/dist/modules/customers/lib/personCompanies.js +4 -4
- package/dist/modules/customers/lib/personCompanies.js.map +2 -2
- package/dist/modules/perspectives/data/validators.js +4 -0
- package/dist/modules/perspectives/data/validators.js.map +2 -2
- package/dist/modules/sales/api/notes/route.js +2 -4
- package/dist/modules/sales/api/notes/route.js.map +2 -2
- package/dist/modules/sales/api/quotes/accept/route.js +2 -2
- package/dist/modules/sales/api/quotes/accept/route.js.map +2 -2
- package/dist/modules/sales/api/quotes/public/[token]/route.js +3 -7
- package/dist/modules/sales/api/quotes/public/[token]/route.js.map +2 -2
- package/dist/modules/sales/api/quotes/send/route.js +2 -2
- package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
- package/dist/modules/sales/api/returns/[id]/route.js +2 -2
- package/dist/modules/sales/api/returns/[id]/route.js.map +2 -2
- package/dist/modules/sales/commands/configuration.js +11 -11
- package/dist/modules/sales/commands/configuration.js.map +2 -2
- package/dist/modules/sales/commands/documentAddresses.js +3 -3
- package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +31 -39
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/notes.js +7 -7
- package/dist/modules/sales/commands/notes.js.map +2 -2
- package/dist/modules/sales/commands/payments.js +2 -2
- package/dist/modules/sales/commands/payments.js.map +2 -2
- package/dist/modules/sales/commands/returns.js +8 -8
- package/dist/modules/sales/commands/returns.js.map +2 -2
- package/dist/modules/sales/commands/shared.js +2 -2
- package/dist/modules/sales/commands/shared.js.map +2 -2
- package/dist/modules/sales/commands/shipments.js +5 -5
- package/dist/modules/sales/commands/shipments.js.map +2 -2
- package/dist/modules/sales/commands/statuses.js +2 -2
- package/dist/modules/sales/commands/statuses.js.map +2 -2
- package/dist/modules/sales/commands/tags.js +3 -3
- package/dist/modules/sales/commands/tags.js.map +2 -2
- package/package.json +8 -8
- package/src/modules/attachments/api/partitions/route.ts +1 -1
- package/src/modules/attachments/lib/reconcileOrganization.ts +16 -7
- package/src/modules/catalog/api/products/route.ts +1 -1
- package/src/modules/customer_accounts/i18n/de.json +12 -0
- package/src/modules/customer_accounts/i18n/en.json +12 -0
- package/src/modules/customer_accounts/i18n/es.json +34 -22
- package/src/modules/customer_accounts/i18n/pl.json +32 -20
- package/src/modules/customers/api/companies/[id]/people/route.ts +2 -2
- package/src/modules/customers/api/deals/[id]/companies/route.ts +2 -2
- package/src/modules/customers/api/deals/[id]/people/route.ts +2 -2
- package/src/modules/customers/api/dictionaries/[kind]/[id]/route.ts +4 -4
- package/src/modules/customers/api/entity-roles-factory.ts +3 -3
- package/src/modules/customers/api/labels/assign/route.ts +2 -2
- package/src/modules/customers/api/labels/unassign/route.ts +2 -2
- package/src/modules/customers/api/people/[id]/companies/[linkId]/route.ts +3 -7
- package/src/modules/customers/api/people/[id]/companies/context.ts +3 -3
- package/src/modules/customers/api/people/[id]/companies/enriched/route.ts +2 -2
- package/src/modules/customers/api/todos/route.ts +2 -2
- package/src/modules/customers/commands/addresses.ts +3 -3
- package/src/modules/customers/commands/comments.ts +3 -3
- package/src/modules/customers/commands/companies.ts +2 -2
- package/src/modules/customers/commands/deals.ts +3 -3
- package/src/modules/customers/commands/dictionaries.ts +3 -3
- package/src/modules/customers/commands/entity-roles.ts +3 -3
- package/src/modules/customers/commands/interactions.ts +6 -6
- package/src/modules/customers/commands/labels.ts +7 -7
- package/src/modules/customers/commands/people.ts +3 -3
- package/src/modules/customers/commands/personCompanyLinks.ts +6 -6
- package/src/modules/customers/commands/pipeline-stages.ts +3 -3
- package/src/modules/customers/commands/pipelines.ts +3 -3
- package/src/modules/customers/commands/shared.ts +3 -3
- package/src/modules/customers/commands/tags.ts +7 -7
- package/src/modules/customers/commands/todos.ts +3 -3
- package/src/modules/customers/lib/personCompanies.ts +4 -4
- package/src/modules/perspectives/data/validators.ts +4 -0
- package/src/modules/sales/api/notes/route.ts +2 -4
- package/src/modules/sales/api/quotes/accept/route.ts +2 -2
- package/src/modules/sales/api/quotes/public/[token]/route.ts +3 -7
- package/src/modules/sales/api/quotes/send/route.ts +2 -2
- package/src/modules/sales/api/returns/[id]/route.ts +2 -2
- package/src/modules/sales/commands/configuration.ts +11 -11
- package/src/modules/sales/commands/documentAddresses.ts +3 -3
- package/src/modules/sales/commands/documents.ts +23 -31
- package/src/modules/sales/commands/notes.ts +7 -7
- package/src/modules/sales/commands/payments.ts +2 -2
- package/src/modules/sales/commands/returns.ts +8 -8
- package/src/modules/sales/commands/shared.ts +2 -2
- package/src/modules/sales/commands/shipments.ts +5 -5
- package/src/modules/sales/commands/statuses.ts +2 -2
- package/src/modules/sales/commands/tags.ts +3 -3
- package/tsconfig.json +0 -2
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
buildChanges,
|
|
6
6
|
requireId
|
|
7
7
|
} from "@open-mercato/shared/lib/commands/helpers";
|
|
8
|
-
import {
|
|
8
|
+
import { notFound } from "@open-mercato/shared/lib/crud/errors";
|
|
9
9
|
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
10
10
|
import { E } from "../../../generated/entities.ids.generated.js";
|
|
11
11
|
import {
|
|
@@ -56,7 +56,7 @@ async function requireContext(em, contextType, contextId, organizationId, tenant
|
|
|
56
56
|
if (contextType === "order") {
|
|
57
57
|
const order = await findOneWithDecryption(em, SalesOrder, { id: contextId }, {}, { tenantId, organizationId });
|
|
58
58
|
if (!order) {
|
|
59
|
-
throw
|
|
59
|
+
throw notFound("sales.notes.context_not_found");
|
|
60
60
|
}
|
|
61
61
|
if (organizationId && tenantId) {
|
|
62
62
|
ensureSameScope(order, organizationId, tenantId);
|
|
@@ -71,7 +71,7 @@ async function requireContext(em, contextType, contextId, organizationId, tenant
|
|
|
71
71
|
if (contextType === "quote") {
|
|
72
72
|
const quote = await findOneWithDecryption(em, SalesQuote, { id: contextId }, {}, { tenantId, organizationId });
|
|
73
73
|
if (!quote) {
|
|
74
|
-
throw
|
|
74
|
+
throw notFound("sales.notes.context_not_found");
|
|
75
75
|
}
|
|
76
76
|
if (organizationId && tenantId) {
|
|
77
77
|
ensureSameScope(quote, organizationId, tenantId);
|
|
@@ -92,7 +92,7 @@ async function requireContext(em, contextType, contextId, organizationId, tenant
|
|
|
92
92
|
{ tenantId, organizationId }
|
|
93
93
|
);
|
|
94
94
|
if (!entity) {
|
|
95
|
-
throw
|
|
95
|
+
throw notFound("sales.notes.context_not_found");
|
|
96
96
|
}
|
|
97
97
|
if (organizationId && tenantId) {
|
|
98
98
|
ensureSameScope(entity, organizationId, tenantId);
|
|
@@ -210,7 +210,7 @@ const createNoteCommand = {
|
|
|
210
210
|
beforeRestore: async ({ em, snapshot }) => {
|
|
211
211
|
const context = await requireContext(em, snapshot.contextType, snapshot.contextId).catch(() => null);
|
|
212
212
|
if (!context) {
|
|
213
|
-
throw
|
|
213
|
+
throw notFound("sales.notes.context_not_found");
|
|
214
214
|
}
|
|
215
215
|
return {
|
|
216
216
|
order: snapshot.orderId ? context.order ?? null : null,
|
|
@@ -232,7 +232,7 @@ const updateNoteCommand = {
|
|
|
232
232
|
const parsed = noteUpdateSchema.parse(rawInput ?? {});
|
|
233
233
|
const em = ctx.container.resolve("em").fork();
|
|
234
234
|
const note = await findOneWithDecryption(em, SalesNote, { id: parsed.id }, {});
|
|
235
|
-
if (!note) throw
|
|
235
|
+
if (!note) throw notFound("sales.notes.not_found");
|
|
236
236
|
ensureTenantScope(ctx, note.tenantId);
|
|
237
237
|
ensureOrganizationScope(ctx, note.organizationId);
|
|
238
238
|
if (parsed.body !== void 0) note.body = parsed.body;
|
|
@@ -356,7 +356,7 @@ const deleteNoteCommand = {
|
|
|
356
356
|
const id = requireId(input, "Note id required");
|
|
357
357
|
const em = ctx.container.resolve("em").fork();
|
|
358
358
|
const note = await findOneWithDecryption(em, SalesNote, { id }, {});
|
|
359
|
-
if (!note) throw
|
|
359
|
+
if (!note) throw notFound("sales.notes.not_found");
|
|
360
360
|
ensureTenantScope(ctx, note.tenantId);
|
|
361
361
|
ensureOrganizationScope(ctx, note.organizationId);
|
|
362
362
|
em.remove(note);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sales/commands/notes.ts"],
|
|
4
|
-
"sourcesContent": ["import { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n buildChanges,\n requireId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport {\n SalesNote,\n SalesOrder,\n SalesQuote,\n SalesInvoice,\n SalesCreditMemo,\n type SalesDocumentKind,\n} from '../data/entities'\nimport {\n noteCreateSchema,\n noteUpdateSchema,\n type NoteCreateInput,\n type NoteUpdateInput,\n} from '../data/validators'\nimport { makeCreateRedo } from '@open-mercato/shared/lib/commands/redo'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { ensureOrganizationScope, ensureSameScope, ensureTenantScope, extractUndoPayload } from './shared'\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: SalesDocumentKind\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype NoteUndoPayload = {\n before?: NoteSnapshot | null\n after?: NoteSnapshot | null\n}\n\nconst noteCrudIndexer = {\n entityType: E.sales.sales_note,\n}\n\nconst noteCrudEvents: CrudEventsConfig = {\n module: 'sales',\n entity: 'note',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nasync function loadNoteSnapshot(em: EntityManager, id: string): Promise<NoteSnapshot | null> {\n const note = await findOneWithDecryption(em, SalesNote, { id }, {})\n if (!note) return null\n return {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n contextType: note.contextType,\n contextId: note.contextId,\n orderId: note.order ? (typeof note.order === 'string' ? note.order : note.order.id) : null,\n quoteId: note.quote ? (typeof note.quote === 'string' ? note.quote : note.quote.id) : null,\n body: note.body,\n authorUserId: note.authorUserId ?? null,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n }\n}\n\nasync function requireContext(\n em: EntityManager,\n contextType: SalesDocumentKind,\n contextId: string,\n organizationId?: string,\n tenantId?: string\n): Promise<{\n organizationId: string\n tenantId: string\n order?: SalesOrder | null\n quote?: SalesQuote | null\n}> {\n if (contextType === 'order') {\n const order = await findOneWithDecryption(em, SalesOrder, { id: contextId }, {}, { tenantId, organizationId })\n if (!order) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(order, organizationId, tenantId)\n }\n return {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n order,\n quote: null,\n }\n }\n if (contextType === 'quote') {\n const quote = await findOneWithDecryption(em, SalesQuote, { id: contextId }, {}, { tenantId, organizationId })\n if (!quote) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(quote, organizationId, tenantId)\n }\n return {\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n order: null,\n quote,\n }\n }\n const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo\n const entity = await findOneWithDecryption(\n em,\n repo as any,\n { id: contextId },\n {},\n { tenantId, organizationId },\n ) as (SalesInvoice | SalesCreditMemo) | null\n if (!entity) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n if (organizationId && tenantId) {\n ensureSameScope(entity, organizationId, tenantId)\n }\n return {\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n order: null,\n quote: null,\n }\n}\n\nfunction resolveAuthor(authSub: string | null): string | null {\n const sub = authSub?.trim()\n if (!sub) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(sub) ? sub : null\n}\n\nconst createNoteCommand: CommandHandler<NoteCreateInput, { noteId: string; authorUserId: string | null }> = {\n id: 'sales.notes.create',\n async execute(rawInput, ctx) {\n const parsed = noteCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, parsed.contextType, parsed.contextId, parsed.organizationId, parsed.tenantId)\n const authorUserId = resolveAuthor(ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n\n const note = em.create(SalesNote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n contextType: parsed.contextType,\n contextId: parsed.contextId,\n order: context.order ?? null,\n quote: context.quote ?? null,\n authorUserId,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n body: parsed.body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id, authorUserId: note.authorUserId ?? null }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as NoteSnapshot | undefined\n return {\n actionLabel: translate('sales.audit.notes.create', 'Create note'),\n resourceKind: 'sales.note',\n resourceId: result.noteId,\n parentResourceKind: snapshot?.contextType ? `sales.${snapshot.contextType}` : null,\n parentResourceId: snapshot?.contextId ?? null,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const noteId = logEntry?.resourceId ?? null\n if (!noteId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const existing = await findOneWithDecryption(em, SalesNote, { id: noteId }, {})\n if (existing) {\n em.remove(existing)\n await em.flush()\n }\n },\n redo: makeCreateRedo<SalesNote, NoteSnapshot, NoteCreateInput, { noteId: string; authorUserId: string | null }>({\n entityClass: SalesNote,\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n findRow: ({ em, id, snapshot }) =>\n findOneWithDecryption(\n em,\n SalesNote,\n { id },\n undefined,\n { tenantId: snapshot.tenantId, organizationId: snapshot.organizationId },\n ),\n seedFromSnapshot: (snapshot) => ({\n id: snapshot.id,\n organizationId: snapshot.organizationId,\n tenantId: snapshot.tenantId,\n contextType: snapshot.contextType,\n contextId: snapshot.contextId,\n body: snapshot.body,\n authorUserId: snapshot.authorUserId,\n appearanceIcon: snapshot.appearanceIcon,\n appearanceColor: snapshot.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n }),\n beforeRestore: async ({ em, snapshot }) => {\n const context = await requireContext(em, snapshot.contextType, snapshot.contextId).catch(() => null)\n if (!context) {\n throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })\n }\n return {\n order: snapshot.orderId ? context.order ?? null : null,\n quote: snapshot.quoteId ? context.quote ?? null : null,\n }\n },\n buildResult: (entity) => ({ noteId: entity.id, authorUserId: entity.authorUserId ?? null }),\n }),\n}\n\nconst updateNoteCommand: CommandHandler<NoteUpdateInput, { noteId: string }> = {\n id: 'sales.notes.update',\n async prepare(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await findOneWithDecryption(em, SalesNote, { id: parsed.id }, {})\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n\n if (parsed.body !== undefined) note.body = parsed.body\n if (parsed.authorUserId !== undefined) {\n note.authorUserId = resolveAuthor(ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n }\n if (parsed.appearanceIcon !== undefined) note.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) note.appearanceColor = parsed.appearanceColor ?? null\n note.updatedAt = new Date()\n\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const after = snapshots.after as NoteSnapshot | undefined\n const changes =\n after && before\n ? buildChanges(\n before as unknown as Record<string, unknown>,\n after as unknown as Record<string, unknown>,\n ['body', 'authorUserId', 'appearanceIcon', 'appearanceColor']\n )\n : {}\n return {\n actionLabel: translate('sales.audit.notes.update', 'Update note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await findOneWithDecryption(em, SalesNote, { id: before.id }, {}, { tenantId: before.tenantId, organizationId: before.organizationId })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n}\n\nconst deleteNoteCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { noteId: string }> =\n {\n id: 'sales.notes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await findOneWithDecryption(em, SalesNote, { id }, {})\n if (!note) throw new CrudHttpError(404, { error: 'sales.notes.not_found' })\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n em.remove(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n return { noteId: note.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.notes.delete', 'Delete note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await findOneWithDecryption(em, SalesNote, { id: before.id }, {}, { tenantId: before.tenantId, organizationId: before.organizationId })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n }\n\nregisterCommand(createNoteCommand)\nregisterCommand(updateNoteCommand)\nregisterCommand(deleteNoteCommand)\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAA4C;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AAEpC,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,yBAAyB,iBAAiB,mBAAmB,0BAA0B;AAqBhG,MAAM,kBAAkB;AAAA,EACtB,YAAY,EAAE,MAAM;AACtB;AAEA,MAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc,CAAC,SAAS;AAAA,IACtB,IAAI,IAAI,YAAY;AAAA,IACpB,gBAAgB,IAAI,YAAY;AAAA,IAChC,UAAU,IAAI,YAAY;AAAA,EAC5B;AACF;AAEA,eAAe,iBAAiB,IAAmB,IAA0C;AAC3F,QAAM,OAAO,MAAM,sBAAsB,IAAI,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC;AAClE,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO;AAAA,IACL,IAAI,KAAK;AAAA,IACT,gBA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AAW,oBAAI,KAAK;AAAA,QACpB,WAAW,oBAAI,KAAK;AAAA,MACtB,CAAC;AACD,SAAG,QAAQ,IAAI;AAAA,IACjB;AACE,SAAK,iBAAiB,OAAO;AAC7B,SAAK,WAAW,OAAO;AACvB,SAAK,cAAc,OAAO;AAC1B,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO,UAAU,QAAQ,SAAS,OAAO;AACtD,SAAK,QAAQ,OAAO,UAAU,QAAQ,SAAS,OAAO;AACtD,SAAK,OAAO,OAAO;AACnB,SAAK,eAAe,OAAO;AAC3B,SAAK,iBAAiB,OAAO;AAC7B,SAAK,kBAAkB,OAAO;AAC9B,SAAK,YAAY,oBAAI,KAAK;AAC1B,UAAM,GAAG,MAAM;AAEf,UAAM,aAAa,IAAI,UAAU,QAAQ,YAAY;AACrD,UAAM,wBAAwB;AAAA,MAC5B;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,aAAa;AAAA,QACX,IAAI,KAAK;AAAA,QACT,gBAAgB,KAAK;AAAA,QACrB,UAAU,KAAK;AAAA,MACjB;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEF,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;",
|
|
4
|
+
"sourcesContent": ["import { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n buildChanges,\n requireId,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { notFound } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport {\n SalesNote,\n SalesOrder,\n SalesQuote,\n SalesInvoice,\n SalesCreditMemo,\n type SalesDocumentKind,\n} from '../data/entities'\nimport {\n noteCreateSchema,\n noteUpdateSchema,\n type NoteCreateInput,\n type NoteUpdateInput,\n} from '../data/validators'\nimport { makeCreateRedo } from '@open-mercato/shared/lib/commands/redo'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { ensureOrganizationScope, ensureSameScope, ensureTenantScope, extractUndoPayload } from './shared'\n\ntype NoteSnapshot = {\n id: string\n organizationId: string\n tenantId: string\n contextType: SalesDocumentKind\n contextId: string\n orderId: string | null\n quoteId: string | null\n body: string\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype NoteUndoPayload = {\n before?: NoteSnapshot | null\n after?: NoteSnapshot | null\n}\n\nconst noteCrudIndexer = {\n entityType: E.sales.sales_note,\n}\n\nconst noteCrudEvents: CrudEventsConfig = {\n module: 'sales',\n entity: 'note',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nasync function loadNoteSnapshot(em: EntityManager, id: string): Promise<NoteSnapshot | null> {\n const note = await findOneWithDecryption(em, SalesNote, { id }, {})\n if (!note) return null\n return {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n contextType: note.contextType,\n contextId: note.contextId,\n orderId: note.order ? (typeof note.order === 'string' ? note.order : note.order.id) : null,\n quoteId: note.quote ? (typeof note.quote === 'string' ? note.quote : note.quote.id) : null,\n body: note.body,\n authorUserId: note.authorUserId ?? null,\n appearanceIcon: note.appearanceIcon ?? null,\n appearanceColor: note.appearanceColor ?? null,\n }\n}\n\nasync function requireContext(\n em: EntityManager,\n contextType: SalesDocumentKind,\n contextId: string,\n organizationId?: string,\n tenantId?: string\n): Promise<{\n organizationId: string\n tenantId: string\n order?: SalesOrder | null\n quote?: SalesQuote | null\n}> {\n if (contextType === 'order') {\n const order = await findOneWithDecryption(em, SalesOrder, { id: contextId }, {}, { tenantId, organizationId })\n if (!order) {\n throw notFound('sales.notes.context_not_found')\n }\n if (organizationId && tenantId) {\n ensureSameScope(order, organizationId, tenantId)\n }\n return {\n organizationId: order.organizationId,\n tenantId: order.tenantId,\n order,\n quote: null,\n }\n }\n if (contextType === 'quote') {\n const quote = await findOneWithDecryption(em, SalesQuote, { id: contextId }, {}, { tenantId, organizationId })\n if (!quote) {\n throw notFound('sales.notes.context_not_found')\n }\n if (organizationId && tenantId) {\n ensureSameScope(quote, organizationId, tenantId)\n }\n return {\n organizationId: quote.organizationId,\n tenantId: quote.tenantId,\n order: null,\n quote,\n }\n }\n const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo\n const entity = await findOneWithDecryption(\n em,\n repo as any,\n { id: contextId },\n {},\n { tenantId, organizationId },\n ) as (SalesInvoice | SalesCreditMemo) | null\n if (!entity) {\n throw notFound('sales.notes.context_not_found')\n }\n if (organizationId && tenantId) {\n ensureSameScope(entity, organizationId, tenantId)\n }\n return {\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n order: null,\n quote: null,\n }\n}\n\nfunction resolveAuthor(authSub: string | null): string | null {\n const sub = authSub?.trim()\n if (!sub) return null\n const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/\n return uuidRegex.test(sub) ? sub : null\n}\n\nconst createNoteCommand: CommandHandler<NoteCreateInput, { noteId: string; authorUserId: string | null }> = {\n id: 'sales.notes.create',\n async execute(rawInput, ctx) {\n const parsed = noteCreateSchema.parse(rawInput ?? {})\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, parsed.contextType, parsed.contextId, parsed.organizationId, parsed.tenantId)\n const authorUserId = resolveAuthor(ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n\n const note = em.create(SalesNote, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n contextType: parsed.contextType,\n contextId: parsed.contextId,\n order: context.order ?? null,\n quote: context.quote ?? null,\n authorUserId,\n appearanceIcon: parsed.appearanceIcon ?? null,\n appearanceColor: parsed.appearanceColor ?? null,\n body: parsed.body,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id, authorUserId: note.authorUserId ?? null }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as NoteSnapshot | undefined\n return {\n actionLabel: translate('sales.audit.notes.create', 'Create note'),\n resourceKind: 'sales.note',\n resourceId: result.noteId,\n parentResourceKind: snapshot?.contextType ? `sales.${snapshot.contextType}` : null,\n parentResourceId: snapshot?.contextId ?? null,\n tenantId: snapshot?.tenantId ?? null,\n organizationId: snapshot?.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const noteId = logEntry?.resourceId ?? null\n if (!noteId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const existing = await findOneWithDecryption(em, SalesNote, { id: noteId }, {})\n if (existing) {\n em.remove(existing)\n await em.flush()\n }\n },\n redo: makeCreateRedo<SalesNote, NoteSnapshot, NoteCreateInput, { noteId: string; authorUserId: string | null }>({\n entityClass: SalesNote,\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n findRow: ({ em, id, snapshot }) =>\n findOneWithDecryption(\n em,\n SalesNote,\n { id },\n undefined,\n { tenantId: snapshot.tenantId, organizationId: snapshot.organizationId },\n ),\n seedFromSnapshot: (snapshot) => ({\n id: snapshot.id,\n organizationId: snapshot.organizationId,\n tenantId: snapshot.tenantId,\n contextType: snapshot.contextType,\n contextId: snapshot.contextId,\n body: snapshot.body,\n authorUserId: snapshot.authorUserId,\n appearanceIcon: snapshot.appearanceIcon,\n appearanceColor: snapshot.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n }),\n beforeRestore: async ({ em, snapshot }) => {\n const context = await requireContext(em, snapshot.contextType, snapshot.contextId).catch(() => null)\n if (!context) {\n throw notFound('sales.notes.context_not_found')\n }\n return {\n order: snapshot.orderId ? context.order ?? null : null,\n quote: snapshot.quoteId ? context.quote ?? null : null,\n }\n },\n buildResult: (entity) => ({ noteId: entity.id, authorUserId: entity.authorUserId ?? null }),\n }),\n}\n\nconst updateNoteCommand: CommandHandler<NoteUpdateInput, { noteId: string }> = {\n id: 'sales.notes.update',\n async prepare(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = noteUpdateSchema.parse(rawInput ?? {})\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await findOneWithDecryption(em, SalesNote, { id: parsed.id }, {})\n if (!note) throw notFound('sales.notes.not_found')\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n\n if (parsed.body !== undefined) note.body = parsed.body\n if (parsed.authorUserId !== undefined) {\n note.authorUserId = resolveAuthor(ctx.auth?.isApiKey ? null : ctx.auth?.sub ?? null)\n }\n if (parsed.appearanceIcon !== undefined) note.appearanceIcon = parsed.appearanceIcon ?? null\n if (parsed.appearanceColor !== undefined) note.appearanceColor = parsed.appearanceColor ?? null\n note.updatedAt = new Date()\n\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n\n return { noteId: note.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadNoteSnapshot(em, result.noteId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const after = snapshots.after as NoteSnapshot | undefined\n const changes =\n after && before\n ? buildChanges(\n before as unknown as Record<string, unknown>,\n after as unknown as Record<string, unknown>,\n ['body', 'authorUserId', 'appearanceIcon', 'appearanceColor']\n )\n : {}\n return {\n actionLabel: translate('sales.audit.notes.update', 'Update note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n snapshotAfter: after ?? null,\n changes,\n payload: {\n undo: {\n before,\n after: after ?? null,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await findOneWithDecryption(em, SalesNote, { id: before.id }, {}, { tenantId: before.tenantId, organizationId: before.organizationId })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n}\n\nconst deleteNoteCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { noteId: string }> =\n {\n id: 'sales.notes.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = ctx.container.resolve('em') as EntityManager\n const snapshot = await loadNoteSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Note id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const note = await findOneWithDecryption(em, SalesNote, { id }, {})\n if (!note) throw notFound('sales.notes.not_found')\n ensureTenantScope(ctx, note.tenantId)\n ensureOrganizationScope(ctx, note.organizationId)\n em.remove(note)\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n return { noteId: note.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as NoteSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('sales.audit.notes.delete', 'Delete note'),\n resourceKind: 'sales.note',\n resourceId: before.id,\n parentResourceKind: before.contextType ? `sales.${before.contextType}` : null,\n parentResourceId: before.contextId ?? null,\n tenantId: before.tenantId,\n organizationId: before.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies NoteUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<NoteUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const context = await requireContext(em, before.contextType, before.contextId).catch(() => null)\n if (!context) return\n let note = await findOneWithDecryption(em, SalesNote, { id: before.id }, {}, { tenantId: before.tenantId, organizationId: before.organizationId })\n if (!note) {\n note = em.create(SalesNote, {\n id: before.id,\n organizationId: before.organizationId,\n tenantId: before.tenantId,\n contextType: before.contextType,\n contextId: before.contextId,\n order: before.orderId ? context.order ?? null : null,\n quote: before.quoteId ? context.quote ?? null : null,\n body: before.body,\n authorUserId: before.authorUserId,\n appearanceIcon: before.appearanceIcon,\n appearanceColor: before.appearanceColor,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(note)\n }\n note.organizationId = before.organizationId\n note.tenantId = before.tenantId\n note.contextType = before.contextType\n note.contextId = before.contextId\n note.order = before.orderId ? context.order ?? null : null\n note.quote = before.quoteId ? context.quote ?? null : null\n note.body = before.body\n note.authorUserId = before.authorUserId\n note.appearanceIcon = before.appearanceIcon\n note.appearanceColor = before.appearanceColor\n note.updatedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: note,\n identifiers: {\n id: note.id,\n organizationId: note.organizationId,\n tenantId: note.tenantId,\n },\n indexer: noteCrudIndexer,\n events: noteCrudEvents,\n })\n },\n }\n\nregisterCommand(createNoteCommand)\nregisterCommand(updateNo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;AAAA,MACR,QAAQ;AAAA,MACR,aAAa;AAAA,QACX,IAAI,KAAK;AAAA,QACT,gBAAgB,KAAK;AAAA,QACrB,UAAU,KAAK;AAAA,MACjB;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEF,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { registerCommand } from "@open-mercato/shared/lib/commands";
|
|
2
2
|
import { LockMode } from "@mikro-orm/core";
|
|
3
|
-
import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
|
|
3
|
+
import { CrudHttpError, notFound } from "@open-mercato/shared/lib/crud/errors";
|
|
4
4
|
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
5
5
|
import { loadCustomFieldValues } from "@open-mercato/shared/lib/crud/custom-fields";
|
|
6
6
|
import { setRecordCustomFields } from "@open-mercato/core/modules/entities/lib/helpers";
|
|
@@ -233,7 +233,7 @@ const createPaymentCommand = {
|
|
|
233
233
|
);
|
|
234
234
|
ensureSameScope(order2, input.organizationId, input.tenantId);
|
|
235
235
|
if (order2.deletedAt) {
|
|
236
|
-
throw
|
|
236
|
+
throw notFound("sales.payments.order_not_found");
|
|
237
237
|
}
|
|
238
238
|
await enforceSalesDocumentOptimisticLock(ctx, order2, SALES_RESOURCE_KIND_ORDER);
|
|
239
239
|
if (order2.currencyCode && input.currencyCode && order2.currencyCode.toUpperCase() !== input.currencyCode.toUpperCase()) {
|