add register function in new folder structure

This commit is contained in:
Pritimay Sarkar
2024-02-19 20:26:46 +05:30
parent a4eed82e48
commit 9417a73b8a
8 changed files with 15076 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"csv-parser": "^3.0.0",
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1",
"html-pdf-node": "^1.0.8",
"moment": "^2.29.4",
"axios": "1.6.2"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0"
},
"private": true
}

View File

@@ -0,0 +1,16 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
node_modules

View File

@@ -0,0 +1,45 @@
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');
const fs = require('fs');
const csv = require('csv-parser');
const html_to_pdf = require('html-pdf-node');
admin.initializeApp();
exports.registerUser = functions.region("asia-south1").https.onRequest(async (req, res) => {
res.set('Access-Control-Allow-Origin', "*")
res.set('Access-Control-Allow-Methods', 'GET, POST');
if (req.method === "OPTIONS") {
// stop preflight requests here
res.set("Access-Control-Allow-Headers", "Content-Type, x-client");
res.status(204).send('');
return;
}
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" });
}
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"csv-parser": "^3.0.0",
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.7.0",
"html-pdf-node": "^1.0.8",
"moment": "^2.29.4"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0"
},
"private": true
}

View File

@@ -0,0 +1,14 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"venv",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}