Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Trying to get underscored fields to work #19

Open
wants to merge 1 commit into
base: db_changes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions api/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ module.exports = function(sequelize, DataTypes) {
}
},
// registration start date
regStartAt: DataTypes.DATE,
regStartAt: {
type: DataTypes.DATE,
field: 'reg_start_at'
},
// submission end date
subEndAt: DataTypes.DATE,
subEndAt: {
type: DataTypes.DATE,
field: 'sub_end_at'
},
// challenge completed date
completedAt: DataTypes.DATE,
completedAt: {
type: DataTypes.DATE,
field: 'completed_at'
},
// challenge title
title: {
type: DataTypes.TEXT,
Expand All @@ -39,21 +48,42 @@ module.exports = function(sequelize, DataTypes) {
},
overview: DataTypes.STRING(140),
account: DataTypes.STRING(255),
accountId: DataTypes.STRING(255),
accountId: {
type: DataTypes.STRING(255),
field: 'account_id'
},
description: DataTypes.TEXT,
source: DataTypes.TEXT,
sourceId: DataTypes.TEXT,
sourceId: {
type: DataTypes.TEXT,
field: 'source_id'
},
tags: DataTypes.ARRAY(DataTypes.TEXT),
prizes: DataTypes.ARRAY(DataTypes.DOUBLE),
prizes: DataTypes.ARRAY(DataTypes.FLOAT),
// the phase status of challenge
status : {
type: DataTypes.ENUM,
values: ['DRAFT', 'SUBMISSION', 'REVIEW', 'COMPLETE']
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'challenges',
underscore: true,
associate : function(models) {
Challenge.hasMany(models.File);
Challenge.hasMany(models.Participant);
Expand Down
52 changes: 39 additions & 13 deletions api/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,66 @@ module.exports = function(sequelize, DataTypes) {
}
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
type: DataTypes.BIGINT,
allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
return parseInt(this.getDataValue('challenge_id'));
}
},
submissionId: {
type: DataTypes.BIGINT, allowNull: false,
type: DataTypes.BIGINT,
field: 'submission_id',
get: function() {
return parseInt(this.getDataValue('submissionId'));
return parseInt(this.getDataValue('submission_id'));
}
},
title : {type: DataTypes.TEXT},
filePath : {type: DataTypes.TEXT, allowNull: false},
filePath : {
type: DataTypes.TEXT,
allowNull: false,
field: 'file_path'
},
size : {
type: DataTypes.BIGINT, allowNull: false,
get: function() {
return parseInt(this.getDataValue('size'));
}
},
fileName : {type: DataTypes.TEXT, allowNull: false},
fileName : {
type: DataTypes.TEXT,
allowNull: false,
field: 'file_name'
},
// file storage location
storageLocation : {
type: DataTypes.ENUM,
values: ['local', 's3'],
allowNull: false
values: ['LOCAL', 'S3'],
allowNull: false,
field: 'storage_location'
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)

createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'files',
underscore: true,
associate : function(models) {
File.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
File.belongsTo(models.Submission, {foreignKey : 'submissionId'});
File.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
File.belongsTo(models.Submission, {foreignKey : 'submission_id'});

}
});
Expand Down
28 changes: 22 additions & 6 deletions api/models/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,46 @@ module.exports = function(sequelize, DataTypes) {
// user id of a participant
userId : {
type: DataTypes.BIGINT, allowNull: false,
field: 'user_id',
get: function() {
return parseInt(this.getDataValue('userId'));
}
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
// role of participant
role : {
type: DataTypes.ENUM,
values: ['owner', 'submitter', 'watcher', 'reviewer'],
values: ['OWNER', 'SUBMITTER', 'WATCHER', 'REVIEWER'],
allowNull: false
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)

createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'participants',
underscore: true,
associate : function(models) {
Participant.belongsTo(models.User, {foreignKey : 'userId'});
Participant.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Participant.belongsTo(models.User, {foreignKey : 'user_id'});
Participant.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
}
});

Expand Down
17 changes: 15 additions & 2 deletions api/models/requirement.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@ module.exports = function(sequelize, DataTypes) {
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
requirementText : DataTypes.TEXT
requirementText: {
type: DataTypes.TEXT,
field: 'requirement_text'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'requirements',
underscore: true,
associate : function(models) {
Requirement.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Requirement.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
Requirement.hasMany(models.ScorecardItem);
}
});
Expand Down
47 changes: 38 additions & 9 deletions api/models/scorecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,43 @@ module.exports = function(sequelize, DataTypes) {
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
// user id of reviewer
reviewerId: {
type: DataTypes.BIGINT,
allowNull: false,
field: 'reviewer_id',
get: function() {
return parseInt(this.getDataValue('reviewerId'));
}
},
submissionId: {
type: DataTypes.BIGINT,
allowNull: false,
field: 'submission_id',
get: function() {
return parseInt(this.getDataValue('submissionId'));
}
},
// sum of all the scorecard items scorecard
scoreSum: DataTypes.INTEGER,
// scoreSum / scoreMax from scorecard items
scorePercent: DataTypes.FLOAT,
scoreSum: {
type: DataTypes.INTEGER,
field: 'score_sum'
},
// score_sum / score_max from scorecard items
scorePercent: {
type: DataTypes.FLOAT,
field: 'score_percent'
},
// sum of highest possible score from scorecard items
scoreMax: DataTypes.FLOAT,
scoreMax: {
type: DataTypes.FLOAT,
field: 'score_max'
},
status : {
type: DataTypes.ENUM,
values: ['VALID', 'INVALID', 'LATE']
Expand All @@ -61,15 +75,30 @@ module.exports = function(sequelize, DataTypes) {
}
},
prize: DataTypes.FLOAT,
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'scorecards',
underscore: true,
associate : function(models) {
Scorecard.hasMany(models.ScorecardItem);
Scorecard.belongsTo(models.Challenge, {foreignKey: 'challengeId'});
Scorecard.belongsTo(models.Submission, {foreignKey: 'submissionId'});
Scorecard.belongsTo(models.User, {foreignKey: 'reviewerId'});
Scorecard.belongsTo(models.Challenge, {foreignKey: 'challenge_id'});
Scorecard.belongsTo(models.Submission, {foreignKey: 'submission_id'});
Scorecard.belongsTo(models.User, {foreignKey: 'reviewer_id'});
}
});

Expand Down
35 changes: 29 additions & 6 deletions api/models/scorecardItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,46 @@ module.exports = function(sequelize, DataTypes) {
},
// scorecard id of this item
scorecardId: {
type: DataTypes.BIGINT, allowNull: false,
type: DataTypes.BIGINT,
allowNull: false,
field: 'scorecard_id',
get: function() {
return parseInt(this.getDataValue('scorecardId'));
}
},
requirementId: DataTypes.INTEGER,
requirementId: {
type: DataTypes.INTEGER,
field: 'requirement_id',
get: function() {
return parseInt(this.getDataValue('requirementId'));
}
},
// score of submission
score: DataTypes.FLOAT,
// comment from reviewer
comment : DataTypes.TEXT,
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
}
}, {
tableName : 'scorecard_items',
underscore: true,
associate : function(models) {
ScorecardItem.belongsTo(models.Scorecard, {foreignKey: 'scorecardId'});
ScorecardItem.belongsTo(models.Requirement, {foreignKey: 'requirementId'});
ScorecardItem.belongsTo(models.Scorecard, {foreignKey: 'scorecard_id'});
ScorecardItem.belongsTo(models.Requirement, {foreignKey: 'requirement_id'});
}
});

Expand Down
Loading