first commit

This commit is contained in:
mstfyldz
2026-03-24 15:46:27 +03:00
parent 095d830279
commit 34b6a46604
33 changed files with 5212 additions and 81 deletions

48
app/config/actions.ts Normal file
View File

@@ -0,0 +1,48 @@
"use server";
import { db } from "@/db";
import { remoteConfig } from "@/db/schema";
import { eq, and } from "drizzle-orm";
/** Fetch all active config entries for a given app */
export async function getAppConfigs(appId: number) {
return await db.query.remoteConfig.findMany({
where: eq(remoteConfig.appId, appId),
orderBy: (rc, { asc }) => [asc(rc.configKey)],
});
}
/**
* Insert or update a config key for an app.
* If the key already exists for this appId, it is overwritten.
*/
export async function upsertConfig(
appId: number,
key: string,
value: unknown
) {
const existing = await db.query.remoteConfig.findFirst({
where: and(
eq(remoteConfig.appId, appId),
eq(remoteConfig.configKey, key)
),
});
if (existing) {
await db
.update(remoteConfig)
.set({ configValue: value, updatedAt: new Date() })
.where(eq(remoteConfig.id, existing.id));
} else {
await db.insert(remoteConfig).values({
appId,
configKey: key,
configValue: value,
});
}
}
/** Delete a config entry by its primary key */
export async function deleteConfig(id: number) {
await db.delete(remoteConfig).where(eq(remoteConfig.id, id));
}