Skip to content

Commit

Permalink
fix: rename snapshot, closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 9, 2024
1 parent 2819a54 commit 9b3e5f7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/app/server/api/snapshots/[snapshotId]/index.patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import SuperJSON from 'superjson'

export default defineEventHandler(async (event) => {
const mq = getMq()
const { snapshotId } = getRouterParams(event, {
decode: true,
}) as {
snapshotId: string
}
const { id, location, description, tags } = await readBody(event)
const storage = await getSnapshotStorage(mq)
const snapshot = await storage.findById(id)
const snapshot = await storage.findById(snapshotId)
if (!snapshot) {
throw new Error(`Snapshot ${id} not found`)
throw new Error(`Snapshot ${snapshotId} not found`)
}

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

// Rename

if (snapshot.id !== id) {
await storage.remove(snapshot.id)
}

// Update in storage

Object.assign(snapshot, {
id,
location,
description,
tags,
Expand Down

0 comments on commit 9b3e5f7

Please sign in to comment.