perf+fix: file download proxy + drop awaits on audit/notifications/finance sync
Two problems reported by the user: 1. File downloads broken on the lab side. The link in JobFilesPanel pointed straight at Appwrite's /storage/.../view URL. Storage permissions are scoped to the job's two teams, but the browser only has a session cookie for our app domain, not for db.kovaksoft.com — so the cross-origin request hit Appwrite as a guest and 401'd. New /api/jobs/[jobId]/files/[fileId]/download route. requireTenant() first, then verify the caller's tenant is one of (clinicTenantId, labTenantId) on the parent job, then storage.getFileDownload via the admin SDK and stream the buffer back with Content-Disposition: attachment so the browser saves it under the original filename. listJobFiles now hands out that relative URL instead of the Appwrite one — same anchor in the panel, just routed through us. 2. Saves and edits feel slow whenever a notification is involved. Every mutation was awaiting logAudit, createNotification and syncFinanceForJob in sequence. None of these need to block the user response — audit is best-effort logging, notifications are async UX, and the finance sync is idempotent and re-runs on the next mutation anyway. Switched all 46 call sites across the action modules to void-fire-and-forget (matching the pattern we already used in clinic-pricing-actions). Net effect: each mutation drops ~3 sequential Appwrite roundtrips before the server action returns.
This commit is contained in:
@@ -201,7 +201,7 @@ export async function createJobAction(
|
||||
},
|
||||
jobPermissions(ctx.tenantId, parsed.data.labTenantId),
|
||||
);
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "create",
|
||||
@@ -209,7 +209,7 @@ export async function createJobAction(
|
||||
entityId: created.$id,
|
||||
changes: { labTenantId: parsed.data.labTenantId, patientCode },
|
||||
});
|
||||
await createNotification({
|
||||
void createNotification({
|
||||
tenantId: parsed.data.labTenantId,
|
||||
jobId: created.$id,
|
||||
message: `${ctx.settings?.companyName ?? "Bir klinik"} yeni iş yayınladı (${patientCode}).`,
|
||||
@@ -302,7 +302,7 @@ export async function acceptJobAction(
|
||||
currentStep: "olcu",
|
||||
});
|
||||
await appendJobHistory({ job, step: "olcu", completedBy: ctx.user.id });
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "update",
|
||||
@@ -310,7 +310,7 @@ export async function acceptJobAction(
|
||||
entityId: jobId,
|
||||
changes: { status: "in_progress", currentStep: "olcu" },
|
||||
});
|
||||
await createNotification({
|
||||
void createNotification({
|
||||
tenantId: job.clinicTenantId,
|
||||
jobId,
|
||||
message: `${ctx.settings?.companyName ?? "Lab"} hasta ${job.patientCode} işini işleme aldı.`,
|
||||
@@ -361,7 +361,7 @@ export async function advanceStepAction(
|
||||
await tablesDB.updateRow(DATABASE_ID, TABLES.jobs, jobId, {
|
||||
status: "sent",
|
||||
});
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "update",
|
||||
@@ -380,7 +380,7 @@ export async function advanceStepAction(
|
||||
completedBy: ctx.user.id,
|
||||
note,
|
||||
});
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "update",
|
||||
@@ -401,8 +401,8 @@ export async function advanceStepAction(
|
||||
completedBy: ctx.user.id,
|
||||
note,
|
||||
});
|
||||
await syncFinanceForJob({ ...job, status: "sent" });
|
||||
await createNotification({
|
||||
void syncFinanceForJob({ ...job, status: "sent" });
|
||||
void createNotification({
|
||||
tenantId: job.clinicTenantId,
|
||||
jobId,
|
||||
message: `Hasta ${job.patientCode} işi gönderildi. Teslim alındığında onaylayın.`,
|
||||
@@ -445,7 +445,7 @@ export async function markDeliveredAction(
|
||||
await tablesDB.updateRow(DATABASE_ID, TABLES.jobs, jobId, {
|
||||
status: "delivered",
|
||||
});
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "update",
|
||||
@@ -453,8 +453,8 @@ export async function markDeliveredAction(
|
||||
entityId: jobId,
|
||||
changes: { status: "delivered" },
|
||||
});
|
||||
await syncFinanceForJob({ ...job, status: "delivered" });
|
||||
await createNotification({
|
||||
void syncFinanceForJob({ ...job, status: "delivered" });
|
||||
void createNotification({
|
||||
tenantId: job.labTenantId,
|
||||
jobId,
|
||||
message: `Hasta ${job.patientCode} işi teslim alındı.`,
|
||||
@@ -502,7 +502,7 @@ export async function cancelJobAction(
|
||||
await tablesDB.updateRow(DATABASE_ID, TABLES.jobs, jobId, {
|
||||
status: "cancelled",
|
||||
});
|
||||
await logAudit({
|
||||
void logAudit({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.user.id,
|
||||
action: "update",
|
||||
|
||||
Reference in New Issue
Block a user