Refactoring 2

This commit is contained in:
Darren Clarke 2024-04-30 11:39:16 +02:00
parent dd14dfe72e
commit e4b78ceec2
76 changed files with 870 additions and 734 deletions

View file

@ -0,0 +1,72 @@
import { Database } from "bridge-common";
import {
createAction,
updateAction,
deleteAction,
selectAllAction,
} from "../actions/service";
import { FieldDescription, Entity } from "./service";
type GenerateCreateActionArgs = {
entity: Entity;
table: keyof Database;
fields: FieldDescription[];
};
export function generateCreateAction({
entity,
table,
fields,
}: GenerateCreateActionArgs) {
return async (currentState: any, formData: FormData) => {
return createAction({
entity,
table,
fields,
currentState,
formData,
});
};
}
type GenerateUpdateActionArgs = {
entity: Entity;
table: keyof Database;
fields: FieldDescription[];
};
export function generateUpdateAction({
entity,
table,
fields,
}: GenerateUpdateActionArgs) {
return async (currentState: any, formData: FormData) => {
return updateAction({
entity,
table,
fields,
currentState,
formData,
});
};
}
type GenerateDeleteActionArgs = {
entity: Entity;
table: keyof Database;
};
export function generateDeleteAction({
entity,
table,
}: GenerateDeleteActionArgs) {
return async (id: string) => {
return deleteAction({ entity, table, id });
};
}
export function generateSelectAllAction(table: keyof Database) {
return async () => {
return selectAllAction(table);
};
}