Skip to content

Commit 9b3e5f7

Browse files
committed
fix: rename snapshot, closes #3
1 parent 2819a54 commit 9b3e5f7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/app/server/api/snapshots/[snapshotId]/index.patch.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import SuperJSON from 'superjson'
66

77
export default defineEventHandler(async (event) => {
88
const mq = getMq()
9+
const { snapshotId } = getRouterParams(event, {
10+
decode: true,
11+
}) as {
12+
snapshotId: string
13+
}
914
const { id, location, description, tags } = await readBody(event)
1015
const storage = await getSnapshotStorage(mq)
11-
const snapshot = await storage.findById(id)
16+
const snapshot = await storage.findById(snapshotId)
1217
if (!snapshot) {
13-
throw new Error(`Snapshot ${id} not found`)
18+
throw new Error(`Snapshot ${snapshotId} not found`)
1419
}
1520

1621
// Copy resources
@@ -23,9 +28,16 @@ export default defineEventHandler(async (event) => {
2328
.filter(file => fs.statSync(file).isDirectory())
2429
}
2530

31+
// Rename
32+
33+
if (snapshot.id !== id) {
34+
await storage.remove(snapshot.id)
35+
}
36+
2637
// Update in storage
2738

2839
Object.assign(snapshot, {
40+
id,
2941
location,
3042
description,
3143
tags,

0 commit comments

Comments
 (0)