File tree 4 files changed +63
-0
lines changed
4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
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' ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const question = require('./Q&A/question');
11
11
const answer = require ( './Q&A/answers' ) ;
12
12
const teamMember = require ( './teamMember' ) ;
13
13
const resource = require ( './resources' ) ;
14
+ const testimonial = require ( './testimonial' ) ;
14
15
15
16
router . use ( '/admin' , admin ) ;
16
17
router . use ( '/auth' , auth ) ;
@@ -24,4 +25,5 @@ router.use('/joinUs', joinUs);
24
25
router . use ( '/teamMember' , teamMember ) ;
25
26
router . use ( '/' , tinyURL ) ;
26
27
router . use ( '/resources' , resource ) ;
28
+ router . use ( '/testimonials' , testimonial ) ;
27
29
module . exports = router ;
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 ;
You canβt perform that action at this time.
0 commit comments