Init commit!

This commit is contained in:
Jennie Robinson Faber 2025-08-22 18:36:16 +01:00
commit 086d682592
34 changed files with 19249 additions and 0 deletions

View file

@ -0,0 +1,40 @@
import { getCollection } from '../../utils/db.js'
export default defineEventHandler(async (event) => {
try {
const id = getRouterParam(event, 'id')
const body = await readBody(event)
const collection = await getCollection('transactions')
// Update document
const updateData = {
...body,
_id: id,
id: undefined,
updatedAt: new Date()
}
const result = await collection.replaceOne(
{ _id: id },
updateData
)
if (result.matchedCount === 0) {
throw createError({
statusCode: 404,
statusMessage: 'Transaction not found'
})
}
return {
success: true,
modifiedCount: result.modifiedCount
}
} catch (error) {
console.error('Error updating transaction:', error)
throw createError({
statusCode: 500,
statusMessage: 'Failed to update transaction'
})
}
})