Skip to content

Commit

Permalink
Merge pull request #507 from UniversityOfHelsinkiCS/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Chamion authored Jul 12, 2018
2 parents 629513a + ac4a043 commit 3f6dd66
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 50 deletions.
1 change: 1 addition & 0 deletions backend/server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
host: process.env.DB_HOST,
dialect: 'postgres',
operatorsAliases: 'false',
logging: false,
kurki_url: "https://opetushallinto.cs.helsinki.fi"
}
}
4 changes: 0 additions & 4 deletions backend/server/controllers/assistants.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,14 @@ module.exports = {
res.status(200).send(returnedAssistantInfo)
}
} catch (e) {
console.log('\n\nAAAA\n\n')
res.status(400).send(e)
}
},

async findStudentsByTeacherInstance(req, res) {
console.log('Etsitään assarin oppilaat')

helper.controller_before_auth_check_action(req, res)
try {
const teacherInsId = req.params.id
console.log('\n\nteacherInsId: ', req.param.id)

const studentsForThisTeacherInstance = await StudentInstance.findAll({
where: {
Expand Down
23 changes: 0 additions & 23 deletions backend/server/controllers/courseinstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ module.exports = {
findByUserTeacherInstance(req, res) {
helper.controller_before_auth_check_action(req, res)
const errors = []
console.log('***REQ BODY***: ', req.body)

const id = parseInt(req.body.userId) //TODO: CHECK THAT THIS IS SANITICED ID
console.log('TOKEN VERIFIED: ', req.authenticated)
console.log('token.data.id: ', req.decoded.id)
db.sequelize
.query(`SELECT * FROM "CourseInstances" JOIN "TeacherInstances" ON "CourseInstances"."id" = "TeacherInstances"."courseInstanceId" WHERE "TeacherInstances"."userId" = ${req.decoded.id}`)
.then(instance => res.status(200).send(instance[0]))
Expand All @@ -53,18 +50,13 @@ module.exports = {
data: undefined
}
const user = req.decoded.id
console.log(req.decoded)
console.log('user.id: ', user)
const teacher = await TeacherInstance.findAll({
where: {
userId: user,
courseInstanceId: courseInst
}
})
if (teacher[0] === undefined) {
console.log('studentti')
console.log('userId: ', user)
console.log('courseInstanceId:', courseInst)
const student = await StudentInstance.findOne({
attributes: {
exclude: ['createdAt', 'updatedAt']
Expand Down Expand Up @@ -156,7 +148,6 @@ module.exports = {
}
]
})
console.log('studentInst: ', student)

try {
if (student) {
Expand Down Expand Up @@ -267,9 +258,6 @@ module.exports = {
*/
registerToCourseInstance(req, res) {
helper.controller_before_auth_check_action(req, res)
console.log(`----------------------------------`)
console.log(req.decoded)
console.log(`----------------------------------`)

CourseInstance.findOne({
where: {
Expand All @@ -293,7 +281,6 @@ module.exports = {
})
}
let promisingThatWeboodiStatusIsChecked = new Promise((resolve, reject) => {
console.log('user.studentNumber', user.studentNumber)
helper.checkWebOodi(req, res, user, resolve) // this does not work.

setTimeout(function() {
Expand All @@ -302,9 +289,6 @@ module.exports = {
})

promisingThatWeboodiStatusIsChecked.then(barf => {
console.log('Yay! ' + barf)
console.log(req.body)

if (barf === 'found') {
StudentInstance.findOrCreate({
where: {
Expand Down Expand Up @@ -419,8 +403,6 @@ module.exports = {
update(req, res) {
helper.controller_before_auth_check_action(req, res)

console.log('REQ body: ', req.body)
console.log('REQ params: ', req.params)
CourseInstance.findOne({
where: {
ohid: req.params.id
Expand Down Expand Up @@ -519,7 +501,6 @@ module.exports = {
helper.controller_before_auth_check_action(req, res)

const termAndYear = helper.CurrentTermAndYear()
console.log('term and year: ', termAndYear)
if (this.remoteAddress === '127.0.0.1') {
res.send('gtfo')
} else {
Expand All @@ -535,8 +516,6 @@ module.exports = {
}
request(options, function(err, resp, body) {
const json = JSON.parse(body)
console.log('json palautta...')
console.log(json)
json.forEach(instance => {
CourseInstance.findOrCreate({
attributes: {
Expand Down Expand Up @@ -569,7 +548,6 @@ module.exports = {
console.log('update next...')
const auth = process.env.TOKEN || 'notset' //You have to set TOKEN in .env file in order for this to work
const termAndYear = helper.CurrentTermAndYear()
console.log('term and year: ', termAndYear)
if (auth === 'notset') {
res.send('Please restart the backend with the correct TOKEN environment variable set')
} else {
Expand All @@ -588,7 +566,6 @@ module.exports = {
}
request(options, function(err, resp, body) {
const json = JSON.parse(body)
console.log(json)
json.forEach(instance => {
CourseInstance.findOrCreate({
attributes: {
Expand Down
7 changes: 0 additions & 7 deletions backend/server/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ module.exports = {

try {
const result = request(options, function(err, resp, body) {
if (result.response) {
console.log('testitulostus: ', result.response.body)
} else {
console.log('testitulostus: result.response.body is undefined')
}
if (err) {
console.log('\nlogin: ', err, 'n')
}
if (result.response && result.response.body && result.response.body.username && result.response.body.error !== 'wrong credentials') {
let first
const last = body.last_name
const number = body.student_number
console.log('\n\n\nbody: ', body, '\n\n\n')
// If first_names from Kurki contains *, use the name after that, otherwise use first name
if (body.first_names.includes('*')) {
first = result.response.body.first_names.split('*')[1].split(' ')[0]
Expand Down Expand Up @@ -61,7 +55,6 @@ module.exports = {
email: newuser.email,
username: newuser.username
}
console.log('user: ', user)

const token = jwt.sign({ username: newuser.username, id: newuser.id }, process.env.SECRET)
res.status(200).send({
Expand Down
6 changes: 0 additions & 6 deletions backend/server/controllers/weeks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const helper = require('../helpers/weeks_controller_helper')

module.exports = {
async create(req, res) {
console.log('\n\n\nweeks.create req: ', req, '\n\n\n')
try {
await helper.controller_before_auth_check_action(req, res)

Expand Down Expand Up @@ -34,9 +33,7 @@ module.exports = {
studentInstanceId: req.body.studentInstanceId
}
})
console.log('\n\n\nweeks, week: ', week)
if (week) {
console.log('\n\nupdating a week\n\n')
let updatedChecks = {}
if (req.body.checks) {
Object.keys(week.checks).map(key => {
Expand All @@ -48,16 +45,13 @@ module.exports = {
} else {
updatedChecks = week.checks
}
console.log('\n\nreq.body.checks: ', req.body.checks, '\n\n')
console.log('\n\nupdatedChecks: ', updatedChecks, '\n\n')
await week.update({
points: req.body.points || week.points,
feedback: req.body.feedback || week.feedback,
checks: updatedChecks
})
res.status(200).send(week)
} else {
console.log('\n\ncreating a new week\n\n')
await Week.create({
points: req.body.points,
studentInstanceId: req.body.studentInstanceId,
Expand Down
5 changes: 0 additions & 5 deletions backend/server/helpers/application_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ function CurrentTermAndYear() {
const month = date.getMonth() + 1
const currentTerm = getCurrentTerm(month)
var year = date.getFullYear()
//console.log('month is: ', month)
//console.log('date: ', date)
if (month >= 11) {
year = year + 1
}
const currentYear = year.toString()
var nextYear = getNextYear(currentTerm, year)
nextYear.toString()
const nextTerm = getNextTerm(currentTerm)
//console.log('year: ', year)
return { currentYear, currentTerm, nextTerm, nextYear }
}

Expand Down Expand Up @@ -226,7 +223,6 @@ async function createCourse(body) {
}).save()

if (result.teachers.length > 0) {
console.log('')
for (let i in result.teachers) {
const user = await User.findOrCreate({
where: {
Expand All @@ -248,7 +244,6 @@ async function createCourse(body) {
} catch (error) {
console.log(error)
}
//await console.log(result.teachers)
}

/**
Expand Down
4 changes: 0 additions & 4 deletions backend/server/helpers/course_instance_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ function checkWebOodi(req, res, user, resolve) {
try {
json = JSON.parse(body)
} catch (e) {
console.log('\n\ncheckWebOodi received this body: ', body, '\n\n\n')
resolve('notfound')
return
}
console.log('\njson students to string', json['students'].toString())
if (json['students'].toString().match(user.studentNumber) !== null) {
// stupid javascript.. even regex match is simpler than json array that has or not has a key of whatever.
console.log('\ncourse_instance_helper found')
Expand Down Expand Up @@ -69,8 +67,6 @@ function findByUserStudentInstance(req, res) {
const Op = Sequelize.Op

const errors = []
console.log('\ncourse_intance_helper, searching by studentInstance...')
console.log('\n***REQ BODY***: ', req.body)

application_helpers.controller_before_auth_check_action(req, res)
if (Number.isInteger(req.decoded.id)) {
Expand Down
4 changes: 3 additions & 1 deletion labtool2.0/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const reducer = combineReducers({
redirect: redirect
})

const store = createStore(reducer, composeWithDevTools(applyMiddleware(thunk, handleRequest)))
const compose = process.env.NODE_ENV === 'production' ? (store) => store : (store) => composeWithDevTools(store)

const store = createStore(reducer, compose(applyMiddleware(thunk, handleRequest)))

export default store

0 comments on commit 3f6dd66

Please sign in to comment.