-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2144 from NMDSdevopsServiceAdm/test
Merging from Test to Staging for Sprint 3.1
- Loading branch information
Showing
31 changed files
with
1,534 additions
and
154 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,38 +1,50 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const cacheMiddleware = require('../utils/middleware/noCache'); | ||
const refCacheMiddleware = require('../utils/middleware/refCache'); | ||
const models = require('../models/index'); | ||
const { | ||
transformTrainingCategories, | ||
transformTrainingCategoriesWithMandatoryTraining, | ||
} = require('../transformers/trainingCategoryTransformer'); | ||
|
||
/* GET ALL ethnicities*/ | ||
router.route('/').get(async function (req, res) { | ||
const getAllTraining = async function (_req, res) { | ||
try { | ||
let results = await models.workerTrainingCategories.findAll({ | ||
order: [ | ||
["seq", "ASC"] | ||
] | ||
}); | ||
order: [['seq', 'ASC']], | ||
}); | ||
|
||
res.send({ | ||
trainingCategories: trainingCategoriesJSON(results) | ||
trainingCategories: transformTrainingCategories(results), | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(503).send(); | ||
} | ||
}); | ||
}; | ||
|
||
const getTrainingByCategory = async (req, res) => { | ||
try { | ||
const establishmentId = req.params.establishmentId; | ||
|
||
function trainingCategoriesJSON(givenCategories){ | ||
let categories=[]; | ||
let establishment = await models.establishment.findWithWorkersAndTraining(establishmentId); | ||
if (!establishment) { | ||
return res.sendStatus(404); | ||
} | ||
|
||
//Go through any results found from DB and map to JSON | ||
givenCategories.forEach(thisCategory => { | ||
categories.push({ | ||
id: thisCategory.id, | ||
seq: thisCategory.seq, | ||
category: thisCategory.category, | ||
}); | ||
}); | ||
let trainingCategories = await models.workerTrainingCategories.findAllWithMandatoryTraining(establishmentId); | ||
|
||
return categories; | ||
res.json({ | ||
trainingCategories: transformTrainingCategoriesWithMandatoryTraining(establishment, trainingCategories), | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
return res.status(503).send(); | ||
} | ||
}; | ||
|
||
router.route('/').get([refCacheMiddleware.refcache, getAllTraining]); | ||
router.route('/:establishmentId/with-training').get([cacheMiddleware.nocache, getTrainingByCategory]); | ||
|
||
module.exports = router; | ||
module.exports.getTrainingByCategory = getTrainingByCategory; |
Oops, something went wrong.