From 4f7eb6f92fa322d879afdd56f653d997af5a364f Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 30 Jul 2020 11:36:03 +0200 Subject: [PATCH] minor fixes --- data_import/import.js | 11 +++--- src/index.ts | 1 + src/routes/user.ts | 1 + static/img/header.svg | 82 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 static/img/header.svg diff --git a/data_import/import.js b/data_import/import.js index aa84bf3..0f8d867 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -158,6 +158,9 @@ async function importCsv(doc) { newE[field] = ''; } }); + // if(newE['materialname'] === '') { // TODO: is this replacement okay? + // newE['materialname'] = newE['material']; + // } if (newE['supplier'] === '') { // empty supplier fields newE['supplier'] = 'unknown'; } @@ -208,7 +211,7 @@ async function allDpts() { res.data.forEach(sample => { sampleIds[sample.number] = sample._id; }); - const dptRegex = /(.*?)_(.*?)_(\d+|\w+_\d+).DPT/; + const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+_\d+).DPT/; const dpts = fs.readdirSync(dptFiles); for (let i in dpts) { const regexRes = dptRegex.exec(dpts[i]) @@ -269,8 +272,8 @@ async function allKfVz() { password: 'Abc123!#' } }); - const kf_template = res.data.find(e => e.name === 'kf')._id; - const vz_template = res.data.find(e => e.name === 'vz')._id; + const kf_template = res.data.filter(e => e.name === 'kf').sort((a, b) => b.version - a.version)[0]._id; + const vz_template = res.data.filter(e => e.name === 'vz').sort((a, b) => b.version - a.version)[0]._id; res = await axios({ method: 'get', url: host + '/samples?status=all', @@ -380,7 +383,7 @@ async function allSamples() { continue; } samples.push({ - number: sample['samplenumber'], + number: sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, ''), // remove leading An_01 and Eh_01 type: sampleType(sample['granulate/part']), batch: sample['charge/batch'], material_id: material._id, diff --git a/src/index.ts b/src/index.ts index 6771860..3fc4ef8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ app.use(helmet(defaultHeaderConfig)); app.use('/api-doc', helmet.contentSecurityPolicy({ ...defaultHeaderConfig, directives: { + defaultSrc: [`'none'`], scriptSrc: [`'self'`], connectSrc: [`'self'`], styleSrc: [`'self'`, `'unsafe-inline'`], diff --git a/src/routes/user.ts b/src/routes/user.ts index 65c41d5..2393150 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -65,6 +65,7 @@ router.put('/user:username([/](?!key|new).?*|/?)', async (req, res, next) => { }); }); +// TODO: only possible if no data is linked to user, otherwise change status, etc. router.delete('/user:username([/](?!key|new).?*|/?)', (req, res, next) => { // this path matches /user, /user/ and /user/xxx, but not /user/key or user/new. See https://forbeslindesay.github.io/express-route-tester/ for the generated regex if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'basic')) return; diff --git a/static/img/header.svg b/static/img/header.svg new file mode 100644 index 0000000..85e56b9 --- /dev/null +++ b/static/img/header.svg @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file