-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐
๐ฟ Add nawc volunteer role (#458)
* Add new role, remove intern role * Add new file
- Loading branch information
1 parent
763b910
commit 2456aec
Showing
11 changed files
with
152 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { errorWrap } = require('../middleware'); | ||
|
||
const Category = require('../models/category'); | ||
const Resource = require('../models/resource'); | ||
const HomePage = require('../models/homepage'); | ||
const Translation = require('../models/translation'); | ||
const VerifiedTranslation = require('../models/verifiedTranslation'); | ||
const { | ||
getVerifiedAggregation, | ||
getNestedVerifiedAggregation, | ||
getVerificationDetails, | ||
} = require('../utils/verification'); | ||
|
||
// Get verified translations for table | ||
router.get( | ||
'/verified', | ||
errorWrap(async (req, res) => { | ||
const { language } = req.query; | ||
const resourceInfo = await Resource.aggregate( | ||
getVerifiedAggregation(language, 'resourceID', 'resource'), | ||
); | ||
const categoryInfo = await Category.aggregate( | ||
getVerifiedAggregation(language, 'categoryID', 'category'), | ||
); | ||
const subcategoryInfo = await Category.aggregate( | ||
getNestedVerifiedAggregation( | ||
language, | ||
'subcategoryID', | ||
'subcategory', | ||
'subcategories', | ||
'name', | ||
), | ||
); | ||
const testimonialInfo = await HomePage.aggregate( | ||
getNestedVerifiedAggregation( | ||
language, | ||
'testimonialID', | ||
'testimonial', | ||
'testimonials', | ||
'person', | ||
), | ||
); | ||
|
||
res.json({ | ||
code: 200, | ||
message: 'Successfully returned verified translation table info', | ||
success: true, | ||
result: resourceInfo.concat( | ||
categoryInfo, | ||
subcategoryInfo, | ||
testimonialInfo, | ||
), | ||
}); | ||
}), | ||
); | ||
|
||
// Get verified translations for an ID | ||
router.get( | ||
'/verified/:id', | ||
errorWrap(async (req, res) => { | ||
const { id } = req.params; | ||
const { language, type } = req.query; | ||
|
||
const verificationDetails = await getVerificationDetails( | ||
type, | ||
language, | ||
id, | ||
); | ||
const { messages } = await Translation.findOne({ | ||
language: { $eq: language }, | ||
}); | ||
verificationDetails.forEach((verificationObject) => { | ||
const key = Object.keys(verificationObject)[0]; | ||
verificationObject[key][language] = messages.get(key); | ||
}); | ||
|
||
res.json({ | ||
code: 200, | ||
message: 'Successfully returned verified translation info', | ||
success: true, | ||
result: verificationDetails, | ||
}); | ||
}), | ||
); | ||
|
||
// Update verified translations for an ID | ||
router.put( | ||
'/verified', | ||
errorWrap(async (req, res) => { | ||
const { language, type } = req.query; | ||
const { translations } = req.body; | ||
|
||
const translationsToUpdate = await Translation.findOne({ | ||
language: { $eq: language }, | ||
}); | ||
translations.forEach(async (translation) => { | ||
const key = Object.keys(translation)[0]; | ||
translationsToUpdate.messages.set(key, translation[key][language]); | ||
const verifiedTranslation = await VerifiedTranslation.updateOne( | ||
{ | ||
translationID: key, | ||
language, | ||
}, | ||
{ $set: { verified: translation[key].verified } }, | ||
); | ||
}); | ||
await translationsToUpdate.save(); | ||
|
||
res.json({ | ||
code: 200, | ||
message: 'Successfully updated verified translation info', | ||
success: true, | ||
result: null, | ||
}); | ||
}), | ||
); | ||
|
||
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
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,21 @@ | ||
const express = require('express'); | ||
|
||
const router = express.Router(); | ||
const { admin, category, resource, homepage, translation } = require('../api'); | ||
const { authAdmin, authGeneral } = require('../middleware/auth'); | ||
const { | ||
admin, | ||
category, | ||
resource, | ||
homepage, | ||
translation, | ||
volunteer, | ||
} = require('../api'); | ||
const { authAdmin, authVolunteer } = require('../middleware/auth'); | ||
|
||
router.use('/api/categories', category); | ||
router.use('/api/resources', resource); | ||
router.use('/api/admin', authAdmin, admin); | ||
router.use('/api/homepage', homepage); | ||
router.use('/api/translation', translation); | ||
router.use('/api/volunteer', authVolunteer, volunteer); | ||
|
||
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
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.