-
Notifications
You must be signed in to change notification settings - Fork 56
Improvements for product/project template refactoring #297
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
Improvements for product/project template refactoring #297
Conversation
In this task out intention to make a restriction when we create a ProductTemplate we should either define If we use Joi to validate input it works like that: in the input, we should include only one of these properties. The way when we define on of them as {
"param": {
"name": "name 1",
"productKey": "productKey 1",
"category": "generic",
"subCategory": "generic",
"icon": "http://example.com/icon1.ico",
"brief": "brief 1",
"details": "details 1",
"aliases": ["product key 1", "product_key_1"],
"isAddOn": true,
"template": {
"template1": {
"name": "template 1",
"details": {
"anyDetails": "any details 1"
},
"others": ["others 11", "others 12"]
},
"template2": {
"name": "template 2",
"details": {
"anyDetails": "any details 2"
},
"others": ["others 21", "others 22"]
}
},
"form": null
}
} It feels that such validation is not that comfortable for us. As when we get a response form the server we can get a response like this with What do you think? Should we keep like this when cannot send a What is the best way from your perspective? |
@mfikria do you think is it possible to let us submit |
@maxceem so in create endpoint we restrict the values should be non-null and in update endpoint the values could be null? |
@mfikria Not exactly. The idea is to treat At the moment we can create/edit produtTemplate by sending a body request like this: {
"param": {
"name": "name 1",
...other params...
"template": {
}
}
}
But if we send requests where we provide {
"param": {
"name": "name 1",
...other params...
"template": {
}
},
"form": null,
}
So the questions is can we treat So we can rephrase the initial task to:
Is it possible to achieve it using Joi without writing a custom logic for this? |
@maxceem yes it could be achieved, i updated the PR. Btw the error message can be override by updating JOI version so it has this feature https://github.com/hapijs/joi/blob/master/API.md#anyerrorerr-options . sample: https://stackoverflow.com/a/54657686 |
@mfikria great, thank you! I'll check it out tomorrow. The message error I think is ok for now, but thanks for mentioning it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything works good.
Thank you @mfikria for improving unit tests also.
866c8f5
into
topcoder-platform:feature/project-product-templates-final-fixes
No description provided.