Refactoring
This commit is contained in:
parent
39cfada3e8
commit
dd14dfe72e
41 changed files with 866 additions and 742 deletions
|
|
@ -28,6 +28,7 @@ export const createAction = async ({
|
|||
currentState,
|
||||
formData,
|
||||
}: CreateActionArgs) => {
|
||||
console.log(formData);
|
||||
const newRecord = fields.reduce(
|
||||
(acc: Record<string, any>, field: FieldDescription) => {
|
||||
if (field.autogenerated === "token") {
|
||||
|
|
@ -41,13 +42,19 @@ export const createAction = async ({
|
|||
{},
|
||||
);
|
||||
|
||||
await db.insertInto(table).values(newRecord).execute();
|
||||
console.log({ newRecord });
|
||||
const record = await db
|
||||
.insertInto(table)
|
||||
.values(newRecord)
|
||||
.returning(["id"])
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
console.log({ record });
|
||||
revalidatePath(`/${entity}`);
|
||||
|
||||
return {
|
||||
...currentState,
|
||||
values: newRecord,
|
||||
values: { ...newRecord, id: record.id },
|
||||
success: true,
|
||||
};
|
||||
};
|
||||
|
|
@ -104,3 +111,7 @@ export const deleteAction = async ({ entity, table, id }: DeleteActionArgs) => {
|
|||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const selectAllAction = async (table: keyof Database) => {
|
||||
return db.selectFrom(table).selectAll().execute();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue