-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a946e5
commit 8058502
Showing
52 changed files
with
854 additions
and
748 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
const to = require("await-to-js").default; | ||
const to = require('await-to-js').default; | ||
|
||
const constants = require("../../../../constants"); | ||
const { ErrorHandler } = require("../../../../helpers/error"); | ||
const constants = require('../../../../constants'); | ||
const { ErrorHandler } = require('../../../../helpers/error'); | ||
|
||
const answers = require("../../../models/answers"); | ||
const answers = require('../../../models/answers'); | ||
|
||
module.exports = async (req, res, next) => { | ||
// getting id and status from body | ||
const id = req.body.id; | ||
const status = req.body.status | ||
|
||
// query fro updating | ||
const [ err, result ] = await to(answers.findOneAndUpdate({ _id : id }, { $set : { isApproved : status } })); | ||
|
||
// error occured due to the some problem | ||
if(err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Database Error', | ||
errStack: err, | ||
}); | ||
|
||
return next(error); | ||
} | ||
|
||
// if result is null that means answer with given id is not exist in collection | ||
if(result === null) { | ||
const answerNotExistError = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: 'Answer Not Exist...', | ||
}); | ||
|
||
return next(answerNotExistError); | ||
} | ||
|
||
// success response | ||
res.status(200).send({ | ||
message : "Status Updated..." | ||
// getting id and status from body | ||
const { id } = req.body; | ||
const { status } = req.body; | ||
|
||
// query fro updating | ||
const [err, result] = await to(answers.findOneAndUpdate({ _id: id }, { $set: { isApproved: status } })); | ||
Check failure Code scanning / CodeQL Database query built from user-controlled sources High
This query object depends on a
user-provided value Error loading related location Loading |
||
|
||
// error occured due to the some problem | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Database Error', | ||
errStack: err, | ||
}); | ||
|
||
return next(); | ||
} | ||
return next(error); | ||
} | ||
|
||
// if result is null that means answer with given id is not exist in collection | ||
if (result === null) { | ||
const answerNotExistError = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: 'Answer Not Exist...', | ||
}); | ||
|
||
return next(answerNotExistError); | ||
} | ||
|
||
// success response | ||
res.status(200).send({ | ||
message: 'Status Updated...', | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
const to = require("await-to-js").default; | ||
const to = require('await-to-js').default; | ||
|
||
const constants = require("../../../../constants"); | ||
const { ErrorHandler } = require("../../../../helpers/error"); | ||
const constants = require('../../../../constants'); | ||
const { ErrorHandler } = require('../../../../helpers/error'); | ||
|
||
const question = require("../../../models/question"); | ||
const question = require('../../../models/question'); | ||
|
||
module.exports = async (req, res, next) => { | ||
// getting id and status from body | ||
const id = req.body.id; | ||
const status = req.body.status | ||
|
||
// query fro updating | ||
const [ err, result ] = await to(question.findOneAndUpdate({ _id : id }, { $set : { isApproved : status } })); | ||
|
||
// error occured due to the some problem | ||
if(err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Database Error', | ||
errStack: err, | ||
}); | ||
|
||
return next(error); | ||
} | ||
|
||
// if result is null that means question with given id is not exist in collection | ||
if(result === null) { | ||
const questionNotExistsError = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: 'Question Not Exist...', | ||
}); | ||
|
||
return next(questionNotExistsError); | ||
} | ||
|
||
// success response | ||
res.status(200).send({ | ||
message : "Status Updated..." | ||
// getting id and status from body | ||
const { id } = req.body; | ||
const { status } = req.body; | ||
|
||
// query fro updating | ||
const [err, result] = await to(question.findOneAndUpdate({ _id: id }, { $set: { isApproved: status } })); | ||
Check failure Code scanning / CodeQL Database query built from user-controlled sources High
This query object depends on a
user-provided value Error loading related location Loading |
||
|
||
// error occured due to the some problem | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Database Error', | ||
errStack: err, | ||
}); | ||
|
||
return next(); | ||
} | ||
return next(error); | ||
} | ||
|
||
// if result is null that means question with given id is not exist in collection | ||
if (result === null) { | ||
const questionNotExistsError = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: 'Question Not Exist...', | ||
}); | ||
|
||
return next(questionNotExistsError); | ||
} | ||
|
||
// success response | ||
res.status(200).send({ | ||
message: 'Status Updated...', | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
const { default: to } = require("await-to-js"); | ||
const constants = require("../../../constants"); | ||
const { ErrorHandler } = require("../../../helpers/error"); | ||
const Admin = require("../../models/Admin"); | ||
const { default: to } = require('await-to-js'); | ||
const constants = require('../../../constants'); | ||
const { ErrorHandler } = require('../../../helpers/error'); | ||
const Admin = require('../../models/Admin'); | ||
|
||
module.exports = async (req, res, next) => { | ||
const { isSuperAdmin } = res.locals.decode; | ||
const { isSuperAdmin } = res.locals.decode; | ||
|
||
if(!isSuperAdmin) { | ||
const error = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 401, | ||
message: 'Unauthorized Request: Not a superAdmin', | ||
user: req.body.email, | ||
}); | ||
if (!isSuperAdmin) { | ||
const error = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 401, | ||
message: 'Unauthorized Request: Not a superAdmin', | ||
user: req.body.email, | ||
}); | ||
|
||
return next(error); | ||
} | ||
return next(error); | ||
} | ||
|
||
const id = req.body.id; | ||
const { id } = req.body; | ||
|
||
const [err, admin] = await to(Admin.findByIdAndDelete(id)); | ||
const [err, admin] = await to(Admin.findByIdAndDelete(id)); | ||
Check failure Code scanning / CodeQL Database query built from user-controlled sources High
This query object depends on a
user-provided value Error loading related location Loading |
||
|
||
if (!admin) { | ||
const error = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: "Admin doesn't exist", | ||
}); | ||
if (!admin) { | ||
const error = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: "Admin doesn't exist", | ||
}); | ||
|
||
return next(error); | ||
} | ||
return next(error); | ||
} | ||
|
||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Mongo Error: Deletion Failed', | ||
errStack: err, | ||
}); | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Mongo Error: Deletion Failed', | ||
errStack: err, | ||
}); | ||
|
||
return next(error); | ||
} | ||
return next(error); | ||
} | ||
|
||
return res.status(200).send({ | ||
message: 'Admin deleted successfully', | ||
}); | ||
} | ||
return res.status(200).send({ | ||
message: 'Admin deleted successfully', | ||
}); | ||
}; |
Oops, something went wrong.