Skip to content

Commit 859a2eb

Browse files
author
Hans Schuller
committed
use where and orwhere for or clauses in bookshelf
1 parent 9935bd5 commit 859a2eb

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

server/service/CoursesService.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ exports.coursesCourse_idApplyPOST = function (course_id, req) {
3030
if (course != null) {
3131
// get all active applications for course
3232
Applications
33-
.where({
34-
ANM_KURS_ID: course_id,
35-
ANM_STAT_ID: 1 || 2
33+
.query({
34+
where: {
35+
ANM_KURS_ID: course_id,
36+
ANM_STAT_ID: 1
37+
},
38+
orWhere: {
39+
ANM_KURS_ID: course_id,
40+
ANM_STAT_ID: 2
41+
}
3642
})
3743
.fetchAll()
3844
.then((applicationModells) => {
@@ -153,11 +159,18 @@ exports.coursesCourse_idGET = function (course_id) {
153159
exports.coursesCourse_idSignoffPOST = function (course_id, req) {
154160
return new Promise(function (resolve, reject) {
155161
let user_id = getUserFromToken(req);
156-
157-
Applications.where({
158-
ANM_TEIL_ID: user_id,
159-
ANM_KURS_ID: course_id,
160-
ANM_STAT_ID: 1 || 2
162+
Applications
163+
.query({
164+
where: {
165+
ANM_TEIL_ID: user_id,
166+
ANM_KURS_ID: course_id,
167+
ANM_STAT_ID: 1
168+
},
169+
orWhere: {
170+
ANM_TEIL_ID: user_id,
171+
ANM_KURS_ID: course_id,
172+
ANM_STAT_ID: 2
173+
}
161174
})
162175
.save({ANM_STAT_ID: 3}, {
163176
patch: true

server/service/UserService.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ exports.userMeGET = function (id) {
3737
exports.userMeCoursesGET = function (user_id) {
3838
return new Promise(function (resolve, reject) {
3939
Applications
40-
.where({
41-
ANM_TEIL_ID: user_id,
42-
ANM_STAT_ID: 1 || 2
40+
.query({
41+
where: {
42+
ANM_TEIL_ID: user_id,
43+
ANM_STAT_ID: 2
44+
},
45+
orWhere:
46+
{ ANM_TEIL_ID: user_id,
47+
ANM_STAT_ID: 1
48+
}
4349
})
4450
.fetchAll({
4551
withRelated: ["course.location"]

0 commit comments

Comments
 (0)