diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 3fc88ec2..d8c6a839 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -4939,8 +4939,11 @@ definitions: terms: type: array items: - type: number - format: integer + type: string + groups: + type: array + items: + type: string external: type: object description: 'READ-ONLY, OPTIONAL. Refernce to external task/issue.' @@ -5070,8 +5073,11 @@ definitions: terms: type: array items: - type: number - format: integer + type: string + groups: + type: array + items: + type: string name: type: string description: project name @@ -5254,7 +5260,7 @@ definitions: type: type: string description: The attachment type, one of 'link' or 'file' - enum: + enum: - link - file tags: @@ -6133,7 +6139,7 @@ definitions: type: array items: $ref: '#/definitions/Milestone' - + MilestoneTemplateRequest: title: Milestone template request object type: object diff --git a/migrations/20212201_project_terms_update_type.sql b/migrations/20212201_project_terms_update_type.sql new file mode 100644 index 00000000..6af47aad --- /dev/null +++ b/migrations/20212201_project_terms_update_type.sql @@ -0,0 +1,7 @@ +-- UPDATE EXISTING projects table +-- modify column `terms` + +-- drop existent column first to avoid any issues during type convertion as we don't need the data if there is any +ALTER TABLE projects DROP COLUMN "terms"; +-- now create a column with a new type +ALTER TABLE projects ADD COLUMN "terms" character varying(255)[] NOT NULL DEFAULT ARRAY[]::character varying[]::character varying(255)[]; diff --git a/migrations/20212401_project_add_groups_field.sql b/migrations/20212401_project_add_groups_field.sql new file mode 100644 index 00000000..38c65b89 --- /dev/null +++ b/migrations/20212401_project_add_groups_field.sql @@ -0,0 +1,4 @@ +-- UPDATE EXISTING projects table +-- add column `groups` + +ALTER TABLE projects ADD COLUMN "groups" character varying(255)[] NOT NULL DEFAULT ARRAY[]::character varying[]::character varying(255)[]; diff --git a/src/events/projects/index.js b/src/events/projects/index.js index 07c91986..a3db47c5 100644 --- a/src/events/projects/index.js +++ b/src/events/projects/index.js @@ -102,7 +102,8 @@ const projectPayloadSchema = Joi.object().keys({ id: Joi.number().integer().positive().required(), createdAt: Joi.date().required(), updatedAt: Joi.date().required(), - terms: Joi.array().items(Joi.number().positive()).optional(), + terms: Joi.array().items(Joi.string()).optional(), + groups: Joi.array().items(Joi.string()).optional(), name: Joi.string().required(), description: Joi.string().allow(null).allow('').optional(), type: Joi.string().max(45).required(), diff --git a/src/models/project.js b/src/models/project.js index 9d3b39f4..b9191dcd 100644 --- a/src/models/project.js +++ b/src/models/project.js @@ -16,7 +16,12 @@ module.exports = function defineProject(sequelize, DataTypes) { estimatedPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: true }, actualPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: true }, terms: { - type: DataTypes.ARRAY(DataTypes.INTEGER), + type: DataTypes.ARRAY(DataTypes.STRING), + allowNull: false, + defaultValue: [], + }, + groups: { + type: DataTypes.ARRAY(DataTypes.STRING), allowNull: false, defaultValue: [], }, diff --git a/src/routes/projects/create.js b/src/routes/projects/create.js index a7b7cd71..00b61ced 100644 --- a/src/routes/projects/create.js +++ b/src/routes/projects/create.js @@ -45,7 +45,8 @@ const createProjectValidations = { })).optional().allow(null), estimatedPrice: Joi.number().precision(2).positive().optional() .allow(null), - terms: Joi.array().items(Joi.number().positive()).optional(), + terms: Joi.array().items(Joi.string()).optional(), + groups: Joi.array().items(Joi.string()).optional(), external: Joi.object().keys({ id: Joi.string(), type: Joi.any().valid('github', 'jira', 'asana', 'other'), diff --git a/src/routes/projects/update.js b/src/routes/projects/update.js index 311f1831..70ed8e6d 100644 --- a/src/routes/projects/update.js +++ b/src/routes/projects/update.js @@ -46,7 +46,8 @@ const updateProjectValdiations = { status: Joi.any().valid(_.values(PROJECT_STATUS)), estimatedPrice: Joi.number().precision(2).positive().allow(null), actualPrice: Joi.number().precision(2).positive(), - terms: Joi.array().items(Joi.number().positive()), + terms: Joi.array().items(Joi.string()), + groups: Joi.array().items(Joi.string()), external: Joi.object().keys({ id: Joi.string(), type: Joi.any().valid('github', 'jira', 'asana', 'other'), diff --git a/src/routes/projects/update.spec.js b/src/routes/projects/update.spec.js index 24c9e9a5..6ac5c481 100644 --- a/src/routes/projects/update.spec.js +++ b/src/routes/projects/update.spec.js @@ -983,7 +983,7 @@ describe('Project', () => { Authorization: `Bearer ${testUtil.jwts.admin}`, }) .send({ - terms: [1, 2, 3], + terms: ['1', '2', '3'], }) .expect(200) .end((err) => { @@ -996,7 +996,7 @@ describe('Project', () => { createEventSpy.calledWith(BUS_API_EVENT.PROJECT_UPDATED, sinon.match({ resource: 'project', id: project1.id, - terms: [1, 2, 3], + terms: ['1', '2', '3'], updatedBy: testUtil.userIds.admin, })).should.be.true; diff --git a/src/utils/es-config.js b/src/utils/es-config.js index 24357857..5144c510 100644 --- a/src/utils/es-config.js +++ b/src/utils/es-config.js @@ -320,7 +320,10 @@ MAPPINGS[ES_PROJECT_INDEX] = { index: 'not_analyzed', }, terms: { - type: 'integer', + type: 'string', + }, + groups: { + type: 'string', }, type: { type: 'string',