From 810975144551aec7a31c73401e329849f309067a Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Mon, 21 Aug 2023 14:39:15 +0530 Subject: [PATCH] user registration for qc --- README.md | 4 ++ changeTestStatus.py | 6 +- cloud-functions/nodejs/.firebaserc | 5 ++ cloud-functions/nodejs/.gitignore | 66 +++++++++++++++++++++ cloud-functions/nodejs/functions/.gitignore | 1 + cloud-functions/nodejs/functions/index.js | 33 +++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 cloud-functions/nodejs/.firebaserc create mode 100644 cloud-functions/nodejs/.gitignore create mode 100644 cloud-functions/nodejs/functions/.gitignore create mode 100644 cloud-functions/nodejs/functions/index.js diff --git a/README.md b/README.md index 5a5f590..fc252ca 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,7 @@ Repo for all data related work. - microsoft excel +### functions + + https://asia-south1-hpos-af3cc.cloudfunctions.net/registerUser + diff --git a/changeTestStatus.py b/changeTestStatus.py index 8eb957a..778c920 100644 --- a/changeTestStatus.py +++ b/changeTestStatus.py @@ -1,8 +1,10 @@ import firebase_admin from firebase_admin import credentials, firestore +import os +key_path = os.getcwd() + '/scripts/keys/hpos-af3cc-firebase-adminsdk-n261k-2bfd463ec0.json' # Replace 'path/to/your/serviceAccountKey.json' with the actual path to your service account JSON file -cred = credentials.Certificate(r'C:\Users\smila\PycharmProjects\pythonqueries\hpos-af3cc-firebase-adminsdk-n261k-6ff4a63c54.json') +cred = credentials.Certificate(key_path) firebase_admin.initialize_app(cred) def move_documents(source_collection): db = firestore.client() @@ -19,7 +21,7 @@ def move_documents(source_collection): try: # Delete the document from the source collection - db.collection(source_collection).document(doc_id).update({"testStatus": False}) + db.collection(source_collection).document(doc_id).update({"testStatus": True}) print(f"Document with ID '{doc_id}' updated") except Exception as e: print(f"Error deleting document with ID '{doc_id}' from the source collection: {e}") diff --git a/cloud-functions/nodejs/.firebaserc b/cloud-functions/nodejs/.firebaserc new file mode 100644 index 0000000..0dccf08 --- /dev/null +++ b/cloud-functions/nodejs/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "hpos-af3cc" + } +} diff --git a/cloud-functions/nodejs/.gitignore b/cloud-functions/nodejs/.gitignore new file mode 100644 index 0000000..dbb58ff --- /dev/null +++ b/cloud-functions/nodejs/.gitignore @@ -0,0 +1,66 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +firebase-debug.log* +firebase-debug.*.log* + +# Firebase cache +.firebase/ + +# Firebase config + +# Uncomment this if you'd like others to create their own Firebase project. +# For a team working on the same Firebase project(s), it is recommended to leave +# it commented so all members can deploy to the same project(s) in .firebaserc. +# .firebaserc + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env diff --git a/cloud-functions/nodejs/functions/.gitignore b/cloud-functions/nodejs/functions/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/cloud-functions/nodejs/functions/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/cloud-functions/nodejs/functions/index.js b/cloud-functions/nodejs/functions/index.js new file mode 100644 index 0000000..f2cda47 --- /dev/null +++ b/cloud-functions/nodejs/functions/index.js @@ -0,0 +1,33 @@ +const { onRequest } = require("firebase-functions/v2/https"); +const logger = require("firebase-functions/logger"); +const functions = require("firebase-functions"); +const admin = require("firebase-admin"); +const moment = require('moment'); + +admin.initializeApp(); + + +exports.registerUser = functions.region("asia-south1").https.onRequest(async (req, res) => { + try { + const token = "e16a1bd15af2ee640f5a7a18c8d8333f5f01f7c66e003bbc21ee52870f1bce27"; + logger.info(`User-Agent ${req.get("User-Agent")}`); + logger.info(`token ${req.get("x-client")}`); + if (req.get("x-client") !== token) { + res.json({ status: "403", message: "auth error", result: "true" }); + } + else { + const { body } = req; + const { _id } = body; + logger.info(`_id ${_id}`); + await admin + .firestore() + .collection("patientData") + .add(Object.assign(Object.assign({}, body), { createdAt: moment().utcOffset("+05:30").format("YYYY-MM-DD HH:mm:ss") })) + res.json({ status: "200" }); + } + } + catch (err) { + logger.info(`error ${err}`); + res.json({ status: "400", message: "some error.", result: "true" }); + } +});