generated from CodeForBaltimore/ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 21
Issue 188 - Return number of emails contacted #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b354210
return email results
ijadams 0035d38
only return meta
ijadams 15eb9d7
move into results
ijadams 964c5a9
reformat trigger ci build
ijadams 180ef3d
fix test
ijadams a3f7258
add temporary auth and fix csv download for Contact
ijadams ffa8e35
fix test
ijadams 4e59ef2
add query param for filter on csv endpoint
ijadams 64d4aed
sort out query param
ijadams a676d17
fix processed results bug
ijadams d125654
csv edits
ijadams 76a9a4b
rm auth
ijadams 89a3779
begin work on single email
ijadams 8b50c92
update postman
ijadams 952fba7
add single email contact
ijadams a701a17
Merge branch 'master' into 188
stoopidJSON 158b9d4
Merge branch 'master' into 188
ijadams504 e81c2b1
rm log
ijadams504 6288309
Merge branch 'master' into 188
ijadams504 cb4f97e
update readme
ijadams504 fecb795
change error type - from code review
ac963cc
Merge pull request #313 from joshglazer/188
joshglazer 5dfdbac
changing error status code - from code review
7bfa55d
Merge pull request #314 from joshglazer/188
joshglazer 15d5bab
Merge branch 'master' of github.com:CodeForBaltimore/Bmore-Responsive…
0460a9b
Merge pull request #315 from joshglazer/188
joshglazer 3cfb2c2
Merge branch 'master' into 188
blakenan-bellese 12ef324
updated status code
joshglazer 454b84a
Merge pull request #318 from joshglazer/188
joshglazer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 +1,65 @@ | ||
| import { Router } from 'express' | ||
| import {Router} from 'express' | ||
| import utils from '../utils' | ||
| import { parseAsync } from 'json2csv' | ||
| import {parseAsync} from 'json2csv' | ||
| import {Op} from 'sequelize' | ||
|
|
||
| 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) => { | ||
|
|
||
| const response = new utils.Response() | ||
| const modelType = req.params.model_type | ||
|
|
||
| try { | ||
|
|
||
| /** @todo refactor this when we change how CSV's are delivered. */ | ||
| // eslint-disable-next-line no-prototype-builtins | ||
| if (req.context.models.hasOwnProperty(modelType) && modelType !== 'User' && modelType !== 'UserRole') { | ||
| /** @todo add filtering */ | ||
| const results = await req.context.models[modelType].findAll({ raw: true }) | ||
| let options = {raw: true} | ||
| // search by name if filter query param is included | ||
| if (req.query && req.query.filter && req.query.filter.length) { | ||
| options.where = { | ||
| name: { | ||
| [Op.iLike]: '%' + req.query.filter + '%' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const processedResults = await utils.processResults(results, modelType) | ||
| /** @todo add a search filter for status once data has a status field. */ | ||
| let results = await req.context.models[modelType].findAll(options) | ||
|
|
||
| if (results.length !== 0) { | ||
| response.setMessage = await parseAsync(JSON.parse(JSON.stringify(processedResults)), Object.keys(results[0]), {}) | ||
| const processedResults = await utils.processResults(results, modelType) | ||
| const fields = Object.keys(results[0]) | ||
| parseAsync(processedResults, {fields}).then(csv => { | ||
| response.setMessage(csv) | ||
| const dateObj = new Date() | ||
| const dateStr = `${dateObj.getUTCMonth() + 1}_${dateObj.getUTCDate()}_${dateObj.getUTCFullYear()}` | ||
| res.setHeader('Content-disposition', `attachment; filename=HCRC_${modelType}_${dateStr}.csv`) | ||
| res.set('Content-Type', 'text/csv') | ||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| }, err => { | ||
| response.setCode(500) | ||
| response.setMessage('Not able to parse data: ' + err) | ||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| }) | ||
| } else { | ||
| response.setCode(200) | ||
| response.setMessage('No results found') | ||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| } | ||
| } else { | ||
| response.setCode(400) | ||
| response.setMessage('Model type is invalid') | ||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| } | ||
| } catch (e) { | ||
| console.error(e) | ||
| response.setCode(500) | ||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| } | ||
|
|
||
| return res.status(response.getCode()).send(response.getMessage()) | ||
| }) | ||
|
|
||
| export default router |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.