feat: created donation api and linked to donations page#111
feat: created donation api and linked to donations page#111
Conversation
| @@ -0,0 +1,34 @@ | |||
| import prisma from '~~/server/utils/prisma' | |||
| import { getRouterParam } from 'h3' | |||
There was a problem hiding this comment.
We don't need this import, it can be removed
There was a problem hiding this comment.
you should make these two seperate files: index.put.ts and index.delete.ts, but otherwise looks good.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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')) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
Following from line 37, use the same randomly generated unique filename
| if (event.method === 'GET') { | ||
| return prisma.donation.findMany({ orderBy: { createdAt: 'desc' } }) | ||
| } | ||
|
|
There was a problem hiding this comment.
Make two different files for the two methods: index.get.ts and index.post.ts
| > 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`: |
There was a problem hiding this comment.
LOL revert this one maybe
There was a problem hiding this comment.
Since we have merge conflicts with this file, use the following steps:
- Delete node_modules
- Delete the pnpm-lock.yaml
- run
pnpm install
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.
