-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathadmin.api.v1.feature-flags.ts
More file actions
43 lines (38 loc) · 1.29 KB
/
admin.api.v1.feature-flags.ts
File metadata and controls
43 lines (38 loc) · 1.29 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
import { ActionFunctionArgs, json } from "@remix-run/server-runtime";
import { prisma } from "~/db.server";
import { requireAdminApiRequest } from "~/services/personalAccessToken.server";
import { makeSetMultipleFlags } from "~/v3/featureFlags.server";
import { validatePartialFeatureFlags } from "~/v3/featureFlags";
export async function action({ request }: ActionFunctionArgs) {
await requireAdminApiRequest(request);
try {
// Parse the request body
const body = await request.json();
// Validate the input using the partial schema
const validationResult = validatePartialFeatureFlags(body as Record<string, unknown>);
if (!validationResult.success) {
return json(
{
error: "Invalid feature flags data",
details: validationResult.error.issues,
},
{ status: 400 }
);
}
const featureFlags = validationResult.data;
const setMultipleFlags = makeSetMultipleFlags(prisma);
const updatedFlags = await setMultipleFlags(featureFlags);
return json({
success: true,
updatedFlags,
message: `Updated ${updatedFlags.length} feature flag(s)`,
});
} catch (error) {
return json(
{
error: error instanceof Error ? error.message : String(error),
},
{ status: 400 }
);
}
}