mirror of
https://github.com/LukeHagar/appwrite-starter-function.git
synced 2025-12-06 04:19:14 +00:00
added count update
This commit is contained in:
@@ -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.`);
|
||||
|
||||
@@ -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.`);
|
||||
|
||||
Reference in New Issue
Block a user