From 859a2eb803341d024cf81a75c8cb526a55c6142f Mon Sep 17 00:00:00 2001 From: Hans Schuller Date: Sun, 23 Sep 2018 14:46:40 +0200 Subject: [PATCH] use where and orwhere for or clauses in bookshelf --- server/service/CoursesService.js | 29 +++++++++++++++++++++-------- server/service/UserService.js | 12 +++++++++--- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/server/service/CoursesService.js b/server/service/CoursesService.js index a89faaf..5413240 100755 --- a/server/service/CoursesService.js +++ b/server/service/CoursesService.js @@ -30,9 +30,15 @@ exports.coursesCourse_idApplyPOST = function (course_id, req) { if (course != null) { // get all active applications for course Applications - .where({ - ANM_KURS_ID: course_id, - ANM_STAT_ID: 1 || 2 + .query({ + where: { + ANM_KURS_ID: course_id, + ANM_STAT_ID: 1 + }, + orWhere: { + ANM_KURS_ID: course_id, + ANM_STAT_ID: 2 + } }) .fetchAll() .then((applicationModells) => { @@ -153,11 +159,18 @@ exports.coursesCourse_idGET = function (course_id) { exports.coursesCourse_idSignoffPOST = function (course_id, req) { return new Promise(function (resolve, reject) { let user_id = getUserFromToken(req); - - Applications.where({ - ANM_TEIL_ID: user_id, - ANM_KURS_ID: course_id, - ANM_STAT_ID: 1 || 2 + Applications + .query({ + where: { + ANM_TEIL_ID: user_id, + ANM_KURS_ID: course_id, + ANM_STAT_ID: 1 + }, + orWhere: { + ANM_TEIL_ID: user_id, + ANM_KURS_ID: course_id, + ANM_STAT_ID: 2 + } }) .save({ANM_STAT_ID: 3}, { patch: true diff --git a/server/service/UserService.js b/server/service/UserService.js index 76aa7dc..f88b3bc 100755 --- a/server/service/UserService.js +++ b/server/service/UserService.js @@ -37,9 +37,15 @@ exports.userMeGET = function (id) { exports.userMeCoursesGET = function (user_id) { return new Promise(function (resolve, reject) { Applications - .where({ - ANM_TEIL_ID: user_id, - ANM_STAT_ID: 1 || 2 + .query({ + where: { + ANM_TEIL_ID: user_id, + ANM_STAT_ID: 2 + }, + orWhere: + { ANM_TEIL_ID: user_id, + ANM_STAT_ID: 1 + } }) .fetchAll({ withRelated: ["course.location"]