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

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