v1.0.0/release
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
import * as firebaseSecret from "./firebaseSecret.json";
|
||||
|
||||
const params = {
|
||||
type: firebaseSecret.type,
|
||||
projectId: firebaseSecret.project_id,
|
||||
privateKeyId: firebaseSecret.private_key_id,
|
||||
privateKey: firebaseSecret.private_key,
|
||||
clientEmail: firebaseSecret.client_email,
|
||||
clientId: firebaseSecret.client_id,
|
||||
authUri: firebaseSecret.auth_uri,
|
||||
tokenUri: firebaseSecret.token_uri,
|
||||
authProviderX509CertUrl: firebaseSecret.auth_provider_x509_cert_url,
|
||||
clientC509CertUrl: firebaseSecret.client_x509_cert_url,
|
||||
};
|
||||
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(params),
|
||||
});
|
||||
|
||||
interface RequestData {
|
||||
gid: string;
|
||||
}
|
||||
|
||||
interface SaveResultRequestData extends RequestData {
|
||||
name: string;
|
||||
age: string;
|
||||
dose: string;
|
||||
[x: string]: string;
|
||||
}
|
||||
|
||||
const serializeGaId = (_gaid: string): string => {
|
||||
if (_gaid) {
|
||||
return _gaid.split(".").join("|");
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
export const saveResult = functions.https.onCall(
|
||||
(data: SaveResultRequestData, context) => {
|
||||
if (!!data && !!context) {
|
||||
const {gid} = data;
|
||||
const docId: string = serializeGaId(gid);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const docData : any = Object.assign({}, data);
|
||||
delete docData.gid;
|
||||
admin.firestore().collection("results").doc(docId).set(docData);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const getPastResult = functions.https.onCall(async (data, context) => {
|
||||
if (!!data && !!context) {
|
||||
const {gid} = data;
|
||||
return await admin
|
||||
.firestore()
|
||||
.collection("results")
|
||||
.doc(serializeGaId(gid))
|
||||
.get()
|
||||
.then((doc) => doc.data());
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
Reference in New Issue
Block a user