From 45cac7ef19a2610d660745bbe0256ddcb6035926 Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Mon, 12 Feb 2024 08:52:01 -0600 Subject: [PATCH] added count update --- functions/bun/src/main.ts | 26 +++++++++++++------------- functions/node/src/main.js | 28 +++++++++++++++------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/functions/bun/src/main.ts b/functions/bun/src/main.ts index ba3d9b9..2c8e11e 100644 --- a/functions/bun/src/main.ts +++ b/functions/bun/src/main.ts @@ -3,17 +3,17 @@ import { Client , Databases } from 'node-appwrite'; // This is your Appwrite function // It's executed each time we get a request export default async ({ req, res, log, error }: any) => { - log(req.bodyRaw); // Raw request body, contains request data - log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string - log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase - log(req.scheme); // Value of the x-forwarded-proto header, usually http or https - log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc. - log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 - log(req.host); // Hostname from the host header, such as awesome.appwrite.io - log(req.port); // Port from the host header, for example 8000 - log(req.path); // Path part of URL, for example /v1/hooks - log(req.queryString); // Raw query params string. For example "limit=12&offset=50" - log(JSON.stringify(req.query)); + // log(req.bodyRaw); // Raw request body, contains request data + // log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string + // log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase + // log(req.scheme); // Value of the x-forwarded-proto header, usually http or https + // log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc. + // log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 + // log(req.host); // Hostname from the host header, such as awesome.appwrite.io + // log(req.port); // Port from the host header, for example 8000 + // log(req.path); // Path part of URL, for example /v1/hooks + // log(req.queryString); // Raw query params string. For example "limit=12&offset=50" + // log(JSON.stringify(req.query)); const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') @@ -29,8 +29,8 @@ export default async ({ req, res, log, error }: any) => { "load", "65ca2f77931f5ebb7d19" ); - log(doc); - // await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {doc.count + 1}) + log(doc["count"]); + await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {count: doc["count"] + 1}) return res.send(`Count Updated`); } else { return res.send(`Invalid request method. Please use GET.`); diff --git a/functions/node/src/main.js b/functions/node/src/main.js index 5701b3e..828a6c8 100644 --- a/functions/node/src/main.js +++ b/functions/node/src/main.js @@ -3,17 +3,17 @@ import { Client, Databases, ID } from "node-appwrite"; // This is your Appwrite function // It's executed each time we get a request export default async ({ req, res, log, error }) => { - log(req.bodyRaw); // Raw request body, contains request data - log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string - log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase - log(req.scheme); // Value of the x-forwarded-proto header, usually http or https - log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc. - log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 - log(req.host); // Hostname from the host header, such as awesome.appwrite.io - log(req.port); // Port from the host header, for example 8000 - log(req.path); // Path part of URL, for example /v1/hooks - log(req.queryString); // Raw query params string. For example "limit=12&offset=50" - log(JSON.stringify(req.query)); + // log(req.bodyRaw); // Raw request body, contains request data + // log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string + // log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase + // log(req.scheme); // Value of the x-forwarded-proto header, usually http or https + // log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc. + // log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50 + // log(req.host); // Hostname from the host header, such as awesome.appwrite.io + // log(req.port); // Port from the host header, for example 8000 + // log(req.path); // Path part of URL, for example /v1/hooks + // log(req.queryString); // Raw query params string. For example "limit=12&offset=50" + // log(JSON.stringify(req.query)); const client = new Client() .setEndpoint("https://appwrite.plygrnd.org/v1") @@ -29,8 +29,10 @@ export default async ({ req, res, log, error }) => { "load", "65ca2e4954a2e5c286d0" ); - log(doc); - // await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", {doc.count + 1}) + log(doc["count"]); + await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", { + count: doc["count"] + 1, + }); return res.send(`Count Updated`); } else { return res.send(`Invalid request method. Please use GET.`);