user registration for qc

This commit is contained in:
Pritimay Sarkar
2023-08-21 14:39:15 +05:30
parent bf617df207
commit 8109751445
6 changed files with 113 additions and 2 deletions

View File

@@ -13,3 +13,7 @@ Repo for all data related work.
- microsoft excel
### functions
https://asia-south1-hpos-af3cc.cloudfunctions.net/registerUser

View File

@@ -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}")

View File

@@ -0,0 +1,5 @@
{
"projects": {
"default": "hpos-af3cc"
}
}

66
cloud-functions/nodejs/.gitignore vendored Normal file
View File

@@ -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

View File

@@ -0,0 +1 @@
node_modules/

View File

@@ -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" });
}
});