Init commit!
This commit is contained in:
commit
086d682592
34 changed files with 19249 additions and 0 deletions
40
server/api/transactions/[id].put.js
Normal file
40
server/api/transactions/[id].put.js
Normal 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'
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue