Skip to content

Commit 1ebf0e3

Browse files
committed
Merge branch 'feature/graph-pagination-response' into feature/db-utils
2 parents d272f8a + 5b82fc0 commit 1ebf0e3

14 files changed

+49
-45
lines changed

server/cohort/cohort.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const processOutput = (profile, includeGraph) => {
1616
return output;
1717
};
1818

19-
function listLearners({ cohortId, query, options }, res) {
19+
function listLearnerStats({ cohortId, query, options }, res) {
2020
const where = { cohortId };
2121
const opts = { where, ...options };
2222
if (query.userId) where.userId = { [Op.in]: query.userId };
@@ -26,7 +26,7 @@ function listLearners({ cohortId, query, options }, res) {
2626
});
2727
}
2828

29-
function getGraph({ cohortId, learnerId }, res) {
29+
async function getLearnerStats({ cohortId, learnerId }, res) {
3030
const where = { cohortId, userId: learnerId };
3131
return LearnerProfile.findOrCreate({ where }).spread(profile => {
3232
const cohortProgress = graphService.getCohortProgress(cohortId);
@@ -50,8 +50,8 @@ async function registerLearners({ cohortId, body }, res) {
5050
}
5151

5252
module.exports = {
53-
getGraph,
54-
listLearners,
53+
getLearnerStats,
54+
listLearnerStats,
5555
getCohortProgress,
5656
registerLearners
5757
};

server/cohort/index.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,21 @@ const ctrl = require('./cohort.controller');
44
const event = require('../event');
55
const graph = require('../knowledge-graph');
66
const { LearnerProfile } = require('../common/database');
7+
const { parseNumericParam } = require('../common/middleware');
78
const router = require('express').Router();
89
const { setParser } = require('../common/pagination');
910

1011
router
11-
.use('/:cohortId*', parseCohortId)
12+
.param('cohortId', parseNumericParam)
13+
.param('learnerId', parseNumericParam)
1214
.use('/:cohortId/graph', graph.router)
1315
.use('/:cohortId/event', event.router)
1416
.get('/:cohortId/progress', ctrl.getCohortProgress)
1517
.post('/:cohortId/register', ctrl.registerLearners)
16-
.use('/:cohortId/learner/:learnerId*', parseLearnerId)
17-
.get('/:cohortId/learner/:learnerId', ctrl.getGraph)
18-
.get('/:cohortId/learner/', setParser(LearnerProfile), ctrl.listLearners);
18+
.get('/:cohortId/learner/:learnerId', ctrl.getLearnerStats)
19+
.get('/:cohortId/learner/', setParser(LearnerProfile), ctrl.listLearnerStats);
1920

2021
module.exports = {
2122
path: '/cohort',
2223
router
2324
};
24-
25-
function parseCohortId(req, _, next) {
26-
req.cohortId = parseInt(req.params.cohortId, 10);
27-
next();
28-
}
29-
30-
function parseLearnerId(req, _, next) {
31-
req.learnerId = parseInt(req.params.learnerId, 10);
32-
next();
33-
}

server/common/database/migrations/20180403080953-create-integration.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ module.exports = {
2020
createdAt: {
2121
type: Sequelize.DATE,
2222
field: 'created_at',
23+
defaultValue: Sequelize.fn('NOW'),
2324
allowNull: false
2425
},
2526
updatedAt: {
2627
type: Sequelize.DATE,
2728
field: 'updated_at',
29+
defaultValue: Sequelize.fn('NOW'),
2830
allowNull: false
2931
},
3032
deletedAt: {

server/common/database/migrations/20181006191154-ungraded-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
createdAt: {
4444
type: Sequelize.DATE,
4545
field: 'created_at',
46-
defaultValue: Sequelize.NOW,
46+
defaultValue: Sequelize.fn('NOW'),
4747
allowNull: false
4848
}
4949
}),

server/common/database/migrations/20181008063500-graded-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
createdAt: {
5353
type: Sequelize.DATE,
5454
field: 'created_at',
55-
defaultValue: Sequelize.NOW,
55+
defaultValue: Sequelize.fn('NOW'),
5656
allowNull: false
5757
}
5858
}),

server/common/database/migrations/20181008110637-repository-graph.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ module.exports = {
2222
createdAt: {
2323
type: Sequelize.DATE,
2424
field: 'created_at',
25+
defaultValue: Sequelize.fn('NOW'),
2526
allowNull: false
2627
},
2728
updatedAt: {
2829
type: Sequelize.DATE,
2930
field: 'updated_at',
31+
defaultValue: Sequelize.fn('NOW'),
3032
allowNull: false
3133
},
3234
deletedAt: {

server/common/database/migrations/20181012161152-learner-profile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ module.exports = {
2727
},
2828
repoState: {
2929
type: Sequelize.JSONB,
30+
field: 'repo_state',
3031
defaultValue: {},
3132
allowNull: false
3233
},
3334
createdAt: {
3435
type: Sequelize.DATE,
3536
field: 'created_at',
37+
defaultValue: Sequelize.fn('NOW'),
3638
allowNull: false
3739
},
3840
updatedAt: {
3941
type: Sequelize.DATE,
4042
field: 'updated_at',
43+
defaultValue: Sequelize.fn('NOW'),
4144
allowNull: false
4245
},
4346
deletedAt: {

server/common/middleware.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
function parseNumericParam(req, _, next, value, name) {
4+
req[name] = parseInt(value, 10);
5+
next();
6+
}
7+
8+
module.exports = {
9+
parseNumericParam
10+
};

server/event/graded-event.model.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ class GradedEvent extends Model {
4848
},
4949
createdAt: {
5050
type: DataTypes.DATE,
51-
field: 'created_at',
52-
defaultValue: DataTypes.NOW
51+
field: 'created_at'
5352
}
5453
};
5554
}
5655

5756
static options() {
5857
return {
5958
tableName: 'graded_event',
60-
timestamps: false,
59+
timestamps: true,
60+
updatedAt: false,
6161
freezeTableName: true
6262
};
6363
}

server/event/ungraded-event.model.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ class UngradedEvent extends Model {
4040
},
4141
createdAt: {
4242
type: DataTypes.DATE,
43-
field: 'created_at',
44-
defaultValue: DataTypes.NOW
43+
field: 'created_at'
4544
}
4645
};
4746
}
4847

4948
static options() {
5049
return {
5150
tableName: 'ungraded_event',
52-
timestamps: false,
51+
timestamps: true,
52+
updatedAt: false,
5353
freezeTableName: true
5454
};
5555
}

0 commit comments

Comments
 (0)