v1.1.0/release functions

(fix lint, build, ignore script)
This commit is contained in:
2021-04-21 23:10:39 -04:00
parent abb00ef27b
commit 732bd6887c
4 changed files with 63 additions and 48 deletions
+4 -1
View File
@@ -50,7 +50,10 @@
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
"source": "functions",
"ignore": [
"functions/scripts"
]
},
"emulators": {
"functions": {
+1
View File
@@ -20,6 +20,7 @@ module.exports = {
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
"/scripts/**/*", // Ignore scripts
],
plugins: ["@typescript-eslint", "import"],
rules: {
@@ -1,6 +1,5 @@
const admin = require("firebase-admin");
const firebaseSecret = require("./firebaseSecret.json");
const firebaseSecret = require("../src/firebaseSecret.json");
admin.initializeApp({
+20 -8
View File
@@ -46,15 +46,17 @@ const VAX_AGES: Record<string, Record<string, string>> = {
};
type SaveResultRequestData = {
name: string;
age: string;
dose: string;
gid: string;
name?: string;
age?: string;
dose?: string;
gid?: string;
} & {
[x: string]: boolean;
} & {
[y: string]: Record<string, boolean>;
};
const serializeGaId = (_gaid: string): string => {
const serializeGaId = (_gaid: string | undefined): string => {
if (_gaid) {
return _gaid.split(".").join("|");
}
@@ -62,7 +64,7 @@ const serializeGaId = (_gaid: string): string => {
};
const addResultToStats = async (data: SaveResultRequestData) => {
const cleanData: Record<string, any> = Object.assign({}, data);
const cleanData: SaveResultRequestData = Object.assign({}, data);
delete cleanData.name;
delete cleanData.dose;
delete cleanData.age;
@@ -109,11 +111,13 @@ const addResultToStats = async (data: SaveResultRequestData) => {
] = admin.firestore.FieldValue.increment(1);
});
}
if (data.name) {
admin.firestore().collection("stats").doc(data.name).update(updateDoc);
}
};
const removeResultFromStats = async (data: FirebaseFirestore.DocumentData) => {
const cleanData: Record<string, any> = Object.assign({}, data);
const cleanData: SaveResultRequestData = Object.assign({}, data);
delete cleanData.name;
delete cleanData.dose;
delete cleanData.age;
@@ -218,6 +222,7 @@ export const getStatsV1 = functions.https.onCall(async () => {
export const saveResultV1 = functions.https.onCall(
async (data: SaveResultRequestData, context) => {
if (!!data && !!context) {
if (!!data.name && !!data.age && !!data.gid) {
const {gid} = data;
// Get existing result
const existingResult = await admin
@@ -227,7 +232,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: SaveResultRequestData = Object.assign({}, data);
delete cleanData.gid;
await admin
.firestore()
@@ -243,6 +248,7 @@ export const saveResultV1 = functions.https.onCall(
}
}
}
}
);
export const getPastResultV1 = functions.https.onCall(
@@ -370,11 +376,13 @@ export const saveResult = functions.https.onCall(
] = admin.firestore.FieldValue.increment(incrementValue);
}
});
if (data.name) {
admin
.firestore()
.collection("stats")
.doc(data.name)
.update(updateDoc);
}
} else if (
existingData !== undefined &&
existingData !== docData &&
@@ -429,11 +437,13 @@ export const saveResult = functions.https.onCall(
}
}
});
if (data.name) {
admin
.firestore()
.collection("stats")
.doc(data.name)
.update(updateDoc);
}
} else if (existingData === undefined) {
// DATA DOESN'T EXIST FOR USER
// SAVE USER DATA
@@ -459,6 +469,7 @@ export const saveResult = functions.https.onCall(
}
}
});
if (data.name) {
admin
.firestore()
.collection("stats")
@@ -467,6 +478,7 @@ export const saveResult = functions.https.onCall(
}
}
}
}
);
export const getPastResult = functions.https.onCall(async (data, context) => {