|
1 | 1 | const stakeholderService = require("../services/stakeholder-service");
|
| 2 | +const { Readable } = require("stream"); |
| 3 | +const stringify = require("csv-stringify"); |
2 | 4 |
|
3 | 5 | const search = (req, res) => {
|
4 | 6 | let categoryIds = req.query.categoryIds;
|
@@ -61,6 +63,73 @@ const getById = (req, res) => {
|
61 | 63 | });
|
62 | 64 | };
|
63 | 65 |
|
| 66 | +const csv = (req, res) => { |
| 67 | + const { ids } = req.body; |
| 68 | + res.setHeader("Content-Disposition", "attachment; filename=foodoasis.csv"); |
| 69 | + res.setHeader("Content-Type", "text/csv"); |
| 70 | + stakeholderService |
| 71 | + .selectCsv(ids) |
| 72 | + .then((resp) => { |
| 73 | + Readable.from(resp) |
| 74 | + .pipe( |
| 75 | + stringify({ |
| 76 | + header: true, |
| 77 | + columns: { |
| 78 | + id: "ID", |
| 79 | + name: "Name", |
| 80 | + inactive: "Closed Permanently", |
| 81 | + inactive_temporary: "Closed for COVID", |
| 82 | + covidNotes: "Covid Notes", |
| 83 | + categories: "Category", |
| 84 | + parentOrganization: "Parent Organization", |
| 85 | + description: "Description", |
| 86 | + address1: "Address", |
| 87 | + address2: "Address2ndLine", |
| 88 | + city: "City", |
| 89 | + state: "State", |
| 90 | + zip: "Zip", |
| 91 | + latitude: "Latitude", |
| 92 | + longitude: "Longitude", |
| 93 | + neighborhoodName: "Neighborhood", |
| 94 | + email: "Email", |
| 95 | + phone: "Phone", |
| 96 | + hours: "Hours", |
| 97 | + website: "Website", |
| 98 | + facebook: "Facebook", |
| 99 | + pinterest: "Pinterest", |
| 100 | + twitter: "Twitter", |
| 101 | + linkedin: "LinkedIn", |
| 102 | + instagram: "Instagram", |
| 103 | + requirements: "Eligibility Requirements", |
| 104 | + languages: "Languages", |
| 105 | + foodTypes: "Food Types", |
| 106 | + items: "Non-food Items", |
| 107 | + services: "Services", |
| 108 | + notes: "Public Notes", |
| 109 | + adminContactName: "Admin Contact", |
| 110 | + adminContactPhone: "Admin Phone", |
| 111 | + adminContactEmail: "Admin Email", |
| 112 | + donationContactName: "Donation Contact", |
| 113 | + donationContactPhone: "Donation Phone", |
| 114 | + donationContactEmail: "Donation Email", |
| 115 | + donationPickup: "Donation Pickup", |
| 116 | + donationAcceptFrozen: "Accepts Frozen", |
| 117 | + donationAcceptRefrigerated: "Accepts Refrigerated", |
| 118 | + donationAcceptPerishable: "Accepts Perishable", |
| 119 | + donationSchedule: "Donation Schedule", |
| 120 | + donationDeliveryInstructions: "Donation Delivery Instructions", |
| 121 | + donationNotes: "Donation Notes", |
| 122 | + verificationStatusId: "Verification Status", |
| 123 | + }, |
| 124 | + }) |
| 125 | + ) |
| 126 | + .pipe(res); |
| 127 | + }) |
| 128 | + .catch((err) => { |
| 129 | + res.status("500").json({ error: err.toString() }); |
| 130 | + }); |
| 131 | +}; |
| 132 | + |
64 | 133 | const post = (req, res) => {
|
65 | 134 | stakeholderService
|
66 | 135 | .insert(req.body)
|
@@ -131,6 +200,7 @@ const claim = (req, res) => {
|
131 | 200 | module.exports = {
|
132 | 201 | search,
|
133 | 202 | searchDashboard,
|
| 203 | + csv, |
134 | 204 | getById,
|
135 | 205 | post,
|
136 | 206 | put,
|
|
0 commit comments