mirror of
https://github.com/LukeHagar/appwrite-starter-function.git
synced 2025-12-06 04:19:14 +00:00
Swap from get and set to raw set
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Client , Databases } from 'node-appwrite';
|
||||
import { Client , Databases, ID } from 'node-appwrite';
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
@@ -24,14 +24,10 @@ export default async ({ req, res, log, error }: any) => {
|
||||
|
||||
// The `req` object contains the request data
|
||||
if (req.method === "GET") {
|
||||
const doc = await databases.getDocument(
|
||||
"metrics",
|
||||
"load",
|
||||
"65ca2f77931f5ebb7d19"
|
||||
);
|
||||
log(doc["count"]);
|
||||
await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {count: doc["count"] + 1})
|
||||
return res.send(`Count Updated`);
|
||||
await databases.createDocument("load", "bun", ID.unique(), {
|
||||
count: 1,
|
||||
});
|
||||
return res.send(`Created Record`);
|
||||
} else {
|
||||
return res.send(`Invalid request method. Please use GET.`);
|
||||
}
|
||||
|
||||
@@ -24,16 +24,10 @@ export default async ({ req, res, log, error }) => {
|
||||
|
||||
// The `req` object contains the request data
|
||||
if (req.method === "GET") {
|
||||
const doc = await databases.getDocument(
|
||||
"metrics",
|
||||
"load",
|
||||
"65ca2e4954a2e5c286d0"
|
||||
);
|
||||
log(doc["count"]);
|
||||
await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", {
|
||||
count: doc["count"] + 1,
|
||||
await databases.createDocument("load", "node", ID.unique(), {
|
||||
count: 1,
|
||||
});
|
||||
return res.send(`Count Updated`);
|
||||
return res.send(`Created Record`);
|
||||
} else {
|
||||
return res.send(`Invalid request method. Please use GET.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user