rfc
rfc copied to clipboard
Create 021-server-defined-attributes.md
What does this PR do?
RFC to add optional server-defined attributes to user
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)
The idea, in general, would help a lot on the part of Appwrite-console administrators (That can be a new market title 😉) and would help in setting pre-defined field structures for validations.
One way of expanding it would be to add a default
callback using a function or other collection attributes.
This way the field value will auto-populate when no value was inserted.
Example 1 - Next appointment date. In this example the default value would come from a function while passing the current document to that function
POST https://cloud.appwrite/v1/databases/:databaseId/collections/:collectionId/attributes/server
Content-Type: application/json
origin: https://localhost
{
"id" : "next_appointment",
"type" : "datetime",
"format" : "",
"size" : 0,
"required": false,
"default" : "[FUNCTION_ID]",
"array" : false,
"filters" : []
}
Then, the function would run when the default value is empty, something like 👇, for example.
module.exports = async (context) => {
try {
// Set another appointment in 90 days.
const next = new Date(+new Date() + (84600 * 90 * 1000));
return context.res.json({ value: next });
} catch (e) {
return context.res.json({ value: '' });
}
};
Example 2 - Adding search attribute
In this example the default value would come from the rest of the fields while each %*%
variable is an attribute name in the current collection
POST https://cloud.appwrite/v1/databases/:databaseId/collections/:collectionId/attributes/server
Content-Type: application/json
origin: https://localhost
{
"id" : "search",
"type" : "string",
"format" : "",
"size" : 512,
"required": false,
"default" : "%name% %email% %address% %country% %phone%",
"array" : false,
"filters" : []
}
👀👀🔥 definitely checking this out