Skip to content

#86, #87 #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2018
Merged

#86, #87 #88

merged 5 commits into from
Jun 6, 2018

Conversation

ngoctay
Copy link
Contributor

@ngoctay ngoctay commented May 31, 2018

ngoctay added 2 commits May 31, 2018 10:49
Copy link

@vikasrohit vikasrohit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderReview I have added few comments which we need to be fixed before getting this merged.
Overall it is looking good @ngoctay

"AUTH0_CLIENT_SECRET": "",
"AUTH0_AUDIENCE": "",
"AUTH0_URL": "",
"AUTH0_CLIENT_ID": "5fctfjaLJHdvM04kSrCcC8yn0I4t1JTd",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this complete file from the commit. Where did you find these values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Will remove the AUTH_*** values from this file.
I got it from forum. It seems that we can't deploy the service without these values.

Copy link

@vikasrohit vikasrohit Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ngoctay Can you please point me to the forum?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikasrohit I found those in another topcoder-platform github project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -39,6 +36,7 @@ module.exports = function defineProject(sequelize, DataTypes) {
cancelReason: DataTypes.STRING,
version: DataTypes.STRING(15),
templateId: DataTypes.BIGINT,
projectTemplateId: DataTypes.BIGINT,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the templateId instead, which is already added to the project schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

permissions('projectType.view'),
(req, res, next) => models.ProjectType.findOne({
where: {
key: req.params.key,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not retrieve records which are deleted i.e. deletedAt is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it.
Sequelize will add the "deletedAt IS NOT NULL" condition automatically because the ProjectType model is paranoid.

    tableName: 'project_types',
    paranoid: true,
    timestamps: true,

I also have a test case to verify it in get.spec.js:

    it('should return 404 for deleted type', (done) => {
      models.ProjectType.destroy({ where: { key } })
        .then(() => {
          request(server)
            .get(`/v4/projectTypes/${key}`)
            .set({
              Authorization: `Bearer ${testUtil.jwts.admin}`,
            })
            .expect(404, done);
        });
    });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

module.exports = [
permissions('projectType.view'),
(req, res, next) => models.ProjectType.findAll({
attributes: { exclude: ['deletedAt', 'deletedBy'] },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not retrieve the deleted records i.e. where deletedAt is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with get.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay


return models.ProjectType.findOne({
where: {
key: req.params.key,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not update a deleted record i.e. where deletedAt is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with get.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

details: Joi.any(),
challengeEligibility: Joi.array().items(Joi.object().keys({
role: Joi.string().valid('submitter', 'reviewer', 'copilot'),
users: Joi.array().items(Joi.number().positive()),
groups: Joi.array().items(Joi.number().positive()),
})).allow(null),
templateId: Joi.number().positive(),
projectTemplateId: Joi.number().integer().positive(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use templateId instead of new field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

})
// Validate the projectTemplateId
.then(() => {
if (project.projectTemplateId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use templateId instead of projectTemplateId everywhere in the new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}

const phases = _.values(projectTemplate.phases);
return Promise.all(_.map(phases, phase =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to create phases before creating direct project. Please try to wrap (may be in the projects model) all project child entities creation in single promise so that projects.create does not look too much nested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to create phases before creating direct project. Please try to wrap (may be in the projects model) all project child entities creation in single promise so that projects.create does not look too much nested.

OK. Will move it to a then() right after creating the project

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap it in a single method which creates project,phase and products and use that in project.create route?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will wrap a single method which creates phases and products. Cannot wrap creating project because we need to return the project instance for creating direct project later.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't get it. Even if we wrap phase/product creation in project creation method, we can still return project object for creating direct project later. Wrapping all 3 in single method would ease having a single database transaction as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will wrap all 3 into a single method.
Regarding to the transaction, we don't need to specify it explicitly since we use continuation-local-storage.

details: Joi.any(),
memers: Joi.any(),
projectTemplateId: Joi.any().strip(), // ignore the project template id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use templateId field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return Promise.resolve();
});
})));
return createPhases(req, newProject, projectTemplate);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ngoctay for the changes, however, can we use the same database transaction, for creating phase/product, which project creation is using? I mean if project creation is not using transaction specifically, can we create a new transaction and pass that to both project and phase/product creation calls?

Copy link
Contributor Author

@ngoctay ngoctay Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reply, @vikasrohit and @coderReview

Please don't worry about the transaction.
We have the transaction wrapper already:
models.sequelize.transaction(() => {

And we don't need the option { transaction: tx } because we use continuation-local-storage.
All db operations inside the models.sequelize.transaction(() => { are automatically wrapped in the transaction.

Reference: http://docs.sequelizejs.com/manual/tutorial/transactions.html

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ngoctay for the update. Understood.

}

const phases = _.values(projectTemplate.phases);
return Promise.all(_.map(phases, phase =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't get it. Even if we wrap phase/product creation in project creation method, we can still return project object for creating direct project later. Wrapping all 3 in single method would ease having a single database transaction as well.

@vikasrohit
Copy link

Thanks @ngoctay for the hard work.

@vikasrohit vikasrohit merged commit 47c3667 into topcoder-platform:feature/dev-challenges Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants