But it is not fixed to only hours also sometimes I need in minutes, so there will be so many functions execution each mins Ok thanks
so I need to do it like this??
try { await appwriteDatabases .createDocument( DATABASE_ID, BANNED_USERS_COLLECTION_ID, getUser.$id, { user: getUser.$id, created: "", reasons: "Violence", } ) .then(async (data) => { const originalDateTime = new Date(data.created);
const updatedDateTime = new Date(
originalDateTime.getTime() + 5 * 60 * 60 * 1000
);
await appwriteDatabases.updateDocument(
DATABASE_ID,
BANNED_USERS_COLLECTION_ID,
getUser.$id,
{
expiry: updatedDateTime,
}
);
});
log("banning_done2");
} catch (updateDocumentError) {
log("Update document error:", updateDocumentError);
}
You can trigger a function each minute
There is problem when creating new doc or update existing doc with same Id, Is there upsertDocument available in appwrite. I manually need to check if doc exist ?update :create doc
There shouldn't be any need to get the servers time or time zone.
Best practice when working with remote servers is to always handle remote timestamps in UTC.
So, you can store the unban timestamp or a banned timestamp and expiry hours and then localize the time client side
But there should be a function like appwrite.getTimestamp(), If I want to fetch some docs from now to in the past in client side using query but using functions is complicated.
If you get server timestamp client side, it will be possible to manipulate it anyways
To override the timing cooldown
That's why I recommend handling all with an Appwrite function so since it's being created server sided, it will not be possible to manipulate it to unban the user sooner than at the expected time
No i have asked to fetch some docs for example posts from now to in the past
I understand. I thought it was to ban as said. In such case, you could get too with a function it. This seems an interesting request so I recommend to create a post in the appwrite GitHub
Edit: appwrite, not appetite. My phone autocorrect is so bugged π
you don't need to get the server time
Ok, for example I need posts list of past 1 week and for this small task small query is enough like
appwrite.listDocs(..., [ Query.greaterThan( 'created', new Date(appwrite.serverTimestamp().setDate(appwrite.serverTimestamp().getDate() - 7) ) ] );
why to create cloud function??
Again, no need to get the server timestamp.
- Get the current timestamp
- Subtract 7 days
- Convert to iso 8601 in UTC
On local device??
Yes
But user can manipulate it you can check it on your Android
So what
By Changing date of device also if I use utc
Please don't randomly post like this
User can access all of my database by manipulating date
*device date
If you really care about hiding data, you'll have to either:
- make the collection private and expose the data via a function
- Only make some documents readable
Recommended threads
- The current user is not authorized to pe...
I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in wi...
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- My account is blocked so please check an...
My account is blocked so please unblock my account because all the apps are closed due to which it is causing a lot of problems