Init commit!
This commit is contained in:
commit
086d682592
34 changed files with 19249 additions and 0 deletions
29
server/api/transactions/[id].delete.js
Normal file
29
server/api/transactions/[id].delete.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { getCollection } from '../../utils/db.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const id = getRouterParam(event, 'id')
|
||||
const collection = await getCollection('transactions')
|
||||
|
||||
// Delete the transaction
|
||||
const result = await collection.deleteOne({ _id: id })
|
||||
|
||||
if (result.deletedCount === 0) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Transaction not found'
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
deletedCount: result.deletedCount
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting transaction:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to delete transaction'
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue