Skip to content

Commit ce35ae3

Browse files
authored
🍁 [Backend] Create Get Testimonial API (#1035)
1 parent 70d21f4 commit ce35ae3

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

β€Žbackend/app/models/Testimonial.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const mongoose = require('mongoose');
2+
3+
const { Schema } = mongoose;
4+
5+
const testimonialSchema = new Schema(
6+
{
7+
name: {
8+
type: String,
9+
required: true,
10+
},
11+
position: {
12+
type: String,
13+
required: true,
14+
},
15+
company: {
16+
type: String,
17+
required: true,
18+
},
19+
image: {
20+
type: String,
21+
required: true,
22+
},
23+
text: {
24+
type: String,
25+
required: true,
26+
},
27+
rating: {
28+
type: Number,
29+
required: true,
30+
},
31+
},
32+
{ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' } }
33+
);
34+
35+
module.exports = mongoose.model('Testimonial', testimonialSchema, 'testimonials');

β€Žbackend/app/routes/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const question = require('./Q&A/question');
1111
const answer = require('./Q&A/answers');
1212
const teamMember = require('./teamMember');
1313
const resource = require('./resources');
14+
const testimonial = require('./testimonial');
1415

1516
router.use('/admin', admin);
1617
router.use('/auth', auth);
@@ -24,4 +25,5 @@ router.use('/joinUs', joinUs);
2425
router.use('/teamMember', teamMember);
2526
router.use('/', tinyURL);
2627
router.use('/resources', resource);
28+
router.use('/testimonials', testimonial);
2729
module.exports = router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const to = require('await-to-js').default;
2+
const Testimonial = require('../../models/Testimonial');
3+
const constants = require('../../../constants');
4+
const { ErrorHandler } = require('../../../helpers/error');
5+
6+
module.exports = async (req, res, next) => {
7+
const [err, response] = await to(Testimonial.find());
8+
if (err) {
9+
const error = new ErrorHandler(constants.ERRORS.DATABASE, {
10+
statusCode: 500,
11+
message: 'Mongo Error: Fetching Failed',
12+
errStack: err,
13+
});
14+
return next(error);
15+
}
16+
17+
res.status(200).json(response);
18+
return next();
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const router = require('express').Router({ mergeParams: true });
2+
3+
const getTestimonials = require('./getTestimonials');
4+
5+
router.get('/getTestimonials', getTestimonials);
6+
7+
module.exports = router;

0 commit comments

Comments
Β (0)