From 57db32c56129efb41494a0d9621b94eb7a6c19b6 Mon Sep 17 00:00:00 2001 From: Mats Andreassen Date: Thu, 28 Jan 2021 20:47:10 +0100 Subject: [PATCH] Set id as objectid --- YFF/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/YFF/index.js b/YFF/index.js index aa21020..21ac86e 100644 --- a/YFF/index.js +++ b/YFF/index.js @@ -5,6 +5,7 @@ const { add, edit, get, remove } = require('../lib/crud') const { getMyStudents } = require('../lib/get-pifu-data') const { logger } = require('@vtfk/logger') const config = require('../config') +const { ObjectId } = require('mongodb') function resolveAction (method) { const collection = config.MONGODB_COLLECTION_YFF @@ -25,7 +26,6 @@ const handleYFF = async (context, req) => { const { student, type, id } = payload const { method, body } = req const user = req.token.upn - if (id && id !== '') payload._id = id logger('info', ['handle-yff', 'method', method, 'student', student, 'user', user, 'type', type, 'id', `${id || 'alle'}`]) @@ -45,11 +45,15 @@ const handleYFF = async (context, req) => { } } - delete payload.id + if (id && id !== '') { + payload._id = new ObjectId(id) + delete payload.id + } + const action = resolveAction(method) const result = await action(payload, body, user) - logger('info', ['handle-yff', 'method', method, 'student', student, 'user', user, 'type', type, 'id', `${id || 'alle'}`, 'result', result.length]) + logger('info', ['handle-yff', 'method', method, 'student', student, 'user', user, 'type', type, 'id', `${id || 'alle'}`, JSON.stringify(payload), 'result', result.length]) return getResponse(result) } catch (error) { logger('error', ['handle-yff', 'method', method, 'student', student, 'user', user, 'id', `${id || 'alle'}`, 'err', error.message])