Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Avatar Component #359

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO_URI=your_mongodb_uri
PORT=5000
41 changes: 41 additions & 0 deletions backend/controllers/donationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { z } = require('zod');
const Donation = require('../models/donation.model.js');

const donationSchema = z.object({
amount: z
.string()
.regex(/^\d+$/, { message: 'Amount must be a number' })
.min(1, { message: 'Amount is required' }),
name: z.string().min(1, { message: 'Name is required' }),
email: z.string().email({ message: 'Invalid email format' }),
});

async function createDonation(req, res) {
try {
const validationResult = donationSchema.safeParse(req.body);
if (!validationResult.success) {
return res.status(400).json({
success: false,
message: 'Validation failed',
errors: validationResult.error.errors,
});
}

const donationData = validationResult.data;
const donation = await Donation.create(donationData);

res.status(201).json({
success: true,
message: 'Donation recorded successfully',
data: donation,
});
} catch (error) {
res.status(500).json({
success: false,
message: 'An error occurred while recording the donation',
error: error.message,
});
}
}

module.exports = { createDonation };
25 changes: 25 additions & 0 deletions backend/models/donation.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require('mongoose');

const donationSchema = new mongoose.Schema({
amount: {
type: Number,
required: true,
},
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
match: [/^\S+@\S+\.\S+$/, 'Invalid email format'],
},
createdAt: {
type: Date,
default: Date.now,
},
});

const Donation = mongoose.model('Donation', donationSchema);

module.exports = Donation;
36 changes: 36 additions & 0 deletions backend/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions backend/node_modules/cors/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions backend/node_modules/cors/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions backend/node_modules/cors/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading