Archived
2

base for csv export

This commit is contained in:
VLE2FE
2020-06-29 12:27:39 +02:00
parent 8aa051f0bd
commit e5cc661928
10 changed files with 87 additions and 17 deletions

View File

@ -89,7 +89,9 @@ function key (req, next): any { // checks API key and returns changed user obje
if (err) return next(err);
if (data.length === 1) { // one user found
resolve({level: data[0].level, name: data[0].name, id: data[0]._id.toString(), location: data[0].location});
delete req.query.key; // delete query parameter to avoid interference with later validation
if (!/^\/api/m.test(req.url)){
delete req.query.key; // delete query parameter to avoid interference with later validation
}
}
else {
resolve(null);

7
src/helpers/csv.ts Normal file
View File

@ -0,0 +1,7 @@
import {parseAsync} from 'json2csv';
export default function csv(input: object, fields: string[], f: (err, data) => void) {
parseAsync(input)
.then(csv => f(null, csv))
.catch(err => f(err, null));
}