link-stack/apps/bridge-frontend/app/_lib/actions.ts

75 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-26 14:31:33 +02:00
import { Database } from "./database";
import { FieldDescription, Entity } from "./service";
import {
createAction,
updateAction,
deleteAction,
2024-04-29 17:27:25 +02:00
selectAllAction,
2024-04-26 14:31:33 +02:00
} from "@/app/_actions/service";
2024-04-25 12:31:03 +02:00
2024-04-26 14:31:33 +02:00
type GenerateCreateActionArgs = {
entity: Entity;
2024-04-25 12:31:03 +02:00
table: keyof Database;
2024-04-26 14:31:33 +02:00
fields: FieldDescription[];
2024-04-25 12:31:03 +02:00
};
2024-04-26 14:31:33 +02:00
export function generateCreateAction({
2024-04-25 12:31:03 +02:00
entity,
table,
fields,
2024-04-26 14:31:33 +02:00
}: GenerateCreateActionArgs) {
return async (currentState: any, formData: FormData) => {
2024-04-29 17:27:25 +02:00
console.log({ entity, table, fields });
console.log({ currentState, formData });
2024-04-26 14:31:33 +02:00
return createAction({
entity,
table,
fields,
currentState,
formData,
});
2024-04-25 12:31:03 +02:00
};
2024-04-26 14:31:33 +02:00
}
2024-04-25 12:31:03 +02:00
2024-04-26 14:31:33 +02:00
type GenerateUpdateActionArgs = {
entity: Entity;
2024-04-25 12:31:03 +02:00
table: keyof Database;
2024-04-26 14:31:33 +02:00
fields: FieldDescription[];
2024-04-25 12:31:03 +02:00
};
2024-04-26 14:31:33 +02:00
export function generateUpdateAction({
2024-04-25 12:31:03 +02:00
entity,
table,
fields,
2024-04-26 14:31:33 +02:00
}: GenerateUpdateActionArgs) {
return async (currentState: any, formData: FormData) => {
return updateAction({
entity,
table,
fields,
currentState,
formData,
});
2024-04-25 12:31:03 +02:00
};
2024-04-26 14:31:33 +02:00
}
2024-04-25 12:31:03 +02:00
2024-04-26 14:31:33 +02:00
type GenerateDeleteActionArgs = {
entity: Entity;
2024-04-25 12:31:03 +02:00
table: keyof Database;
};
2024-04-26 14:31:33 +02:00
export function generateDeleteAction({
entity,
table,
}: GenerateDeleteActionArgs) {
return async (id: string) => {
return deleteAction({ entity, table, id });
};
}
2024-04-29 17:27:25 +02:00
export function generateSelectAllAction(table: keyof Database) {
return async () => {
return selectAllAction(table);
};
}