-
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.
Merge branch 'HITK-TECH-Community:main' into admin-profile-validation
- Loading branch information
Showing
22 changed files
with
1,239 additions
and
10 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
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,22 @@ | ||
const Joi = require('joi'); | ||
|
||
const postTestimonialValidationSchema = Joi.object().keys({ | ||
name: Joi.string().required(), | ||
position: Joi.string().required(), | ||
company: Joi.string().required(), | ||
image: Joi.string().uri().required(), | ||
text: Joi.string().required(), | ||
rating: Joi.number().min(1).max(5).required(), | ||
}); | ||
|
||
const getTestimonialsValidationSchema = Joi.object().keys({ | ||
page: Joi.number().min(1).optional(), | ||
company: Joi.string().optional(), | ||
year: Joi.number().optional(), | ||
month: Joi.number().min(1).max(12).optional(), | ||
}); | ||
|
||
module.exports = { | ||
postTestimonialValidationSchema, | ||
getTestimonialsValidationSchema, | ||
}; |
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,27 @@ | ||
const to = require('await-to-js').default; | ||
const Testimonial = require('../../models/Testimonial'); | ||
const { ErrorHandler } = require('../../../helpers/error'); | ||
const constants = require('../../../constants'); | ||
|
||
module.exports = async (req, res, next) => { | ||
const [err, testimonial] = await to(Testimonial.findByIdAndDelete(req.params.id)); | ||
if (!testimonial) { | ||
const error = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: "Testimonial doesn't exist", | ||
}); | ||
return next(error); | ||
} | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Mongo Error: Deletion Failed', | ||
errStack: err, | ||
}); | ||
return next(error); | ||
} | ||
res.status(200).send({ | ||
message: 'Testimonial deleted successfully', | ||
}); | ||
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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
const router = require('express').Router({ mergeParams: true }); | ||
const validationMiddleware = require('../../../helpers/middlewares/validation'); | ||
const { authMiddleware } = require('../../../helpers/middlewares/auth'); | ||
|
||
const { postTestimonialValidationSchema } = require('./@validationSchema'); | ||
const postTestimonial = require('./postTestimonial'); | ||
const getTestimonials = require('./getTestimonials'); | ||
const deleteTestimonial = require('./deleteTestimonial'); | ||
|
||
router.post('/', validationMiddleware(postTestimonialValidationSchema), authMiddleware, postTestimonial); | ||
router.get('/getTestimonials', getTestimonials); | ||
router.delete('/:id', authMiddleware, deleteTestimonial); | ||
|
||
module.exports = router; |
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,21 @@ | ||
const to = require('await-to-js').default; | ||
const Testimonial = require('../../models/Testimonial'); | ||
const { ErrorHandler } = require('../../../helpers/error'); | ||
const constants = require('../../../constants'); | ||
|
||
module.exports = async (req, res, next) => { | ||
const [err, { _id }] = await to(Testimonial.create({ ...req.body })); | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Mongo Error: Insertion Failed', | ||
errStack: err, | ||
}); | ||
return next(error); | ||
} | ||
res.status(200).send({ | ||
message: 'Testimonial added successfully', | ||
id: _id, | ||
}); | ||
return next(); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
Oops, something went wrong.