rfc icon indicating copy to clipboard operation
rfc copied to clipboard

Create 021-server-defined-attributes.md

Open vermakhushboo opened this issue 11 months ago • 2 comments

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.)

vermakhushboo avatar Mar 07 '24 13:03 vermakhushboo

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" : []
}

byawitz avatar Mar 07 '24 17:03 byawitz

👀👀🔥 definitely checking this out

jasonetorres avatar Mar 11 '24 16:03 jasonetorres