added count update

This commit is contained in:
Luke Hagar
2024-02-12 08:52:01 -06:00
parent 683aa0abac
commit 45cac7ef19
2 changed files with 28 additions and 26 deletions

View File

@@ -3,17 +3,17 @@ import { Client , Databases } from 'node-appwrite';
// This is your Appwrite function // This is your Appwrite function
// It's executed each time we get a request // It's executed each time we get a request
export default async ({ req, res, log, error }: any) => { export default async ({ req, res, log, error }: any) => {
log(req.bodyRaw); // Raw request body, contains request data // 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.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(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.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.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.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.host); // Hostname from the host header, such as awesome.appwrite.io
log(req.port); // Port from the host header, for example 8000 // log(req.port); // Port from the host header, for example 8000
log(req.path); // Path part of URL, for example /v1/hooks // 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(req.queryString); // Raw query params string. For example "limit=12&offset=50"
log(JSON.stringify(req.query)); // log(JSON.stringify(req.query));
const client = new Client() const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1') .setEndpoint('https://cloud.appwrite.io/v1')
@@ -29,8 +29,8 @@ export default async ({ req, res, log, error }: any) => {
"load", "load",
"65ca2f77931f5ebb7d19" "65ca2f77931f5ebb7d19"
); );
log(doc); log(doc["count"]);
// await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {doc.count + 1}) await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {count: doc["count"] + 1})
return res.send(`Count Updated`); return res.send(`Count Updated`);
} else { } else {
return res.send(`Invalid request method. Please use GET.`); return res.send(`Invalid request method. Please use GET.`);

View File

@@ -3,17 +3,17 @@ import { Client, Databases, ID } from "node-appwrite";
// This is your Appwrite function // This is your Appwrite function
// It's executed each time we get a request // It's executed each time we get a request
export default async ({ req, res, log, error }) => { export default async ({ req, res, log, error }) => {
log(req.bodyRaw); // Raw request body, contains request data // 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.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(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.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.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.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.host); // Hostname from the host header, such as awesome.appwrite.io
log(req.port); // Port from the host header, for example 8000 // log(req.port); // Port from the host header, for example 8000
log(req.path); // Path part of URL, for example /v1/hooks // 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(req.queryString); // Raw query params string. For example "limit=12&offset=50"
log(JSON.stringify(req.query)); // log(JSON.stringify(req.query));
const client = new Client() const client = new Client()
.setEndpoint("https://appwrite.plygrnd.org/v1") .setEndpoint("https://appwrite.plygrnd.org/v1")
@@ -29,8 +29,10 @@ export default async ({ req, res, log, error }) => {
"load", "load",
"65ca2e4954a2e5c286d0" "65ca2e4954a2e5c286d0"
); );
log(doc); log(doc["count"]);
// await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", {doc.count + 1}) await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", {
count: doc["count"] + 1,
});
return res.send(`Count Updated`); return res.send(`Count Updated`);
} else { } else {
return res.send(`Invalid request method. Please use GET.`); return res.send(`Invalid request method. Please use GET.`);