Until now the only bulk action anywhere was Archive on the interests
list — implemented as parallel fan-out with no per-row failure
reporting. The bulk BullMQ worker was a TODO stub with no producers.
- bulk-helpers.runBulk wraps a per-row loop and returns
{results, summary} for the caller. Page-size capped at 100.
- New endpoints: /api/v1/{interests,clients,yachts,companies}/bulk
with a Zod discriminated union over the action. Interests support
change_stage + add_tag + remove_tag + archive; clients/yachts/companies
support archive + add_tag + remove_tag. Each action is permission-gated
individually (delete vs edit vs change_stage).
- interest-list, client-list, yacht-list expose the new actions in the
bulk-action toolbar with dialogs for stage / tag selection. Failure
summaries surface via window.confirm.
- bulkWorker stub gets a docblock explaining the v1 sync-only choice
and what the queue is reserved for (CSV imports, port-wide migrations,
bulk emails to >100 recipients).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
929 B
TypeScript
44 lines
929 B
TypeScript
/**
|
|
* Shared utilities for synchronous bulk endpoints.
|
|
* See `/api/v1/{entity}/bulk` route handlers for usage.
|
|
*/
|
|
|
|
export interface BulkRowResult {
|
|
id: string;
|
|
ok: boolean;
|
|
error?: string;
|
|
}
|
|
|
|
export interface BulkSummary {
|
|
total: number;
|
|
succeeded: number;
|
|
failed: number;
|
|
}
|
|
|
|
export async function runBulk(
|
|
ids: string[],
|
|
perRow: (id: string) => Promise<void>,
|
|
): Promise<{ results: BulkRowResult[]; summary: BulkSummary }> {
|
|
const results: BulkRowResult[] = [];
|
|
for (const id of ids) {
|
|
try {
|
|
await perRow(id);
|
|
results.push({ id, ok: true });
|
|
} catch (err) {
|
|
results.push({
|
|
id,
|
|
ok: false,
|
|
error: err instanceof Error ? err.message : 'unknown error',
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
results,
|
|
summary: {
|
|
total: results.length,
|
|
succeeded: results.filter((r) => r.ok).length,
|
|
failed: results.filter((r) => !r.ok).length,
|
|
},
|
|
};
|
|
}
|