-
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.
🍁 Refactor Resource Form: Create new broadcast upon successful resour…
…ce form submission (#1031) * Refactor Resource Form: Create new broadcast upon successful resource form submission * Refactor Resource Form: Create new broadcast upon successful resource form submission * Refactor Resource Form: Create new broadcast upon successful resource form submission * Refactor Resource Form: Create new broadcast upon successful resource form submission
- Loading branch information
1 parent
fe73f78
commit 70d21f4
Showing
18 changed files
with
417 additions
and
952 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 was deleted.
Oops, something went wrong.
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,13 +1,14 @@ | ||
const Joi = require('joi'); | ||
|
||
const ResourcesValidationSchema = Joi.object().keys({ | ||
name: Joi.string().trim().required().min(3), | ||
email: Joi.string().trim().email().required(), | ||
url: Joi.string().trim().required().min(10), | ||
description: Joi.string().trim().required().min(5), | ||
trustLevel: Joi.number().integer().required(), | ||
expiryDate: Joi.date().required(), | ||
additionalInfo: Joi.string().trim().min(5), | ||
const postResourceValidationSchema = Joi.object().keys({ | ||
title: Joi.string().required(), | ||
content: Joi.string().required(), | ||
link: Joi.string().uri().required(), | ||
expiresOn: Joi.date() | ||
.min(new Date(new Date() - 100000)) | ||
.required(), | ||
imageUrl: Joi.array().min(1).items(Joi.string().uri()).required(), | ||
tags: Joi.array().min(1).items(Joi.string()).required(), | ||
}); | ||
|
||
module.exports = ResourcesValidationSchema; | ||
module.exports = postResourceValidationSchema; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,14 +1,9 @@ | ||
const router = require('express').Router({ mergeParams: true }); | ||
const addaResource = require('./addResource'); | ||
const deleteResource = require('./deleteResource'); | ||
const getResource = require('./getResource'); | ||
const postResource = require('./postResource'); | ||
const validation = require('../../../helpers/middlewares/validation'); | ||
const ResourcesValidationSchema = require('./@validationSchema'); | ||
const { authMiddleware } = require('../../../helpers/middlewares/auth'); | ||
const postResourceValidationSchema = require('./@validationSchema'); | ||
|
||
router.post('/', validation(ResourcesValidationSchema), addaResource); | ||
// adding resouce in broadcast schema | ||
router.post('/', validation(postResourceValidationSchema), postResource); | ||
|
||
// Route for deleting a resource | ||
router.delete('/deleteResource', deleteResource); | ||
router.get('/getresources', authMiddleware, getResource); | ||
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 Broadcast = require('../../models/Broadcast'); | ||
const { ErrorHandler } = require('../../../helpers/error'); | ||
const constants = require('../../../constants'); | ||
|
||
module.exports = async (req, res, next) => { | ||
const [err, response] = await to(Broadcast.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: 'Resource added successfully', | ||
response: 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
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.