add backend job for user search logic
This commit is contained in:
@@ -204,6 +204,10 @@ exports.dataRegularity = async (event, context) => {
|
||||
|
||||
|
||||
const axios = require('axios');
|
||||
const admin = require("firebase-admin");
|
||||
const moment = require('moment');
|
||||
|
||||
admin.initializeApp();
|
||||
|
||||
exports.migrateUsers = async (event, context) => {
|
||||
const resource = context.resource;
|
||||
@@ -212,35 +216,47 @@ exports.migrateUsers = async (event, context) => {
|
||||
// now log the full event object
|
||||
console.log(JSON.stringify(event));
|
||||
const { _id, name } = event.value.fields;
|
||||
const { _idSearch, abhaIdSearch, aadharIdSearch } = event.value.fields;
|
||||
if (!_idSearch?.stringValue) {
|
||||
const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get();
|
||||
docs?.forEach(async (doc) => {
|
||||
await admin.firestore().collection("patientData").doc(doc.id).update({
|
||||
_idSearch: `${moment().format('YYYYMMDD')}${doc.data()._id}`,
|
||||
abhaIdSearch: `${moment().format('YYYYMMDD')}${doc.data().abhaId}`,
|
||||
aadharIdSearch: `${moment().format('YYYYMMDD')}${doc.data().aadharId}`,
|
||||
});
|
||||
console.log('search logic', _id.stringValue);
|
||||
})
|
||||
}
|
||||
const NO_OF_COPIES = 3;
|
||||
for (let i = 0; i < NO_OF_COPIES; i++) {
|
||||
await axios.post("https://asia-south1-hpos-preprod.cloudfunctions.net/registerUser",
|
||||
{
|
||||
"_id": `${_id.stringValue}${i}`,
|
||||
"aadharId": "2808202300001",
|
||||
"abhaId": "12434949797979",
|
||||
"birthYear": "2000",
|
||||
"bloodGroup": "",
|
||||
"careOf": "",
|
||||
"caste": "",
|
||||
"city": "Bengaluru",
|
||||
"district": "Bengaluru",
|
||||
"gender": "Male",
|
||||
"house": "42",
|
||||
"maritalStatus": "Single",
|
||||
"name": name.stringValue,
|
||||
"phoneNumber": "9123456789",
|
||||
"pinCode": "560060",
|
||||
"registeredBy": "admin",
|
||||
"registrationCenterName": "SMI",
|
||||
"sickleCellHistory": null,
|
||||
"state": "Karnataka",
|
||||
"subCaste": "",
|
||||
"testStatus": false,
|
||||
"underMedication": false,
|
||||
"underTransfusion": false,
|
||||
"userImageURL": "https://hpos-prod.web.app/logo.png"
|
||||
}, {
|
||||
await axios.post("https://asia-south1-hpos-preprod.cloudfunctions.net/registerUser",
|
||||
{
|
||||
"_id": `${_id.stringValue}${i}`,
|
||||
"aadharId": "2808202300001",
|
||||
"abhaId": "12434949797979",
|
||||
"birthYear": "2000",
|
||||
"bloodGroup": "",
|
||||
"careOf": "",
|
||||
"caste": "",
|
||||
"city": "Bengaluru",
|
||||
"district": "Bengaluru",
|
||||
"gender": "Male",
|
||||
"house": "42",
|
||||
"maritalStatus": "Single",
|
||||
"name": name.stringValue,
|
||||
"phoneNumber": "9123456789",
|
||||
"pinCode": "560060",
|
||||
"registeredBy": "admin",
|
||||
"registrationCenterName": "SMI",
|
||||
"sickleCellHistory": null,
|
||||
"state": "Karnataka",
|
||||
"subCaste": "",
|
||||
"testStatus": false,
|
||||
"underMedication": false,
|
||||
"underTransfusion": false,
|
||||
"userImageURL": "https://hpos-prod.web.app/logo.png"
|
||||
}, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-client": "e16a1bd15af2ee640f5a7a18c8d8333f5f01f7c66e003bbc21ee52870f1bce27"
|
||||
@@ -264,28 +280,19 @@ admin.initializeApp();
|
||||
exports.retestMarking = async (event, context) => {
|
||||
const resource = context.resource;
|
||||
// log out the resource string that triggered the function
|
||||
console.log('Function triggered by change to: ' + resource);
|
||||
console.log('Function triggered by change to: ' + resource);
|
||||
// now log the full event object
|
||||
console.log(JSON.stringify(event));
|
||||
const { _id, classificationResult } = event.value.fields;
|
||||
console.log("classificationResult", classificationResult.stringValue);
|
||||
if (classificationResult?.stringValue?.includes("Negative Borderline") || classificationResult?.stringValue?.includes("Inconclusive") || classificationResult?.stringValue?.includes("Trait")) {
|
||||
const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get();
|
||||
docs?.forEach(async (doc) => {
|
||||
await admin.firestore().collection("patientData").doc(doc.id).update({
|
||||
testStatus: false,
|
||||
retested: true
|
||||
// incubationTime: admin.firestore.FieldValue.delete()
|
||||
const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get();
|
||||
docs?.forEach(async (doc) => {
|
||||
await admin.firestore().collection("patientData").doc(doc.id).update({
|
||||
testStatus: false,
|
||||
retested: true
|
||||
// incubationTime: admin.firestore.FieldValue.delete()
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const {_idSearch, abhaIdSearch, aadharIdSearch} = event.value.fields;
|
||||
if (!_idSearch?.stringValue) {
|
||||
await admin.firestore().collection("patientData").doc(doc.id).update({
|
||||
_idSearch: `${moment().format('YYYYMMDD')}${_id}`,
|
||||
abhaIdSearch: `${moment().format('YYYYMMDD')}${abhaId}`,
|
||||
aadharIdSearch: `${moment().format('YYYYMMDD')}${aadharId}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user