forked from Stellar-split/split-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
97 lines (88 loc) · 2.61 KB
/
Copy pathroute.ts
File metadata and controls
97 lines (88 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { NextRequest, NextResponse } from "next/server";
/**
* PATCH /api/invoices/bulk
*
* Bulk operation endpoint for archive, delete, and tag operations.
* Accepts up to 200 invoice IDs per request.
*
* Request body:
* - invoiceIds: string[] (required)
* - action: 'archive' | 'delete' | 'tag' (required)
* - archived?: boolean (for archive action)
* - tags?: string[] (for tag action)
*/
export async function PATCH(request: NextRequest) {
try {
const body = await request.json();
const { invoiceIds, action, archived, tags } = body as {
invoiceIds: string[];
action: string;
archived?: boolean;
tags?: string[];
};
// Validate inputs
if (!Array.isArray(invoiceIds) || invoiceIds.length === 0) {
return NextResponse.json(
{ error: "invoiceIds must be a non-empty array" },
{ status: 400 },
);
}
if (invoiceIds.length > 200) {
return NextResponse.json(
{ error: "Maximum 200 invoices per request" },
{ status: 400 },
);
}
if (!["archive", "delete", "tag"].includes(action)) {
return NextResponse.json(
{ error: "action must be 'archive', 'delete', or 'tag'" },
{ status: 400 },
);
}
if (action === "archive" && typeof archived !== "boolean") {
return NextResponse.json(
{ error: "archived must be a boolean for archive action" },
{ status: 400 },
);
}
if (action === "tag" && !Array.isArray(tags)) {
return NextResponse.json(
{ error: "tags must be an array for tag action" },
{ status: 400 },
);
}
// TODO: Implement actual database operations
// For now, validate the request and return success.
// In production:
// - archive: Update archived status in database
// - delete: Mark invoices as deleted or remove them
// - tag: Apply tags to invoices
let message = "";
switch (action) {
case "archive":
message = `${invoiceIds.length} invoices ${archived ? "archived" : "unarchived"}`;
break;
case "delete":
message = `${invoiceIds.length} invoices deleted`;
break;
case "tag":
message = `${invoiceIds.length} invoices tagged with: ${tags?.join(", ")}`;
break;
}
return NextResponse.json(
{
success: true,
count: invoiceIds.length,
action,
message,
},
{ status: 200 },
);
} catch (error) {
console.error("Bulk invoice operation error:", error);
return NextResponse.json(
{ error: "Failed to process bulk operation" },
{ status: 500 },
);
}
}