Skip to content

Commit 0f886c6

Browse files
author
Markus Guder
committed
Merge remote-tracking branch 'origin/master' into feature/testing
2 parents d62c37f + 34acdea commit 0f886c6

10 files changed

Lines changed: 177 additions & 71 deletions

File tree

dist/ngsw.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@
110110
"/assets/img/loading.gif": "cdc1627a1ff312a43d1700a3694da1050e0e026d",
111111
"/assets/js/idb.js": "6f82cc3f3c743e77b6931a0129d7afddd6cfe3c4",
112112
"/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
113-
<<<<<<<<< Temporary merge branch 1
114-
"/index.html": "ddd41bb17fac02df04e340345552a3ccfa37bf92"
115-
=========
116-
"/index.html": "03eb209dd5570c5324be09681b2438acd2300697"
117-
>>>>>>>>> Temporary merge branch 2
113+
"/index.html": "73c0cb44bb3ccb7f09aa06ad1cf8b10fa369a6e6"
118114
},
119115
"navigationUrls": [
120116
{

server/service/CategoriesService.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Categories = require('../utils/database').Category;
44
var knex = require('../utils/database').knex;
55
var Errors = require('../utils/errors');
6+
var Trimmer = require('../utils/trim');
67
/**
78
* get all courses of a category
89
* get all courses of a category
@@ -20,7 +21,7 @@ exports.categoriesCategory_idCoursesGET = function(category_id) {
2021
reject(Errors.notFound("GET ID " +category_id, "Category"));
2122
}
2223
let courses = category.related("courses").toJSON();
23-
resolve(courses);
24+
resolve(Trimmer.courses(courses));
2425
}))
2526
.catch((error) => {
2627
reject(error);
@@ -64,7 +65,7 @@ exports.categoriesGET = function() {
6465
Categories
6566
.fetchAll()
6667
.then((categories) => {
67-
resolve(categories.map(item => item.attributes));
68+
resolve(Trimmer.categories(categories.toJSON()));
6869
})
6970
.catch((error) => {
7071
reject(error);

server/service/CoursesService.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var knex = require('../utils/database').knex;
88
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
99
var Errors = require('../utils/errors');
1010
var moment = require('moment');
11+
var Trimmer = require('../utils/trim');
1112

1213
/**
1314
* apply to participate in specific course
@@ -45,7 +46,7 @@ exports.coursesCourse_idApplyPOST = function (course_id, req) {
4546
new Applications(generateApplicationFor(user_id, course_id, areSlotsLefToParticipate))
4647
.save()
4748
.then((application) => {
48-
resolve(application);
49+
resolve(application.toJSON());
4950
})
5051
.catch((error) => {
5152
reject(error);
@@ -106,7 +107,7 @@ exports.coursesCourse_idFeedbackPOST = function (course_id, data) {
106107
new CourseFeedback({...data, kurs_id: course_id})
107108
.save()
108109
.then((feedback) => {
109-
resolve(feedback.attributes);
110+
resolve(feedback.toJSON());
110111
})
111112
.catch((error) => {
112113
console.log(error);
@@ -128,12 +129,12 @@ exports.coursesCourse_idGET = function (course_id) {
128129
Courses.where({
129130
kurs_id: course_id
130131
})
131-
.fetch({withRelated: ["location"]})
132+
.fetch({withRelated: ["location", "teacher"]})
132133
.then((course) => {
133134
if (!course) {
134135
reject(Errors.notFound("GET ID " + course_id, "COURSE"));
135136
}
136-
resolve(course.toJSON());
137+
resolve(Trimmer.course(course.toJSON()));
137138
})
138139
.catch((error) => {
139140
reject(error);
@@ -161,11 +162,11 @@ exports.coursesCourse_idSignoffPOST = function (course_id, req) {
161162
.save({ANM_STAT_ID: 3}, {
162163
patch: true
163164
})
164-
.then(applicationModel => {
165-
if (!applicationModel) {
165+
.then(application => {
166+
if (!application) {
166167
reject(Errors.notFound("course with ID ", course_id));
167168
}
168-
resolve(applicationModel);
169+
resolve(application.toJSON());
169170
})
170171
.catch(err => {
171172
reject(Errors.notFound("course with ID ", course_id));
@@ -198,9 +199,9 @@ exports.coursesGET = function (query) {
198199
});
199200
} else {
200201
Courses
201-
.fetchAll({withRelated: ["location"]})
202-
.then((course) => {
203-
resolve(course.toJSON());
202+
.fetchAll({withRelated: ["location", "teacher"]})
203+
.then((courses) => {
204+
resolve(Trimmer.courses(courses.toJSON()));
204205
})
205206
.catch((error) => {
206207
reject(error);
@@ -220,9 +221,9 @@ exports.coursesHighlightsGET = function () {
220221
return new Promise(function (resolve, reject) {
221222
Courses
222223
.where({kurs_highlight: 1})
223-
.fetchAll({withRelated: ["location"]})
224+
.fetchAll({withRelated: ["location", "teacher"]})
224225
.then((courses) => {
225-
resolve(courses.toJSON());
226+
resolve(Trimmer.courses(courses.toJSON()));
226227
})
227228
.catch((error) => {
228229
reject(error);
@@ -237,12 +238,14 @@ exports.coursesLastminuteGET = function() {
237238
.query(function(qb) {
238239
qb.whereBetween('KURS_ANMFRIST', [moment().format('YYYY-MM-DD'), moment().add(6, 'weeks').format('YYYY-MM-DD')]);
239240
})
240-
.fetchAll({withRelated: ["applications", "location"]})
241+
.fetchAll({withRelated: ["applications", "location", "teacher"]})
241242
.then((courses) => {
242-
resolve(courses
243-
.filter(item => item.related('applications').toJSON().length < item.attributes.KURS_TEIL_MAX)
244-
.filter(item => item.attributes.KURS_KURSSTAT_ID === 3)
245-
.map(item => item.toJSON())
243+
resolve(Trimmer.courses(
244+
courses
245+
.filter(item => item.related('applications').toJSON().length < item.attributes.KURS_TEIL_MAX)
246+
.filter(item => item.attributes.KURS_KURSSTAT_ID === 3)
247+
.map(item => item.toJSON())
248+
)
246249
)
247250
})
248251
.catch((error) => {

server/service/UserService.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
88
var bcrypt = require('bcryptjs');
99
var config = require('../config'); // get config file
1010
var Errors = require('../utils/errors');
11+
var Trimmer = require('../utils/trim');
1112

1213
/**
1314
* get me
@@ -25,7 +26,7 @@ exports.userMeGET = function (id) {
2526
if (!user) {
2627
reject(Errors.notFound("GET ID " + id, "USER"))
2728
}
28-
resolve(user);
29+
resolve(Trimmer.user(user.toJSON()));
2930
})
3031
.catch((error) => {
3132
reject(error);
@@ -45,7 +46,7 @@ exports.userMeCoursesGET = function (user_id) {
4546
})
4647
.then((applications) => {
4748
let courses = applications.map(item => item.related('course').toJSON());
48-
resolve(courses);
49+
resolve(Trimmer.courses(courses));
4950
})
5051
.catch((error) => {
5152
reject(error);
@@ -63,7 +64,7 @@ exports.userMeCoursesGET = function (user_id) {
6364
**/
6465
exports.userPOST = function (data) {
6566
return new Promise(function (resolve, reject) {
66-
User.where({teil_email: data.teil_email})
67+
User.where({TEIL_EMAIL : data.TEIL_EMAIL})
6768
.fetch()
6869
.then((model) => {
6970
if (!model) {
@@ -75,8 +76,11 @@ exports.userPOST = function (data) {
7576
}, config.secret, {
7677
expiresIn: 86400 // expires in 24 hours
7778
});
79+
// for some reason, bookshelf returns TEIL_ID just as id after saving
80+
let trimmedUser = Trimmer.user(user.toJSON());
81+
trimmedUser.TEIL_ID = user.attributes.id;
7882
resolve({
79-
user: user,
83+
user: trimmedUser,
8084
token: token
8185
});
8286
})
@@ -108,11 +112,11 @@ exports.userPUT = function (id, data) {
108112
.save(data, {
109113
patch: true
110114
})
111-
.then(userModel => {
112-
if (!userModel) {
115+
.then(user => {
116+
if (!user) {
113117
reject(Errors.notFound("PUT ID " + id, "USER"));
114118
}
115-
resolve(userModel);
119+
resolve(Trimmer.user(user.toJSON()));
116120
})
117121
.catch(err => {
118122
reject(err);

server/test/courses.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ describe("Courses Highlights", () => {
224224
})
225225
})
226226

227+
it("it should show valid teacher data for all highlight courses", (done) => {
228+
229+
dbHelper.Courses.setupHighlightsCoursesWithTeacher()
230+
.then(() => {
231+
chai.request(server)
232+
.get('/v1/courses/highlights')
233+
.end((err, res) => {
234+
res.should.have.status(200);
235+
res.body.should.be.a('array');
236+
res.body.forEach(item => {
237+
item.teacher.TEIL_VORNAME.should.equal("John");
238+
item.teacher.DATENHISTORY.should.equal("USER_IDENTIFIER");
239+
})
240+
done();
241+
})
242+
})
243+
})
227244
it("it should get all courses with found by a query", (done) => {
228245
chai.request(server)
229246
.get('/v1/courses')

server/test/helpers/dbhelpers.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var User = require('../../utils/database').User;
99
var Applications = require('../../utils/database').Application;
1010
var Location = require('../../utils/database').Location;
1111

12+
let sampleUser = require('./sampleData').user();
13+
1214
var generateApplicationFor = require('../../service/CoursesService').generateApplicationFor;
1315

1416

@@ -17,23 +19,12 @@ const AuthHelper = {
1719
clearDataBaseInsertUser: () => {
1820
return new Promise((resolve, reject) => {
1921
console.log("Clearing all Content in Table vhslq_teilnehmer and Insert valid user");
20-
let user = {
21-
teil_vorname: "John",
22-
teil_nachname: "Doe",
23-
teil_email: "johndoe@vhslq.de",
24-
teil_notizen: "john's notes",
25-
teil_passwort: "hunter22",
26-
eingegeben_von_user: 0,
27-
eingegeben_am_datum: "2018-01-01",
28-
eingegeben_am_zeit: "00:00:00",
29-
datenhistory: "John's data history"
30-
};
3122

3223
knex("vhslq_teilnehmer")
3324
.del()
3425
.then(() => {
3526
console.log("Finished clearing all Content in Table vhslq_teilnehmer");
36-
new User(user)
27+
new User(sampleUser)
3728
.save()
3829
.then((user) => {
3930
resolve(user);
@@ -131,6 +122,21 @@ const CoursesHelper = {
131122
});
132123
},
133124

125+
setupHighlightsCoursesWithTeacher: () => {
126+
return new Promise((resolve, reject) => {
127+
User.where({TEIL_VORNAME: "John"})
128+
.fetch()
129+
.then(user => {
130+
Courses
131+
.where({KURS_HIGHLIGHT: 1})
132+
.save({KURS_REFERENT_ID: user.attributes.TEIL_ID}, {patch: true})
133+
.then(courses => {
134+
resolve(courses.toJSON());
135+
})
136+
})
137+
})
138+
},
139+
134140
setupLastMinute: () => {
135141
console.log("Setting up Last Minute Content in Table vhslq_kurse")
136142
return new Promise((resolve, reject) => {

server/test/helpers/sampleData.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,18 @@ if (process.env.NODE_ENV === 'test') {
616616
DATENHISTORY: "LOCATION_IDENTIFIER"
617617
}
618618
}
619+
620+
exports.user = () => {
621+
return {
622+
TEIL_VORNAME: "John",
623+
TEIL_NACHNAME: "Doe",
624+
TEIL_EMAIL: "johndoe@vhslq.de",
625+
TEIL_NOTIZEN: "john's notes",
626+
TEIL_PASSWORT: "hunter22",
627+
EINGEGEBEN_VON_USER: 0,
628+
EINGEGEBEN_AM_DATUM: "2018-01-01",
629+
EINGEGEBEN_AM_ZEIT: "00:00:00",
630+
DATENHISTORY: "USER_IDENTIFIER"
631+
}
632+
}
619633
}

0 commit comments

Comments
 (0)