Skip to content

Commit

Permalink
🍁 [Backend] Create Get Testimonial API (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgaur99 authored Jun 10, 2024
1 parent 70d21f4 commit ce35ae3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
35 changes: 35 additions & 0 deletions backend/app/models/Testimonial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mongoose = require('mongoose');

const { Schema } = mongoose;

const testimonialSchema = new Schema(
{
name: {
type: String,
required: true,
},
position: {
type: String,
required: true,
},
company: {
type: String,
required: true,
},
image: {
type: String,
required: true,
},
text: {
type: String,
required: true,
},
rating: {
type: Number,
required: true,
},
},
{ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' } }
);

module.exports = mongoose.model('Testimonial', testimonialSchema, 'testimonials');
2 changes: 2 additions & 0 deletions backend/app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const question = require('./Q&A/question');
const answer = require('./Q&A/answers');
const teamMember = require('./teamMember');
const resource = require('./resources');
const testimonial = require('./testimonial');

router.use('/admin', admin);
router.use('/auth', auth);
Expand All @@ -24,4 +25,5 @@ router.use('/joinUs', joinUs);
router.use('/teamMember', teamMember);
router.use('/', tinyURL);
router.use('/resources', resource);
router.use('/testimonials', testimonial);
module.exports = router;
19 changes: 19 additions & 0 deletions backend/app/routes/testimonial/getTestimonials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const to = require('await-to-js').default;
const Testimonial = require('../../models/Testimonial');
const constants = require('../../../constants');
const { ErrorHandler } = require('../../../helpers/error');

module.exports = async (req, res, next) => {
const [err, response] = await to(Testimonial.find());
if (err) {
const error = new ErrorHandler(constants.ERRORS.DATABASE, {
statusCode: 500,
message: 'Mongo Error: Fetching Failed',
errStack: err,
});
return next(error);
}

res.status(200).json(response);
return next();
};
7 changes: 7 additions & 0 deletions backend/app/routes/testimonial/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const router = require('express').Router({ mergeParams: true });

const getTestimonials = require('./getTestimonials');

router.get('/getTestimonials', getTestimonials);

module.exports = router;

0 comments on commit ce35ae3

Please sign in to comment.