-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Ojas-Arora:main' into rupesh10
- Loading branch information
Showing
23 changed files
with
1,025 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
node_modules | ||
.env | ||
.env | ||
uploads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import mongoose from 'mongoose'; | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
// Database connection | ||
export const dbConnect = async () => { | ||
const url = process.env.MONGO_URI; | ||
|
||
if (!url) { | ||
console.error('No URL received from env. Check .env file path.'); | ||
process.exit(1); | ||
} | ||
|
||
const dbConnect = async () => { | ||
try { | ||
await mongoose.connect(url); | ||
console.log('MongoDB connected'); | ||
} catch (err) { | ||
console.error('Database connection error:', err); | ||
process.exit(1); // Exit process with failure | ||
await mongoose.connect('mongodb://127.0.0.1:27017/scd_profile_db'); | ||
console.log("Database connected successfully!"); | ||
} catch (error) { | ||
console.error("Database connection error:", error); | ||
} | ||
}; | ||
|
||
export default dbConnect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Testimonial from '../models/Testimonial.js'; | ||
|
||
// Add a new testimonial with image upload | ||
const addTestimonial = async (req, res) => { | ||
try { | ||
const { name, profession, review, stars } = req.body; | ||
const image = req.file ? req.file.path : ''; // Save uploaded image path | ||
|
||
const newTestimonial = new Testimonial({ name, profession, review, stars, image }); | ||
await newTestimonial.save(); | ||
|
||
res.status(201).json({ message: 'Testimonial added successfully', testimonial: newTestimonial }); | ||
} catch (error) { | ||
console.error('Error adding testimonial:', error); | ||
res.status(500).json({ error: 'Failed to add testimonial' }); | ||
} | ||
}; | ||
|
||
// Get all testimonials | ||
const getTestimonials = async (req, res) => { | ||
try { | ||
const testimonials = await Testimonial.find(); | ||
res.status(200).json(testimonials); | ||
} catch (error) { | ||
console.error('Error fetching testimonials:', error); | ||
res.status(500).json({ error: 'Failed to fetch testimonials' }); | ||
} | ||
}; | ||
|
||
export { addTestimonial, getTestimonials }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import multer from 'multer'; | ||
import path from 'path'; | ||
|
||
// Configure storage for uploaded files | ||
const storage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
cb(null, 'uploads/'); // Save files to 'uploads' folder | ||
}, | ||
filename: (req, file, cb) => { | ||
cb(null, `${Date.now()}-${file.originalname}`); // Unique filename | ||
}, | ||
}); | ||
|
||
// File type filter (only images allowed) | ||
const fileFilter = (req, file, cb) => { | ||
const allowedTypes = /jpeg|jpg|png/; | ||
const extName = allowedTypes.test(path.extname(file.originalname).toLowerCase()); | ||
const mimeType = allowedTypes.test(file.mimetype); | ||
|
||
if (extName && mimeType) { | ||
return cb(null, true); | ||
} else { | ||
cb(new Error('Only image files are allowed!'), false); | ||
} | ||
}; | ||
|
||
// Initialize multer with storage settings | ||
const upload = multer({ storage, fileFilter }); | ||
|
||
export default upload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
// Testimonial schema | ||
const testimonialSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
profession: { | ||
type: String, | ||
required: true, | ||
}, | ||
review: { | ||
type: String, | ||
required: true, | ||
}, | ||
stars: { | ||
type: Number, | ||
required: true, | ||
min: 1, | ||
max: 5, | ||
}, | ||
image: { | ||
type: String, // Image path | ||
required: false, | ||
}, | ||
createdOn: { | ||
type: Date, | ||
default: Date.now, // Automatically set to the current date and time | ||
}, | ||
}); | ||
|
||
const Testimonial = mongoose.model('Testimonial', testimonialSchema); | ||
export default Testimonial; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import express from 'express'; | ||
import { addTestimonial, getTestimonials } from '../controller/testimonialController.js'; | ||
import upload from '../middleware/upload.js'; // Import multer middleware | ||
|
||
const router = express.Router(); | ||
|
||
// Add a testimonial (with image upload) | ||
router.post('/add', upload.single('image'), addTestimonial); | ||
|
||
// Get all testimonials | ||
router.get('/all', getTestimonials); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const loginForm = document.getElementById('loginForm'); | ||
if (loginForm) { | ||
loginForm.addEventListener('submit', handleLoginSubmit); | ||
} | ||
}); | ||
|
||
function handleLoginSubmit(event) { | ||
event.preventDefault(); // Prevent the default form submission | ||
|
||
const email = document.getElementById('email').value; | ||
const password = document.getElementById('password').value; | ||
|
||
const formData = { email, password }; | ||
|
||
|
||
fetch('http://localhost:3000/api/v1/auth/login', { | ||
|
||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(formData), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.token) { | ||
alert('Login successful!'); | ||
localStorage.setItem('authToken', data.token); | ||
window.location.href = './index.html'; | ||
} else { | ||
alert('Login failed: ' + data.message); | ||
} | ||
}) | ||
.catch(error => console.error('Error:', error)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.