Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
Set id as objectid
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsAnd committed Jan 28, 2021
1 parent 0e65f61 commit 57db32c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions YFF/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}`])

Expand All @@ -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])
Expand Down

0 comments on commit 57db32c

Please # to comment.