Commit 9ca58d9b authored by antoine masson's avatar antoine masson
Browse files

v1.07

-Add CSV export for results
-Add exact version on root 
parent 3ef10b56
......@@ -117,12 +117,13 @@ exports.delete_a_token = (req, res) => {
}
};
exports.down_survey_tokens = async (req,res)=>{
exports.downJSON_survey_tokens = async (req,res)=>{
try{
const survey=await Survey.findById(req.params.survey_id)
Token.find({survey_id:req.params.survey_id,test:false},).
exec(async function (err, tokens) {
tokens.forEach(o=>o.survey_id=survey.general.short_name)
tokens.forEach(o=>{delete o.test; delete o.id})
res.set("Content-Type", "application/octet-stream");
res.set("Content-Disposition", "attachment;filename="+survey.general.short_name+"-token.json");
await res.send(tokens);
......@@ -132,6 +133,32 @@ exports.down_survey_tokens = async (req,res)=>{
}
};
exports.downCSV_survey_tokens = async (req,res)=>{
const { Parser,transforms: { flatten } } = require('json2csv');
try{
const survey=await Survey.findById(req.params.survey_id)
Token.find({survey_id:req.params.survey_id,test:false},).
exec(async function (err, tokens) {
let tokensjson=await JSON.parse(JSON.stringify(tokens))
tokensjson.forEach(o=>o.survey_id=survey.general.short_name)
tokensjson.forEach(o=>{delete o.test; delete o.id})
const transforms = [flatten({ paths: ['answers'] })];
const parser = new Parser({transforms});
try {
const tokenscsv = await parser.parse(tokensjson);
res.set("Content-Type", "application/octet-stream");
res.set("Content-Disposition", "attachment;filename="+survey.general.short_name+"-token.csv");
await res.send(tokenscsv);
}catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
});
} catch (err) {
res.status(400).json({ message: err,status:"Error"});
}
};
// client
exports.loginToken = async (req, res) => {
......
......@@ -15,6 +15,7 @@
"express": "^4.16.4",
"express-fileupload": "^1.2.1",
"express-zip": "^3.0.0",
"json2csv": "^5.0.6",
"jsonwebtoken": "^8.5.1",
"mime-types": "^2.1.27",
"mongoose": "^5.11.9",
......@@ -628,6 +629,14 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/commander": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz",
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==",
"engines": {
"node": ">= 6"
}
},
"node_modules/compress-commons": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-2.1.1.tgz",
......@@ -1492,6 +1501,31 @@
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
},
"node_modules/json2csv": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.6.tgz",
"integrity": "sha512-0/4Lv6IenJV0qj2oBdgPIAmFiKKnh8qh7bmLFJ+/ZZHLjSeiL3fKKGX3UryvKPbxFbhV+JcYo9KUC19GJ/Z/4A==",
"dependencies": {
"commander": "^6.1.0",
"jsonparse": "^1.3.1",
"lodash.get": "^4.4.2"
},
"bin": {
"json2csv": "bin/json2csv.js"
},
"engines": {
"node": ">= 10",
"npm": ">= 6.13.0"
}
},
"node_modules/jsonparse": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz",
"integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=",
"engines": [
"node >= 0.2.0"
]
},
"node_modules/jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
......@@ -1587,6 +1621,11 @@
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
},
"node_modules/lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"node_modules/lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
......@@ -3441,6 +3480,11 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"commander": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz",
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA=="
},
"compress-commons": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-2.1.1.tgz",
......@@ -4135,6 +4179,21 @@
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
},
"json2csv": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.6.tgz",
"integrity": "sha512-0/4Lv6IenJV0qj2oBdgPIAmFiKKnh8qh7bmLFJ+/ZZHLjSeiL3fKKGX3UryvKPbxFbhV+JcYo9KUC19GJ/Z/4A==",
"requires": {
"commander": "^6.1.0",
"jsonparse": "^1.3.1",
"lodash.get": "^4.4.2"
}
},
"jsonparse": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz",
"integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA="
},
"jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
......@@ -4222,6 +4281,11 @@
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
......
{
"name": "api",
"version": "1.0.0",
"version": "1.0.7",
"description": "",
"main": "index.js",
"scripts": {
......@@ -16,6 +16,7 @@
"express": "^4.16.4",
"express-fileupload": "^1.2.1",
"express-zip": "^3.0.0",
"json2csv": "^5.0.6",
"jsonwebtoken": "^8.5.1",
"mime-types": "^2.1.27",
"mongoose": "^5.11.9",
......
This diff is collapsed.
module.exports = app => {
const VERSION = require('../package.json').version
app.get('/',async (req, res) => {
return res
.status(401)
.json({ message: "API EAWAG Version 1.0.0" ,status: "OK"});
.status(400)
.json({ message: "API EAWAG Version "+VERSION ,status: "OK"});
})
};
......@@ -8,7 +8,8 @@ module.exports = app => {
app.get("/tokens/survey/:survey_id", auth(true), Builder.list_survey_tokens);
app.get("/tokens/survey/:survey_id/test", auth(true), Builder.test_survey_token);
app.get("/tokens/down/:survey_id", auth(true), Builder.down_survey_tokens);
app.get("/tokens/downjson/:survey_id", auth(true), Builder.downJSON_survey_tokens);
app.get("/tokens/downcsv/:survey_id", auth(true), Builder.downCSV_survey_tokens);
app.get("/tokens/token/:id", auth(true), Builder.get_a_token);
app.delete("/tokens/token/:id", auth(true), Builder.delete_a_token);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment