-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π [Backend] Create Get Testimonial API (#1035)
- Loading branch information
1 parent
70d21f4
commit ce35ae3
Showing
4 changed files
with
63 additions
and
0 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 |
---|---|---|
@@ -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'); |
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,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(); | ||
}; |
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,7 @@ | ||
const router = require('express').Router({ mergeParams: true }); | ||
|
||
const getTestimonials = require('./getTestimonials'); | ||
|
||
router.get('/getTestimonials', getTestimonials); | ||
|
||
module.exports = router; |