v1.1.0/release
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "functions",
|
||||
"name": "vaxandme-api",
|
||||
"scripts": {
|
||||
"lint": "eslint --ext .js,.ts .",
|
||||
"build": "tsc",
|
||||
|
||||
+218
-134
@@ -19,24 +19,39 @@ admin.initializeApp({
|
||||
credential: admin.credential.cert(params),
|
||||
});
|
||||
|
||||
const VAX_NAMES : Record<string, string> = {
|
||||
const VAX_NAMES: Record<string, string> = {
|
||||
PB: "Pfizer-BioNTech",
|
||||
MD: "Moderna",
|
||||
JJ: "J&J Janssen",
|
||||
};
|
||||
|
||||
const VAX_DOSES : Record<string, string> = {
|
||||
const VAX_DOSES: Record<string, string> = {
|
||||
ONE: "Dose 1",
|
||||
TWO: "Dose 2",
|
||||
};
|
||||
|
||||
const VAX_AGES: Record<string, Record<string, string>> = {
|
||||
"Pfizer-BioNTech": {
|
||||
YOUNGER: "18 - 55",
|
||||
OLDER: "56 & Older",
|
||||
},
|
||||
"Moderna": {
|
||||
YOUNGER: "18 - 64",
|
||||
OLDER: "65 & Older",
|
||||
},
|
||||
"J&J Janssen": {
|
||||
YOUNGER: "18 - 59",
|
||||
OLDER: "60 & Older",
|
||||
},
|
||||
};
|
||||
|
||||
type SaveResultRequestData = {
|
||||
name: string;
|
||||
age: string;
|
||||
dose: string;
|
||||
gid: string;
|
||||
} & {
|
||||
[x: string] : boolean;
|
||||
[x: string]: boolean;
|
||||
};
|
||||
|
||||
const serializeGaId = (_gaid: string): string => {
|
||||
@@ -46,86 +61,90 @@ const serializeGaId = (_gaid: string): string => {
|
||||
return "";
|
||||
};
|
||||
|
||||
const addResultToStats = async (data : SaveResultRequestData) => {
|
||||
const cleanData : Record<string, any> =
|
||||
Object.assign({}, data);
|
||||
const addResultToStats = async (data: SaveResultRequestData) => {
|
||||
const cleanData: Record<string, any> = Object.assign({}, data);
|
||||
delete cleanData.name;
|
||||
delete cleanData.dose;
|
||||
delete cleanData.age;
|
||||
delete cleanData.gid;
|
||||
const updateDoc : Record<string, admin.firestore.FieldValue> = {
|
||||
const updateDoc: Record<string, admin.firestore.FieldValue> = {
|
||||
count: admin.firestore.FieldValue.increment(1),
|
||||
};
|
||||
if (data.name === VAX_NAMES.PB || data.name === VAX_NAMES.MD) {
|
||||
if (data.dose === VAX_DOSES.ONE) {
|
||||
updateDoc[`${VAX_DOSES.ONE}.${data.age}.count`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${VAX_DOSES.ONE}.${data.age}.count`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
} else if (data.dose === VAX_DOSES.TWO) {
|
||||
updateDoc[`${VAX_DOSES.ONE}.${data.age}.count`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[`${VAX_DOSES.TWO}.${data.age}.count`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${VAX_DOSES.ONE}.${data.age}.count`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${VAX_DOSES.TWO}.${data.age}.count`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
}
|
||||
Object.keys(VAX_DOSES).forEach((doseKey : string) => {
|
||||
const dose : string = VAX_DOSES[doseKey];
|
||||
Object.keys(cleanData[dose]).forEach((symptom : string) => {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey: string) => {
|
||||
const dose: string = VAX_DOSES[doseKey];
|
||||
Object.keys(cleanData[dose]).forEach((symptom: string) => {
|
||||
if (cleanData[dose][symptom]) {
|
||||
let updateDocSymptom = symptom.replace("/", "OR");
|
||||
if (symptom === "DIARRHEA") {
|
||||
updateDocSymptom = "DIRRHEA";
|
||||
}
|
||||
updateDoc[`${dose}.${data.age}.${updateDocSymptom}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${dose}.${data.age}.${updateDocSymptom}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
updateDoc[`${data.age}.count`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
Object.keys(cleanData).forEach((symptom : string) => {
|
||||
updateDoc[`${data.age}.count`] = admin.firestore.FieldValue.increment(1);
|
||||
Object.keys(cleanData).forEach((symptom: string) => {
|
||||
let updateDocSymptom = symptom.replace("/", "OR");
|
||||
if (symptom === "DIARRHEA") {
|
||||
updateDocSymptom = "DIRRHEA";
|
||||
}
|
||||
updateDoc[`${data.age}.${updateDocSymptom}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${data.age}.${updateDocSymptom}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
});
|
||||
}
|
||||
admin.firestore().collection("stats").doc(data.name).update(updateDoc);
|
||||
};
|
||||
|
||||
const removeResultFromStats = async (data : FirebaseFirestore.DocumentData) => {
|
||||
const cleanData : Record<string, any> =
|
||||
Object.assign({}, data);
|
||||
const removeResultFromStats = async (data: FirebaseFirestore.DocumentData) => {
|
||||
const cleanData: Record<string, any> = Object.assign({}, data);
|
||||
delete cleanData.name;
|
||||
delete cleanData.dose;
|
||||
delete cleanData.age;
|
||||
delete cleanData.gid;
|
||||
const updateDoc : Record<string, admin.firestore.FieldValue> = {
|
||||
const updateDoc: Record<string, admin.firestore.FieldValue> = {
|
||||
count: admin.firestore.FieldValue.increment(-1),
|
||||
};
|
||||
if (data.name === VAX_NAMES.PB || data.name === VAX_NAMES.MD) {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey : string) => {
|
||||
const dose : string = VAX_DOSES[doseKey];
|
||||
Object.keys(cleanData[dose]).forEach((symptom : string) => {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey: string) => {
|
||||
const dose: string = VAX_DOSES[doseKey];
|
||||
Object.keys(cleanData[dose]).forEach((symptom: string) => {
|
||||
if (cleanData[dose][symptom]) {
|
||||
let updateDocSymptom = symptom.replace("/", "OR");
|
||||
if (symptom === "DIARRHEA") {
|
||||
updateDocSymptom = "DIRRHEA";
|
||||
}
|
||||
updateDoc[`${dose}.${data.age}.${updateDocSymptom}`] =
|
||||
admin.firestore.FieldValue.increment(-1);
|
||||
updateDoc[
|
||||
`${dose}.${data.age}.${updateDocSymptom}`
|
||||
] = admin.firestore.FieldValue.increment(-1);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Object.keys(cleanData).forEach((symptom : string) => {
|
||||
Object.keys(cleanData).forEach((symptom: string) => {
|
||||
let updateDocSymptom = symptom.replace("/", "OR");
|
||||
if (symptom === "DIARRHEA") {
|
||||
updateDocSymptom = "DIRRHEA";
|
||||
}
|
||||
updateDoc[`${data.age}.${updateDocSymptom}`] =
|
||||
admin.firestore.FieldValue.increment(-1);
|
||||
updateDoc[
|
||||
`${data.age}.${updateDocSymptom}`
|
||||
] = admin.firestore.FieldValue.increment(-1);
|
||||
});
|
||||
}
|
||||
admin.firestore().collection("stats").doc(data.name).update(updateDoc);
|
||||
@@ -134,18 +153,67 @@ const removeResultFromStats = async (data : FirebaseFirestore.DocumentData) => {
|
||||
/**
|
||||
* FUNCTIONS FROM V1.1.0 TO CURRENT
|
||||
*/
|
||||
export const getStatsV1 = functions.https.onCall(
|
||||
async () => {
|
||||
const stats = await admin.firestore().collection("stats").get();
|
||||
const docs = stats.docs
|
||||
.map((docSnap) => ({name: docSnap.id, result: docSnap.data()}));
|
||||
const returnData : Record<string, unknown> = {};
|
||||
docs.forEach((vaxResult) => {
|
||||
returnData[vaxResult.name] = {};
|
||||
returnData[vaxResult.name] = vaxResult.result;
|
||||
export const getStatsV1 = functions.https.onCall(async () => {
|
||||
const stats = await admin.firestore().collection("stats").get();
|
||||
const docs = stats.docs.map((docSnap) => ({
|
||||
name: docSnap.id,
|
||||
result: docSnap.data(),
|
||||
}));
|
||||
const returnData: Record<string, unknown> = {};
|
||||
docs.forEach((vaxResult) => {
|
||||
if (vaxResult.name === VAX_NAMES.PB || vaxResult.name === VAX_NAMES.MD) {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey) => {
|
||||
const dose: string = VAX_DOSES[doseKey];
|
||||
Object.keys(VAX_AGES[vaxResult.name]).forEach((ageKey) => {
|
||||
const age: string = VAX_AGES[vaxResult.name][ageKey];
|
||||
if (vaxResult.result[dose][age]["NAUSEA / VOMITING"] >= 0) {
|
||||
if (vaxResult.result[dose][age]["NAUSEA OR VOMITING"] >= 0) {
|
||||
vaxResult.result[dose][age]["NAUSEA OR VOMITING"] +=
|
||||
vaxResult.result[dose][age]["NAUSEA / VOMITING"];
|
||||
} else {
|
||||
vaxResult.result[dose][age]["NAUSEA OR VOMITING"] =
|
||||
vaxResult.result[dose][age]["NAUSEA / VOMITING"];
|
||||
}
|
||||
}
|
||||
if (vaxResult.result[dose][age]["DIRRHEA"] >= 0) {
|
||||
if (vaxResult.result[dose][age]["DIARRHEA"] >= 0) {
|
||||
vaxResult.result[dose][age]["DIARRHEA"] +=
|
||||
vaxResult.result[dose][age]["DIRRHEA"];
|
||||
} else {
|
||||
vaxResult.result[dose][age]["DIARRHEA"] =
|
||||
vaxResult.result[dose][age]["DIRRHEA"];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return returnData;
|
||||
});
|
||||
} else {
|
||||
Object.keys(VAX_AGES[vaxResult.name]).forEach((ageKey) => {
|
||||
const age: string = VAX_AGES[vaxResult.name][ageKey];
|
||||
if (vaxResult.result[age]["NAUSEA / VOMITING"] >= 0) {
|
||||
if (vaxResult.result[age]["NAUSEA OR VOMITING"] >= 0) {
|
||||
vaxResult.result[age]["NAUSEA OR VOMITING"] +=
|
||||
vaxResult.result[age]["NAUSEA / VOMITING"];
|
||||
} else {
|
||||
vaxResult.result[age]["NAUSEA OR VOMITING"] =
|
||||
vaxResult.result[age]["NAUSEA / VOMITING"];
|
||||
}
|
||||
}
|
||||
if (vaxResult.result[age]["DIRRHEA"] >= 0) {
|
||||
if (vaxResult.result[age]["DIARRHEA"] >= 0) {
|
||||
vaxResult.result[age]["DIARRHEA"] +=
|
||||
vaxResult.result[age]["DIRRHEA"];
|
||||
} else {
|
||||
vaxResult.result[age]["DIARRHEA"] =
|
||||
vaxResult.result[age]["DIRRHEA"];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
returnData[vaxResult.name] = {};
|
||||
returnData[vaxResult.name] = vaxResult.result;
|
||||
});
|
||||
return returnData;
|
||||
});
|
||||
|
||||
export const saveResultV1 = functions.https.onCall(
|
||||
async (data: SaveResultRequestData, context) => {
|
||||
@@ -159,8 +227,7 @@ export const saveResultV1 = functions.https.onCall(
|
||||
.get()
|
||||
.then((docSnap) => docSnap.data());
|
||||
// Update user result
|
||||
const cleanData : Record<string, any> =
|
||||
Object.assign({}, data);
|
||||
const cleanData: Record<string, any> = Object.assign({}, data);
|
||||
delete cleanData.gid;
|
||||
await admin
|
||||
.firestore()
|
||||
@@ -175,73 +242,80 @@ export const saveResultV1 = functions.https.onCall(
|
||||
await addResultToStats(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const getPastResultV1 =
|
||||
functions.https.onCall(async (data : {gid:string}, context) => {
|
||||
if (!!data && !!context) {
|
||||
const {gid} = data;
|
||||
let hasToUpdateDb = false;
|
||||
const existingData : admin.firestore.DocumentData | undefined =
|
||||
export const getPastResultV1 = functions.https.onCall(
|
||||
async (data: { gid: string }, context) => {
|
||||
if (!!data && !!context) {
|
||||
const {gid} = data;
|
||||
let hasToUpdateDb = false;
|
||||
const existingData: admin.firestore.DocumentData | undefined =
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("results")
|
||||
.doc(serializeGaId(gid))
|
||||
.get()
|
||||
.then((doc) => doc.data());
|
||||
if (existingData) {
|
||||
const returnData : admin.firestore.DocumentData | undefined =
|
||||
Object.assign({}, existingData);
|
||||
if (existingData.name === VAX_NAMES.PB ||
|
||||
existingData.name === VAX_NAMES.MD) {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey : string) => {
|
||||
const dose : string = VAX_DOSES[doseKey];
|
||||
if (!existingData[dose]) {
|
||||
hasToUpdateDb = true;
|
||||
const temp : Record<string, unknown> = {};
|
||||
Object.keys(existingData).forEach((symptom) => {
|
||||
if (symptom !== "name" &&
|
||||
if (existingData) {
|
||||
const returnData:
|
||||
| admin.firestore.DocumentData
|
||||
| undefined = Object.assign({}, existingData);
|
||||
if (
|
||||
existingData.name === VAX_NAMES.PB ||
|
||||
existingData.name === VAX_NAMES.MD
|
||||
) {
|
||||
Object.keys(VAX_DOSES).forEach((doseKey: string) => {
|
||||
const dose: string = VAX_DOSES[doseKey];
|
||||
if (!existingData[dose]) {
|
||||
hasToUpdateDb = true;
|
||||
const temp: Record<string, unknown> = {};
|
||||
Object.keys(existingData).forEach((symptom) => {
|
||||
if (
|
||||
symptom !== "name" &&
|
||||
symptom !== "age" &&
|
||||
symptom !== "dose") {
|
||||
if (existingData.dose === dose) {
|
||||
temp[symptom] = existingData[symptom];
|
||||
delete returnData[symptom];
|
||||
} else {
|
||||
temp[symptom] = false;
|
||||
symptom !== "dose"
|
||||
) {
|
||||
if (existingData.dose === dose) {
|
||||
temp[symptom] = existingData[symptom];
|
||||
delete returnData[symptom];
|
||||
} else {
|
||||
temp[symptom] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
returnData[dose] = temp;
|
||||
}
|
||||
if (returnData[dose]["NAUSEA / VOMITING"]) {
|
||||
});
|
||||
returnData[dose] = temp;
|
||||
}
|
||||
if (returnData[dose]["NAUSEA / VOMITING"]) {
|
||||
returnData[dose]["NAUSEA OR VOMITING"] =
|
||||
returnData[dose]["NAUSEA / VOMITING"];
|
||||
}
|
||||
if (returnData[dose]["DIRRHEA"]) {
|
||||
returnData[dose]["DIARRHEA"] = returnData["DIRRHEA"];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (returnData["NAUSEA / VOMITING"]) {
|
||||
returnData["NAUSEA OR VOMITING"] =
|
||||
returnData["NAUSEA / VOMITING"];
|
||||
}
|
||||
if (returnData["DIRRHEA"]) {
|
||||
returnData["DIARRHEA"] = returnData["DIRRHEA"];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (returnData["NAUSEA / VOMITING"]) {
|
||||
returnData["NAUSEA OR VOMITING"] =
|
||||
returnData["NAUSEA / VOMITING"];
|
||||
}
|
||||
if (returnData["DIRRHEA"]) {
|
||||
returnData["DIARRHEA"] = returnData["DIRRHEA"];
|
||||
if (hasToUpdateDb) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("results")
|
||||
.doc(serializeGaId(gid))
|
||||
.set(returnData);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
if (hasToUpdateDb) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("results")
|
||||
.doc(serializeGaId(gid))
|
||||
.set(returnData);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
);
|
||||
|
||||
/**
|
||||
* FUNCTIONS FROM V1.0.0 TO V1.0.1
|
||||
@@ -252,7 +326,7 @@ export const saveResult = functions.https.onCall(
|
||||
const {gid} = data;
|
||||
const docId: string = serializeGaId(gid);
|
||||
const docData: Record<string, string | boolean> =
|
||||
Object.assign({}, data);
|
||||
Object.assign({}, data);
|
||||
delete docData.gid;
|
||||
const existingData = await admin
|
||||
.firestore()
|
||||
@@ -260,16 +334,19 @@ export const saveResult = functions.https.onCall(
|
||||
.doc(docId)
|
||||
.get()
|
||||
.then((doc) => doc.data());
|
||||
if (existingData !== undefined && existingData !== docData &&
|
||||
existingData.name === docData.name) {
|
||||
if (
|
||||
existingData !== undefined &&
|
||||
existingData !== docData &&
|
||||
existingData.name === docData.name
|
||||
) {
|
||||
// DATA EXISTS FOR USER
|
||||
// BUT DIFF DATA SENT FOR UPDATE
|
||||
await admin.firestore().collection("results").doc(docId).set(docData);
|
||||
delete docData.age;
|
||||
delete docData.name;
|
||||
delete docData.dose;
|
||||
const updateDoc : Record<string, admin.firestore.FieldValue> = {};
|
||||
Object.keys(docData).forEach((symptom : string) => {
|
||||
const updateDoc: Record<string, admin.firestore.FieldValue> = {};
|
||||
Object.keys(docData).forEach((symptom: string) => {
|
||||
// IF WAS TRUE, NOW FALSE = -1
|
||||
// IF WAS TRUE, NOW TRUE = 0
|
||||
// IF WAS FALSE, NOW TRUE = +1
|
||||
@@ -277,17 +354,20 @@ export const saveResult = functions.https.onCall(
|
||||
let incrementValue = 0;
|
||||
if (existingData[symptom] === true && docData[symptom] === false) {
|
||||
incrementValue = -1;
|
||||
} else if (existingData[symptom] === false &&
|
||||
docData[symptom] === true) {
|
||||
} else if (
|
||||
existingData[symptom] === false &&
|
||||
docData[symptom] === true
|
||||
) {
|
||||
incrementValue = 1;
|
||||
}
|
||||
if (data.dose) {
|
||||
updateDoc[
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(incrementValue);
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(incrementValue);
|
||||
} else {
|
||||
updateDoc[`${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(incrementValue);
|
||||
updateDoc[
|
||||
`${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(incrementValue);
|
||||
}
|
||||
});
|
||||
admin
|
||||
@@ -295,25 +375,27 @@ export const saveResult = functions.https.onCall(
|
||||
.collection("stats")
|
||||
.doc(data.name)
|
||||
.update(updateDoc);
|
||||
} else if (existingData !== undefined && existingData !== docData &&
|
||||
existingData.name !== docData.name) {
|
||||
} else if (
|
||||
existingData !== undefined &&
|
||||
existingData !== docData &&
|
||||
existingData.name !== docData.name
|
||||
) {
|
||||
// UNDO DATA FOR OLD VAX
|
||||
// DECREMENT VALUES FOR EACH SYMPTOM ON OLD VAX
|
||||
const undoDoc : Record<string, admin.firestore.FieldValue> = {
|
||||
const undoDoc: Record<string, admin.firestore.FieldValue> = {
|
||||
count: admin.firestore.FieldValue.increment(-1),
|
||||
};
|
||||
Object.keys(existingData).forEach((symptom : string) => {
|
||||
if (symptom !== "name" && symptom !== "dose" &&
|
||||
symptom !== "age" ) {
|
||||
Object.keys(existingData).forEach((symptom: string) => {
|
||||
if (symptom !== "name" && symptom !== "dose" && symptom !== "age") {
|
||||
if (existingData[symptom] === true) {
|
||||
if (existingData.dose) {
|
||||
undoDoc[
|
||||
`${existingData.dose}.${existingData.age}.${
|
||||
symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(-1);
|
||||
undoDoc[`${existingData.dose}.${existingData.age}.${
|
||||
symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(-1);
|
||||
} else {
|
||||
undoDoc[`${existingData.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(-1);
|
||||
undoDoc[
|
||||
`${existingData.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,19 +412,20 @@ export const saveResult = functions.https.onCall(
|
||||
delete docData.name;
|
||||
delete docData.dose;
|
||||
// INCREMENT TOTAL RESPONSE COUNT
|
||||
const updateDoc : Record<string, admin.firestore.FieldValue> = {
|
||||
const updateDoc: Record<string, admin.firestore.FieldValue> = {
|
||||
count: admin.firestore.FieldValue.increment(1),
|
||||
};
|
||||
// INCREMENT VALUES FOR EACH SYMPTOM
|
||||
Object.keys(docData).forEach((symptom : string) => {
|
||||
Object.keys(docData).forEach((symptom: string) => {
|
||||
if (docData[symptom] === true) {
|
||||
if (data.dose) {
|
||||
updateDoc[
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
} else {
|
||||
updateDoc[`${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -359,19 +442,20 @@ export const saveResult = functions.https.onCall(
|
||||
delete docData.name;
|
||||
delete docData.dose;
|
||||
// INCREMENT TOTAL RESPONSE COUNT
|
||||
const updateDoc : Record<string, admin.firestore.FieldValue> = {
|
||||
const updateDoc: Record<string, admin.firestore.FieldValue> = {
|
||||
count: admin.firestore.FieldValue.increment(1),
|
||||
};
|
||||
// INCREMENT VALUES FOR EACH SYMPTOM
|
||||
Object.keys(docData).forEach((symptom : string) => {
|
||||
Object.keys(docData).forEach((symptom: string) => {
|
||||
if (docData[symptom] === true) {
|
||||
if (data.dose) {
|
||||
updateDoc[
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
`${data.dose}.${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
} else {
|
||||
updateDoc[`${data.age}.${symptom.replace("/", "OR")}`] =
|
||||
admin.firestore.FieldValue.increment(1);
|
||||
updateDoc[
|
||||
`${data.age}.${symptom.replace("/", "OR")}`
|
||||
] = admin.firestore.FieldValue.increment(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -382,12 +466,13 @@ export const saveResult = functions.https.onCall(
|
||||
.update(updateDoc);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const getPastResult = functions.https.onCall(async (data, context) => {
|
||||
if (!!data && !!context) {
|
||||
const {gid} = data;
|
||||
const existingData : admin.firestore.DocumentData | undefined = await admin
|
||||
const existingData: admin.firestore.DocumentData | undefined = await admin
|
||||
.firestore()
|
||||
.collection("results")
|
||||
.doc(serializeGaId(gid))
|
||||
@@ -395,8 +480,7 @@ export const getPastResult = functions.https.onCall(async (data, context) => {
|
||||
.then((doc) => doc.data());
|
||||
if (existingData) {
|
||||
if (existingData["NAUSEA / VOMITING"]) {
|
||||
existingData["NAUSEA OR VOMITING"] =
|
||||
existingData["NAUSEA / VOMITING"];
|
||||
existingData["NAUSEA OR VOMITING"] = existingData["NAUSEA / VOMITING"];
|
||||
}
|
||||
return existingData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user