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