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,6 +216,18 @@ 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",
|
||||
@@ -279,13 +295,4 @@ exports.retestMarking = async (event, context) => {
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
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