generated from CodeForBaltimore/ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into revjtanton/HOTFIX-temp-user-creation
- Loading branch information
Showing
5 changed files
with
111 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Router } from 'express'; | ||
import validator from 'validator'; | ||
import utils from '../utils'; | ||
import { parseAsync } from "json2csv"; | ||
|
||
const router = new Router(); | ||
router.use(utils.authMiddleware) | ||
|
||
// Gets a data dump from the passed in model (if it exists). | ||
router.get('/:model_type', async (req, res) => { | ||
let code; | ||
let message; | ||
const modelType = req.params.model_type; | ||
try { | ||
if(req.context.models.hasOwnProperty(modelType)){ | ||
//todo add filtering | ||
const results = await req.context.models[modelType].findAll({raw:true}); | ||
|
||
const processedResults = await utils.processResults(results, modelType); | ||
|
||
if(results.length !== 0){ | ||
message = await parseAsync(JSON.parse(JSON.stringify(processedResults)), Object.keys(results[0]), {}); | ||
} | ||
code = 200; | ||
} else { | ||
message = "model type is invalid" | ||
code = 422; | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
code = 500; | ||
} | ||
|
||
return utils.response(res, code, message); | ||
}); | ||
|
||
export default 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