Skip to content

Commit e9d2f64

Browse files
authored
Merge pull request #554 from UniversityOfHelsinkiCS/trunk
Trunk
2 parents ec802f9 + dd50b84 commit e9d2f64

File tree

17 files changed

+158
-132
lines changed

17 files changed

+158
-132
lines changed

backend/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const authenticate = (request, response, next) => {
113113
;(request.decoded = decoded), (request.authenticated = { success: true, error: '' })
114114
} catch (e) {
115115
request.authenticated = { success: false, error: 'token verification failed' }
116-
logger.error(e)
116+
// logger.error(e)
117117
}
118118
}
119119

@@ -139,9 +139,9 @@ app.get('*', (req, res) =>
139139
})
140140
)
141141

142-
let server = app.listen(3001, function() {
143-
let port = server.address().port
144-
console.log('Backend is listening on port %s', port)
142+
const server = app.listen(3001, () => {
143+
const port = server.address().port
144+
logger.info('Backend started and listening on port ' + port)
145145
})
146146

147147
module.exports = server

backend/server/config/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
password: process.env.DB_PASSWORD,
77
database: process.env.DB_NAME,
88
host: '127.0.0.1',
9+
port: process.env.DB_PORT,
910
dialect: 'postgres',
1011
operatorsAliases: 'false',
1112
kurki_url: process.env.KURKI_URL == null ? "https://opetushallinto.cs.helsinki.fi" : process.env.KURKI_URL

backend/server/controllers/admin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const helper = require('../helpers/admin_helper')
2+
const logger = require('../utils/logger')
23

34
module.exports = {
45
/**
@@ -22,7 +23,7 @@ module.exports = {
2223
values2: areActive
2324
})
2425
} catch (e) {
25-
console.log('\nadmin, async list catch: ', e, '\n')
26+
logger.error(e)
2627

2728
res.send('errored in controllers/admin/list')
2829
}

backend/server/controllers/assistants.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Op = Sequelize.Op
99
const StudentInstanceController = require('../controllers').studentInstances
1010
const env = process.env.NODE_ENV || 'development'
1111
const config = require('./../config/config.js')[env]
12+
const logger = require('../utils/logger')
1213

1314
module.exports = {
1415
async create(req, res) {
@@ -22,7 +23,6 @@ module.exports = {
2223
res.status(400).send('you have to be authenticated to do this')
2324
return
2425
}
25-
console.log('\n\nAuthentication succeeded')
2626
const requestMakerId = req.decoded.id
2727
const studentInstance = await StudentInstance.findOne({
2828
where: {
@@ -67,13 +67,12 @@ module.exports = {
6767
res.status(400).send('The teacher is not from the same course as this student.')
6868
return
6969
}
70-
console.log('\n\nCourses match')
7170
studentInstance.updateAttributes({
7271
teacherInstanceId: teacherInsId
7372
})
7473
res.status(200).send(studentInstance)
7574
} catch (e) {
76-
console.log('\n\nAssistantInstance creation failed.\n', e)
75+
logger.error(e)
7776
}
7877
},
7978

@@ -139,7 +138,7 @@ module.exports = {
139138
})
140139
res.status(200).send(studentsForThisTeacherInstance)
141140
} catch (e) {
142-
console.log('\nfindStudentsByTeacherInstance did not succeed\n\n')
141+
logger.error(e)
143142
res.status(400).send(e)
144143
}
145144
}

backend/server/controllers/checklists.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const helper = require('../helpers/checklist_helper')
22
const TeacherInstance = require('../models').TeacherInstance
33
const Checklist = require('../models').Checklist
4+
const logger = require('../utils/logger')
45

56
module.exports = {
67
async create(req, res) {
@@ -89,8 +90,8 @@ module.exports = {
8990
data: req.body
9091
})
9192
} catch (e) {
93+
logger.error(e)
9294
res.status(500).send('Unexpected error')
93-
console.log(e)
9495
}
9596
},
9697
async getOne(req, res) {
@@ -121,8 +122,8 @@ module.exports = {
121122
})
122123
}
123124
} catch (e) {
125+
logger.error(e)
124126
res.status(500).send(e)
125-
console.log(e)
126127
}
127128
}
128129
}

backend/server/controllers/codeReviews.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const StudentInstance = require('../models').StudentInstance
33
const TeacherInstance = require('../models').TeacherInstance
44
const CourseInstance = require('../models').CourseInstance
55
const helper = require('../helpers/code_review_helper')
6+
const logger = require('../utils/logger')
67

78
module.exports = {
89
async bulkInsert(req, res) {
@@ -76,7 +77,7 @@ module.exports = {
7677
data: req.body
7778
})
7879
} catch (e) {
79-
console.log('CodeReview bulk insert failed.\n', e)
80+
logger.error('CodeReview bulk insert failed.\n', e)
8081
res.status(500).send('Unexpected error.')
8182
}
8283
},

backend/server/controllers/courseinstances.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const config = require('./../config/config.js')[env]
1717
const logger = require('../utils/logger')
1818

1919
const overkillLogging = (req, error) => {
20-
console.log('request: ', req)
21-
console.log('error: ', error)
20+
logger.debug('request: ', req)
21+
logger.error('error: ', error)
2222
}
2323

2424
const validationErrorMessages = {
@@ -291,7 +291,7 @@ module.exports = {
291291
})
292292
}
293293
if (course.active === false) {
294-
console.log('course is not active')
294+
logger.info('course registration failed because course is not active')
295295
overkillLogging(req, null)
296296
return res.status(400).send({
297297
message: 'course is not active'
@@ -368,38 +368,32 @@ module.exports = {
368368

369369
try {
370370
if (req.authenticated.success) {
371-
console.log('\nauth success\n')
372371
CourseInstance.findOne({
373372
where: {
374373
ohid: req.body.ohid
375374
}
376375
})
377376
.then(course => {
378377
if (!course) {
379-
console.log('\nkurssia ei löytynyt\n')
380378
res.status(404).send('course not found')
381379
return
382380
}
383-
console.log('\nkurssi löytyi\n')
384381
StudentInstance.find({
385382
where: {
386383
userId: req.decoded.id,
387384
courseInstanceId: course.id
388385
}
389386
}).then(targetStudent => {
390387
if (!targetStudent) {
391-
console.log('\nopiskelijaa ei löytynyt\n')
392388
res.status(404).send('Student not found')
393389
return
394390
}
395-
console.log('\nopiskelija löytyi\n')
396391
return targetStudent
397392
.update({
398393
github: req.body.github || targetStudent.github,
399394
projectName: req.body.projectname || targetStudent.projectName
400395
})
401396
.then(updatedStudentInstance => {
402-
console.log('\nUpdated student project info succesfully\n')
403397
res.status(200).send(updatedStudentInstance)
404398
})
405399
.catch((error) => {
@@ -588,7 +582,6 @@ module.exports = {
588582
getNewer(req, res) {
589583
helper.controller_before_auth_check_action(req, res)
590584

591-
console.log('update next...')
592585
const auth = process.env.TOKEN || 'notset' //You have to set TOKEN in .env file in order for this to work
593586
const termAndYear = helper.CurrentTermAndYear()
594587
if (auth === 'notset') {

backend/server/controllers/login.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const User = require('../models').User
33
const request = require('request')
44
const env = process.env.NODE_ENV || 'development'
55
const config = require('./../config/config.js')[env]
6+
const logger = require('../utils/logger')
67

78
module.exports = {
89
/**
@@ -11,18 +12,17 @@ module.exports = {
1112
* @param res
1213
*/
1314
login(req, res) {
14-
console.log('entered login')
1515
const options = {
1616
method: 'post',
1717
uri: `${config.kurki_url}/login`,
1818
strictSSL: false,
19-
json: { username: req.body.username, password: req.body.password }
19+
json: { username: req.body.username.toLowerCase(), password: req.body.password }
2020
}
2121

2222
try {
23-
const result = request(options, function(err, resp, body) {
23+
const result = request(options, (err, resp, body) => {
2424
if (err) {
25-
console.log('\nlogin: ', err, 'n')
25+
logger.error('\nlogin: ', err, 'n')
2626
}
2727
if (result.response && result.response.body && result.response.body.username && result.response.body.error !== 'wrong credentials') {
2828
let first
@@ -35,7 +35,7 @@ module.exports = {
3535
first = result.response.body.first_names.split(' ')[0]
3636
}
3737
User.findOrCreate({
38-
where: { username: body.username },
38+
where: { username: body.username.toLowerCase() },
3939
defaults: {
4040
firsts: first,
4141
lastname: last,
@@ -70,10 +70,10 @@ module.exports = {
7070
}
7171
})
7272
} catch (error) {
73+
logger.error(error)
7374
res.status(500).send({
7475
error: 'Unexpected error'
7576
})
76-
console.log(error)
7777
}
7878
}
7979
}

backend/server/controllers/weeks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868
res.status(400).send('token verific ation failed')
6969
}
7070
} catch (error) {
71-
console.log('\nweeks, ', error, '\n')
71+
logger.error('\nweeks, ', error, '\n')
7272
}
7373
},
7474
/**

backend/server/helpers/application_helper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports.getCurrent = getCurrent
99
exports.createCourse = createCourse
1010
const env = process.env.NODE_ENV || 'development'
1111
const config = require('./../config/config.js')[env]
12+
const logger = require('../utils/logger')
1213

1314
/**
1415
*
@@ -239,7 +240,7 @@ async function createCourse(body) {
239240
}
240241
return result
241242
} catch (error) {
242-
console.log(error)
243+
logger.error(error)
243244
}
244245
}
245246

@@ -262,7 +263,7 @@ async function getCurrent(req, res) {
262263
})
263264
return result
264265
} catch (error) {
265-
console.log(error)
266+
logger.error(error)
266267
}
267268
}
268269

@@ -285,6 +286,6 @@ async function getNewer(req, res) {
285286
})
286287
return result
287288
} catch (error) {
288-
console.log(error)
289+
logger.error(error)
289290
}
290291
}

0 commit comments

Comments
 (0)