Skip to content

feat: created donation api and linked to donations page#111

Open
KF212132 wants to merge 5 commits intospring26from
donationapi
Open

feat: created donation api and linked to donations page#111
KF212132 wants to merge 5 commits intospring26from
donationapi

Conversation

@KF212132
Copy link
Copy Markdown
Collaborator

Created a donation api and linked it to the donations page. All of the text-based information is working, but there are issues with the images. I also need to fix the button.
donation api

@KF212132 KF212132 linked an issue Mar 26, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@Vikachubro21 Vikachubro21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got this

@@ -0,0 +1,34 @@
import prisma from '~~/server/utils/prisma'
import { getRouterParam } from 'h3'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this import, it can be removed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should make these two seperate files: index.put.ts and index.delete.ts, but otherwise looks good.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is only one image per donation, should we have a name for the image? (ik when we're storing it, it has a file name, but we dont actually need that when trying to fetch the image). Another thing, you're not actually accessing the imageUrl field (which is where we store the filepath actually) from the donation table. Might want to look into this some

throw createError({ statusCode: 404, message: 'Donation not found' })
}

const dirPath = path.join(process.env.IMAGE_STORAGE_PATH || 'public/images', id)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id in theory can be anything. Since we don't know what it's for, I'd recommend storing it at IMAGE_STORAGE_PATH/donations/[id]

fs.mkdirSync(dirPath, { recursive: true })
}

const filePath = path.join(dirPath, decodeURIComponent(file.filename || 'image.png'))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the example on the other post method, generate a unique filename, we dont actually need to store the name of the file anywhere


fs.writeFileSync(filePath, file.data)

const imageUrl = path.join(id, file.filename || 'image.png')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following from line 37, use the same randomly generated unique filename

Comment thread server/api/admin/donations/index.ts Outdated
if (event.method === 'GET') {
return prisma.donation.findMany({ orderBy: { createdAt: 'desc' } })
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make two different files for the two methods: index.get.ts and index.post.ts

Comment thread README.md Outdated
> However, if any errors show up, they must be resolved.

Start the development server on `http://localhost:3000`:
Start the development server on `http://localhosnt:3000`:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL revert this one maybe

Comment thread pnpm-lock.yaml
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have merge conflicts with this file, use the following steps:

  1. Delete node_modules
  2. Delete the pnpm-lock.yaml
  3. run pnpm install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Create and fetch donation funds

2 participants