Init commit!
This commit is contained in:
commit
086d682592
34 changed files with 19249 additions and 0 deletions
23
server/api/transactions/index.get.js
Normal file
23
server/api/transactions/index.get.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { getCollection } from '../../utils/db.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const collection = await getCollection('transactions')
|
||||
const transactions = await collection.find({}).toArray()
|
||||
|
||||
// Convert MongoDB _id to id for frontend compatibility
|
||||
const formattedTransactions = transactions.map(transaction => ({
|
||||
...transaction,
|
||||
id: transaction._id.toString(),
|
||||
_id: undefined
|
||||
}))
|
||||
|
||||
return formattedTransactions
|
||||
} catch (error) {
|
||||
console.error('Error fetching transactions:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to fetch transactions'
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue