Skip to content

[ Backend ]Create Get Testimonial API #1035

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

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
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;
Loading