feat: add rebuild machine option

This commit is contained in:
BennyKok
2024-01-12 18:56:02 +08:00
parent 2ff19f53d0
commit b8e478c8ee
2 changed files with 51 additions and 10 deletions
+29 -3
View File
@@ -113,7 +113,7 @@ export const updateCustomMachine = withServerPromise(
.where(eq(machinesTable.id, id));
// Perform custom build if there are changes
await buildMachine(data, currentMachine);
await _buildMachine(data, currentMachine);
redirect(`/machines/${id}`);
} else {
revalidatePath("/machines");
@@ -123,6 +123,32 @@ export const updateCustomMachine = withServerPromise(
}
);
export const buildMachine = withServerPromise(
async ({ id }: { id: string }) => {
const { userId } = auth();
if (!userId) return { error: "No user id" };
const currentMachine = await db.query.machinesTable.findFirst({
where: eq(machinesTable.id, id),
});
if (!currentMachine) return { error: "Machine not found" };
const datas = await db
.update(machinesTable)
.set({
status: "building",
endpoint: "not-ready",
})
.where(eq(machinesTable.id, id))
.returning();
// Perform custom build if there are changes
await _buildMachine(datas[0], currentMachine);
redirect(`/machines/${id}`);
}
);
export const addCustomMachine = withServerPromise(
async (data: z.infer<typeof addCustomMachineSchema>) => {
const { userId, orgId } = auth();
@@ -143,14 +169,14 @@ export const addCustomMachine = withServerPromise(
const b = a[0];
await buildMachine(data, b);
await _buildMachine(data, b);
redirect(`/machines/${b.id}`);
// revalidatePath("/machines");
return { message: "Machine Building" };
}
);
async function buildMachine(
async function _buildMachine(
data: z.infer<typeof addCustomMachineSchema>,
b: MachineType
) {