mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
delete backup.
This commit is contained in:
@@ -4,7 +4,47 @@ import {userAction} from "@/safe-actions";
|
||||
import {z} from "zod";
|
||||
import {prisma} from "@/prisma";
|
||||
import {ServerActionResult} from "@/types/action-type";
|
||||
import {Restoration} from "@prisma/client";
|
||||
import {Backup, Restoration} from "@prisma/client";
|
||||
|
||||
|
||||
export const deleteBackupAction = userAction
|
||||
.schema(z.object({
|
||||
backupId: z.string(),
|
||||
databaseId: z.string(),
|
||||
}))
|
||||
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Backup>> => {
|
||||
|
||||
try {
|
||||
const backupDeleted = await prisma.backup.delete({
|
||||
where:{
|
||||
databaseId: parsedInput.databaseId,
|
||||
id: parsedInput.backupId
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
value: backupDeleted,
|
||||
actionSuccess: {
|
||||
message: "Backup has been successfully deleted.",
|
||||
messageParams: {message: "success"},
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error deleting backup:", error);
|
||||
return {
|
||||
success: false,
|
||||
actionError: {
|
||||
message: "Failed to delete backup.",
|
||||
status: 500,
|
||||
cause: error instanceof Error ? error.message : "Unknown error",
|
||||
messageParams: {message: "Error deleting the backup"},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
export const createRestorationAction = userAction
|
||||
@@ -28,7 +68,7 @@ export const createRestorationAction = userAction
|
||||
value: restoration,
|
||||
actionSuccess: {
|
||||
message: "Restoration has been successfully created.",
|
||||
messageParams: { restorationId: restoration.id },
|
||||
messageParams: {restorationId: restoration.id},
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -39,11 +79,10 @@ export const createRestorationAction = userAction
|
||||
message: "Failed to create backup.",
|
||||
status: 500,
|
||||
cause: error instanceof Error ? error.message : "Unknown error",
|
||||
messageParams: { message: "Error creating the restoration" },
|
||||
messageParams: {message: "Error creating the restoration"},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user