mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Merge pull request #65 from ohtuprojekti-ilmo/configuration
Configuration
This commit is contained in:
@@ -24,25 +24,20 @@ const returnPopulatedConfiguration = (req, res, unPopulatedConfiguration) => {
|
||||
const setForeignKeys = async (configuration, req, res) => {
|
||||
try {
|
||||
if (req.body.review_question_set_1_id) {
|
||||
db.ReviewQuestionSet.findOne({ where: { id: req.body.review_question_set_1_id } })
|
||||
.then(async foundSet => {
|
||||
if (!foundSet) return res.status(400).json({ error: 'no review question set with that id' })
|
||||
await configuration.setReview_question_set_1(req.body.review_question_set_1_id)
|
||||
})
|
||||
const foundSet = await db.ReviewQuestionSet.findOne({ where: { id: req.body.review_question_set_1_id } })
|
||||
if (!foundSet) return res.status(400).json({ error: 'no review question set with that id' })
|
||||
await configuration.setReview_question_set_1(req.body.review_question_set_1_id)
|
||||
}
|
||||
if (req.body.review_question_set_2_id) {
|
||||
db.ReviewQuestionSet.findOne({ where: { id: req.body.review_question_set_2_id } })
|
||||
.then(async foundSet => {
|
||||
if (!foundSet) return res.status(400).json({ error: 'no review question set with that id' })
|
||||
await configuration.setReview_question_set_2(req.body.review_question_set_2_id)
|
||||
})
|
||||
const foundSet = await db.ReviewQuestionSet.findOne({ where: { id: req.body.review_question_set_2_id } })
|
||||
if (!foundSet) return res.status(400).json({ error: 'no review question set with that id' })
|
||||
await configuration.setReview_question_set_2(req.body.review_question_set_2_id)
|
||||
|
||||
}
|
||||
if (req.body.registration_question_set_id) {
|
||||
db.RegistrationQuestionSet.findOne({ where: { id: req.body.registration_question_set_id } })
|
||||
.then(async foundSet => {
|
||||
if (!foundSet) return res.status(400).json({ error: 'no registration question set with that id' })
|
||||
await configuration.setRegistration_question_set(req.body.review_question_set_1_id)
|
||||
})
|
||||
const foundSet = await db.RegistrationQuestionSet.findOne({ where: { id: req.body.registration_question_set_id } })
|
||||
if (!foundSet) return res.status(400).json({ error: 'no registration question set with that id' })
|
||||
await configuration.setRegistration_question_set(req.body.registration_question_set_id)
|
||||
}
|
||||
returnPopulatedConfiguration(req, res, configuration)
|
||||
} catch (error) {
|
||||
|
||||
@@ -39,7 +39,7 @@ const createChecks = (req, res) => {
|
||||
db.RegistrationQuestionSet
|
||||
.findOne({ where: { name: req.body.name } })
|
||||
.then(foundSet => {
|
||||
if (foundSet) return res.status(400).json({ error: 'name already in use' })
|
||||
if (foundSet ) return res.status(400).json({ error: 'name already in use' })
|
||||
createRegistrationQuestionSet(req, res)
|
||||
})
|
||||
.catch(error => handleDatabaseError(res, error))
|
||||
@@ -47,11 +47,11 @@ const createChecks = (req, res) => {
|
||||
|
||||
const updateChecks = (req, res) => {
|
||||
if (isNaN(req.params.id)) return res.status(400).json({ error: 'invalid id' })
|
||||
if (!req.body.id) return res.status(400).json({ error: 'name undefined' })
|
||||
if (!req.body.name) return res.status(400).json({ error: 'name undefined' })
|
||||
db.RegistrationQuestionSet
|
||||
.findOne({ where: { name: req.body.name } })
|
||||
.then(duplicateNameSet => {
|
||||
if (duplicateNameSet) return res.status(400).json({ error: 'name already in use' })
|
||||
if (duplicateNameSet && (duplicateNameSet.id !== parseInt(req.params.id))) return res.status(400).json({ error: 'name already in use' })
|
||||
db.RegistrationQuestionSet
|
||||
.findOne({ where: { id: req.params.id } })
|
||||
.then(foundSet => {
|
||||
|
||||
@@ -47,11 +47,11 @@ const createChecks = (req, res) => {
|
||||
|
||||
const updateChecks = (req, res) => {
|
||||
if (isNaN(req.params.id)) return res.status(400).json({ error: 'invalid id' })
|
||||
if (!req.body.id) return res.status(400).json({ error: 'name undefined' })
|
||||
if (!req.body.name) return res.status(400).json({ error: 'name undefined' })
|
||||
db.ReviewQuestionSet
|
||||
.findOne({ where: { name: req.body.name } })
|
||||
.then(duplicateNameSet => {
|
||||
if (duplicateNameSet) return res.status(400).json({ error: 'name already in use' })
|
||||
if (duplicateNameSet && (duplicateNameSet.id !== parseInt(req.params.id))) return res.status(400).json({ error: 'name already in use' })
|
||||
db.ReviewQuestionSet
|
||||
.findOne({ where: { id: req.params.id } })
|
||||
.then(foundSet => {
|
||||
|
||||
Reference in New Issue
Block a user