diff --git a/api/models/challenge.js b/api/models/challenge.js index 09dd107..e43c969 100644 --- a/api/models/challenge.js +++ b/api/models/challenge.js @@ -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, @@ -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); diff --git a/api/models/file.js b/api/models/file.js index 8405282..2db97d4 100644 --- a/api/models/file.js +++ b/api/models/file.js @@ -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'}); } }); diff --git a/api/models/participant.js b/api/models/participant.js index e79b990..5894c6c 100644 --- a/api/models/participant.js +++ b/api/models/participant.js @@ -24,12 +24,14 @@ 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')); } @@ -37,17 +39,31 @@ module.exports = function(sequelize, DataTypes) { // 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'}); } }); diff --git a/api/models/requirement.js b/api/models/requirement.js index 472f445..c5062ff 100644 --- a/api/models/requirement.js +++ b/api/models/requirement.js @@ -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); } }); diff --git a/api/models/scorecard.js b/api/models/scorecard.js index e1eb587..9d0365b 100644 --- a/api/models/scorecard.js +++ b/api/models/scorecard.js @@ -24,6 +24,7 @@ module.exports = function(sequelize, DataTypes) { }, challengeId: { type: DataTypes.BIGINT, allowNull: false, + field: 'challenge_id', get: function() { return parseInt(this.getDataValue('challengeId')); } @@ -31,22 +32,35 @@ module.exports = function(sequelize, DataTypes) { // 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'] @@ -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'}); } }); diff --git a/api/models/scorecardItem.js b/api/models/scorecardItem.js index 1ccfe45..40fb33e 100644 --- a/api/models/scorecardItem.js +++ b/api/models/scorecardItem.js @@ -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'}); } }); diff --git a/api/models/submission.js b/api/models/submission.js index 05cb2f5..19277c0 100644 --- a/api/models/submission.js +++ b/api/models/submission.js @@ -22,27 +22,46 @@ 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')); } }, // user id of submitter submitterId : { - type: DataTypes.BIGINT, allowNull: false, + type: DataTypes.BIGINT, + allowNull: false, + field: 'submitter_id', get: function() { return parseInt(this.getDataValue('submitterId')); } }, - 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 : 'submissions', + underscore: true, associate : function(models) { Submission.hasMany(models.File); Submission.hasMany(models.Scorecard); - Submission.belongsTo(models.User, {foreignKey : 'submitterId'}); - Submission.belongsTo(models.Challenge, {foreignKey : 'challengeId'}); + Submission.belongsTo(models.User, {foreignKey : 'submitter_id'}); + Submission.belongsTo(models.Challenge, {foreignKey : 'challenge_id'}); } }); diff --git a/api/models/user.js b/api/models/user.js index 27b9d2b..1028bf2 100644 --- a/api/models/user.js +++ b/api/models/user.js @@ -16,10 +16,25 @@ module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { name: DataTypes.TEXT, email: 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 : 'users', + underscore: true, associate : function(models) { User.hasMany(models.Participant); User.hasMany(models.Scorecard); diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 0542236..e5abf37 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -1463,7 +1463,7 @@ definitions: - VALID - INVALID - LATE - description: "show if this scorecard is valid ENUM:valid,invalid,late" + description: "show if this scorecard is valid ENUM:VALID,INVALID,LATE" # TODO: should next three be here or should we do a result object pay: type: boolean @@ -1571,10 +1571,10 @@ definitions: type: string description: The role the participant has on the challenge enum: - - owner - - submitter - - watcher - - reviewer + - OWNER + - SUBMITTER + - WATCHER + - REVIEWER createdAt: type: string format: date-time diff --git a/config/schema-migrations/20141010150000-enums.js b/config/schema-migrations/20141010150000-enums.js index 058b8e6..0a1fa51 100644 --- a/config/schema-migrations/20141010150000-enums.js +++ b/config/schema-migrations/20141010150000-enums.js @@ -7,9 +7,9 @@ exports.up = function (db, callback) { db.runSql.bind(db, "CREATE TYPE enum_challenges_status AS ENUM ( 'DRAFT', 'SUBMISSION', 'REVIEW', 'COMPLETE');"), db.runSql.bind(db, - "CREATE TYPE \"enum_files_storageLocation\" AS ENUM ('local', 's3');"), + "CREATE TYPE enum_files_storage_location AS ENUM ('LOCAL', 'S3');"), db.runSql.bind(db, - "CREATE TYPE enum_participants_role AS ENUM ('owner', 'submitter', 'watcher', 'reviewer');"), + "CREATE TYPE enum_participants_role AS ENUM ('OWNER', 'SUBMITTER', 'WATCHER', 'REVIEWER');"), db.runSql.bind(db, "CREATE TYPE enum_scorecards_status AS ENUM ('VALID', 'INVALID', 'LATE');") ], callback); @@ -18,7 +18,7 @@ exports.up = function (db, callback) { exports.down = function (db, callback) { async.series([ db.runSql.bind(db, "DROP TYPE enum_challenges_status;"), - db.runSql.bind(db, "DROP TYPE \"enum_files_storageLocation\";"), + db.runSql.bind(db, "DROP TYPE enum_files_storage_location;"), db.runSql.bind(db, "DROP TYPE enum_participants_role;"), db.runSql.bind(db, "DROP TYPE enum_scorecards_status;") ], callback); diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index 34c634d..e1fe4d2 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -5,133 +5,118 @@ var type = dbm.dataType; exports.up = function (db, callback) { async.series([ // challenges table - db.runSql.bind(db, - 'CREATE TABLE challenges ( ' + - 'id bigserial NOT NULL, ' + - '"regStartAt" timestamp with time zone, ' + - '"subEndAt" timestamp with time zone, ' + - '"completedAt" timestamp with time zone, ' + - 'title text NOT NULL DEFAULT \'Untitled Challenge\'::text, ' + - 'overview character varying(140), ' + - 'description text, ' + - 'tags text[], ' + - 'prizes NUMERIC(11,2)[], ' + - 'account character varying(255), ' + - '"accountId" character varying(255), ' + - '"source" text, ' + - '"sourceId" text, ' + - 'status enum_challenges_status NOT NULL, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128) ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY challenges ADD CONSTRAINT challenges_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'challenges', { + id: { type: 'int', primaryKey: true, autoIncrement: true }, + reg_start_at: 'datetime', + sub_end_at: 'datetime', + completed_at: 'datetime', + title: { type: 'text', notNull: true }, + overview: { type: 'string', length: 140 }, + description: 'text', + account: { type: 'string', length: 255 }, + account_id: { type: 'string', length: 255 }, + source: 'text', + source_id: 'text', + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 } + }), + db.runSql.bind(db, 'ALTER TABLE challenges ADD COLUMN tags text[];'), + db.runSql.bind(db, 'ALTER TABLE challenges ADD COLUMN prizes NUMERIC(11,2)[];'), + db.runSql.bind(db, 'ALTER TABLE challenges ADD COLUMN status enum_challenges_status NOT NULL;'), // files table - db.runSql.bind(db, - 'CREATE TABLE files ( ' + - 'id bigserial NOT NULL, ' + - 'title text, ' + - '"filePath" text NOT NULL, ' + - 'size bigint NOT NULL, ' + - '"fileName" text NOT NULL, ' + - '"storageLocation" "enum_files_storageLocation" NOT NULL, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128), ' + - '"submissionId" bigint, ' + - '"challengeId" bigint NOT NULL ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY files ADD CONSTRAINT files_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'files', { + id: { type: 'int', primaryKey: true, autoIncrement: true }, + title: 'text', + file_path: { type: 'text', notNull: true }, + size: { type: 'bigint', notNull: true }, + file_name: { type: 'text', notNull: true }, + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 }, + submission_id: 'bigint', + challenge_id: { type: 'bigint', notNull: true } + }), + db.runSql.bind(db, 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT NULL;'), // participants table - db.runSql.bind(db, - 'CREATE TABLE participants ( ' + - 'id bigserial NOT NULL, ' + - 'role enum_participants_role NOT NULL, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128), ' + - '"challengeId" bigint NOT NULL, ' + - '"userId" bigint NOT NULL ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY participants ADD CONSTRAINT participants_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'participants', { + id: { type: 'int', primaryKey: true, autoIncrement: true }, + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 }, + challenge_id: { type: 'bigint', notNull: true }, + user_id: { type: 'bigint', notNull: true } + }), + db.runSql.bind(db, 'ALTER TABLE participants ADD COLUMN role enum_participants_role NOT NULL;'), // submissions table - db.runSql.bind(db, - 'CREATE TABLE submissions ( ' + - 'id bigserial NOT NULL, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128), ' + - '"challengeId" bigint NOT NULL, ' + - '"submitterId" bigint NOT NULL ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY submissions ADD CONSTRAINT submissions_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'submissions', { + id: { type: 'int', primaryKey: true, autoIncrement: true }, + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 }, + challenge_id: { type: 'bigint', notNull: true }, + submitter_id: { type: 'bigint', notNull: true } + }), // scorecards table - db.runSql.bind(db, - 'CREATE TABLE scorecards ( ' + - 'id bigserial NOT NULL, ' + - '"scoreSum" integer, ' + - '"scorePercent" double precision, ' + - '"scoreMax" double precision, ' + - 'status enum_scorecards_status, ' + - 'pay boolean, ' + - 'place integer, ' + - 'prize double precision, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128), ' + - '"reviewerId" bigint NOT NULL, ' + - '"submissionId" bigint NOT NULL, ' + - '"challengeId" bigint NOT NULL ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY scorecards ADD CONSTRAINT scorecards_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'scorecards', { + id: { type: 'int', primaryKey: true, autoIncrement: true }, + score_sum: 'int', + pay: 'boolean', + place: 'int', + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 }, + reviewer_id: { type: 'bigint', notNull: true }, + submission_id: { type: 'bigint', notNull: true }, + challenge_id: { type: 'bigint', notNull: true } + }), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN score_percent double precision;'), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN score_max double precision;'), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status;'), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN prize double precision;'), // scorecard_items table - db.runSql.bind(db, - 'CREATE TABLE scorecard_items ( ' + - 'id bigserial NOT NULL, ' + - '"requirementId" integer, ' + - 'score double precision, ' + - 'comment text, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128), ' + - '"scorecardId" bigint NOT NULL ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY scorecard_items ADD CONSTRAINT scorecard_items_pkey PRIMARY KEY (id);'), + db.createTable.bind(db, 'scorecard_items', { + id: {type: 'int', primaryKey: true, autoIncrement: true}, + requirement_id: 'int', + comment: 'text', + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 }, + scorecard_id: { type: 'bigint', notNull: true } + }), + db.runSql.bind(db, 'ALTER TABLE scorecard_items ADD COLUMN score double precision;'), // requirements table - db.runSql.bind(db, - 'CREATE TABLE requirements ( ' + - 'id bigserial NOT NULL, ' + - '"requirementText" text, ' + - '"challengeId" bigint NOT NULL REFERENCES challenges("id") ON UPDATE CASCADE ON DELETE SET NULL, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL ' + - ');'), + db.createTable.bind(db, 'requirements', { + id: {type: 'int', primaryKey: true, autoIncrement: true}, + requirement_text: 'text', + challenge_id: { type: 'bigint', notNull: true }, + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true } + }), + db.runSql.bind(db, 'ALTER TABLE requirements ADD CONSTRAINT requirements_challenge_fk FOREIGN KEY (challenge_id) REFERENCES challenges (id) ON UPDATE CASCADE ON DELETE SET NULL;'), // users table - db.runSql.bind(db, - 'CREATE TABLE users ( ' + - 'id bigserial NOT NULL, ' + - 'name text, ' + - 'email text, ' + - '"createdAt" timestamp with time zone NOT NULL, ' + - '"updatedAt" timestamp with time zone NOT NULL, ' + - '"createdBy" character varying(128), ' + - '"updatedBy" character varying(128) ' + - ');'), - db.runSql.bind(db, 'ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY KEY (id);') - + db.createTable.bind(db, 'users', { + id: {type: 'int', primaryKey: true, autoIncrement: true}, + name: 'text', + email: 'text', + created_at: { type: 'datetime', notNull: true }, + updated_at: { type: 'datetime', notNull: true }, + created_by: { type: 'string', length: 128 }, + updated_by: { type: 'string', length: 128 } + }), ], callback); }; diff --git a/lib/controllerHelper.js b/lib/controllerHelper.js index aef0144..ca0d7b8 100644 --- a/lib/controllerHelper.js +++ b/lib/controllerHelper.js @@ -17,6 +17,10 @@ var paramHelper = require('./paramHelper'); var partialResponseHelper = require('./partialResponseHelper'); +function _toUnderscored(value) { + return value.replace(/([A-Z])/g, function($1) { return '_' + $1.toLowerCase(); }); +} + /** * Find an entity with the provided filters and its own id. * @param model the entity model @@ -195,6 +199,19 @@ function getAllEntities(model, referenceModels, options, req, res, next) { }); } + if (filters.where && referenceModels) { + var referenceIds = []; + referenceModels.forEach(function (referenceModel) { + referenceIds.push(routeHelper.getRefIdField(referenceModel)); + }); + _.keys(filters.where).forEach(function (filterKey) { + if (referenceIds.indexOf(filterKey) !== -1) { + filters.where[_toUnderscored(filterKey)] = filters.where[filterKey]; + delete filters.where[filterKey]; + } + }); + } + model.findAndCountAll(filters).success(function(result) { callback(null, result.count, result.rows); }) diff --git a/package.json b/package.json index d59d4b2..6367c66 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "multiparty": "^3.3.2", "newrelic": "^1.12.1", "pg": "^3.4.1", - "sequelize": "^1.7.10", + "sequelize": "^2.0.0-rc2", "swagger-tools": ">=0.6.11", "time-grunt": "^0.3.1", "inflection": "1.5.1", diff --git a/test/controllers/challenges.js b/test/controllers/challenges.js index aa8760e..9da6a2e 100644 --- a/test/controllers/challenges.js +++ b/test/controllers/challenges.js @@ -206,6 +206,8 @@ describe('Challenges Controller', function() { Challenge.create(challengeData).success(function(savedEntity) { challenges.push(savedEntity); callback(); + }).error(function (err) { + done(err); }); }, function(err) { should.not.exist(err); @@ -456,7 +458,7 @@ describe('Challenges Controller', function() { filePath: '/uploads', size: 123, fileName: 'my-submission.zip', - storageLocation: 'local' + storageLocation: 'LOCAL' }; done(); }); @@ -637,7 +639,7 @@ describe('Challenges Controller', function() { var participantId; beforeEach(function(done) { reqData = { - role: 'submitter', + role: 'SUBMITTER', userId: 222 }; done(); @@ -782,7 +784,7 @@ describe('Challenges Controller', function() { it('should able to update the existing participant', function(done) { // send request - reqData.role = 'reviewer'; + reqData.role = 'REVIEWER'; request(url) .put('/challenges/'+challenge.id+'/participants/'+participantId) .send(reqData) @@ -798,7 +800,7 @@ describe('Challenges Controller', function() { }); it('should able to update the existing participant without challengeId in request body', function(done) { - reqData.role = 'submitter'; + reqData.role = 'SUBMITTER'; // send request request(url) .put('/challenges/'+challenge.id+'/participants/' + participantId) diff --git a/test/controllers/files.js b/test/controllers/files.js index 5826390..317c9f3 100644 --- a/test/controllers/files.js +++ b/test/controllers/files.js @@ -65,7 +65,7 @@ describe('Files Controller', function() { filePath: '/uploads', size: 123, fileName: 'my-submission.zip', - storageLocation: 'local' + storageLocation: 'LOCAL' }; done(); }); diff --git a/test/models/file.js b/test/models/file.js index 8cc49d1..c42940c 100644 --- a/test/models/file.js +++ b/test/models/file.js @@ -39,7 +39,7 @@ describe('', function() { filePath: '/uploads', size: 123, fileName: 'my-submission.zip', - storageLocation: 'local', + storageLocation: 'LOCAL', challengeId: 111 }; done(); diff --git a/test/models/participant.js b/test/models/participant.js index edfaa6f..e98df6e 100644 --- a/test/models/participant.js +++ b/test/models/participant.js @@ -35,7 +35,7 @@ describe('', function() { describe('Model Participant:', function() { beforeEach(function(done) { data = { - role: 'submitter', + role: 'SUBMITTER', challengeId: 111, userId: 222 }; @@ -138,7 +138,7 @@ describe('', function() { }); it('should able to update a participant with valid id', function(done) { - entity.role = 'reviewer'; + entity.role = 'REVIEWER'; // update an entity entity.save().success(function(updatedEntity) { updatedEntity.id.should.equal(entity.id);