youpin-api
youpin-api copied to clipboard
Export data to CSV/XSLX weekly
Export pins as CSV or XSLX
Input:
- Start - end date range
- Assigned department (optional)
- Assigned user (optional)
Output:
Tabular data with these columns:
- Pin Detail
- Status
- Reported Date
- Close Date (if any)
- Assigned Department
- Assigned User
- Category (in Thai and English)
- Tag
Should it be a command line script?
Seems to me like a cron job in another container might be fitting. Maybe a pure service that takes any data object (in JSON perhaps) and response with a CSV file transparently that gets run by a cron job weekly.
formatData(obj) -> csv
If no one is on this, I'd like to give it a first take.
Also, are we limited to using Javascript, provided if docker orchestrates isolated services?
Actually, I have another idea. Maybe we can create a new route for this purpose. For example,
URL : ./export/pins?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD&department=[all|...]&format=[json|xml|csv]
I guess they plan to use it from frontend. Meaning that, the user will select date range and the frontend will redirect to this url with parameters and return data with corresponding content-type. We might also need to check whether the user have an access to data of the department.
@heytitle I see. Why weekly then? That sounded like something that's not user-facing.
@jochasinga You're right, the weekly part is unnecessary. It will be handled on frontend.
I agree with @heytitle about making a new route for this.
So basically the route send a GET request with relevant query params or payload to the database, retrieve the data and do the parsing to CSV or whatever format on the frontend.
I think the workflow will look like this.
What do you think? cc: @jochasinga @rapee @parnurzeal @supasate
@heytitle you mean the api server responds with Content-Type: 'text/csv'
and does the parsing in the back end while the UI returns a promise and display a download element when response is ready. Looks good.
@jochasinga actually, what I meant by download dialog
is the one from the browser which can be called in 2 ways to do that
- using
download
attribute of<a>
. For example,
<a href="<path>/<to>/<api>?query=.." download="filename.csv">Download</a>
- add
Content-Disposition: attachment; filename="filename.csv"
header when returning the data. I've tested found that usingContent-Type
only would't force browser to show the save dialog. See : https://stackoverflow.com/questions/20039533/how-can-i-force-a-save-as-dialog