Skip to content

Commit

Permalink
Merge pull request #155 from marc101101/feature/bugfix_my_courses
Browse files Browse the repository at this point in the history
use where and orwhere for or clauses in bookshelf
  • Loading branch information
marc101101 authored Sep 23, 2018
2 parents 4315afe + 859a2eb commit 49e46a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
29 changes: 21 additions & 8 deletions server/service/CoursesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions server/service/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 49e46a1

Please sign in to comment.