mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
CF config setup
This commit is contained in:
@@ -7,6 +7,7 @@ const TEMPLATE_KEYS = {
|
||||
body: "/*<GENERATED_CODE>*/",
|
||||
subscriptionCollectionPath: /<<COLLECTION_PATH>>/gi,
|
||||
triggerEvent: /<<TRIGGER_EVENT>>/gi,
|
||||
targetDocPath: /<<TARGET_DOC_PATH>>/gi,
|
||||
};
|
||||
// fs.readFile(OutputPath, "utf-8", (err, data) => {
|
||||
// fs.writeFile(OutputPath, data + generatedCode, err => {
|
||||
@@ -42,13 +43,12 @@ const main = async () => {
|
||||
schema.subscription
|
||||
);
|
||||
output = output.replace(TEMPLATE_KEYS.triggerEvent, "onUpdate");
|
||||
output = output.replace(TEMPLATE_KEYS.targetDocPath, "founder[0].docPath");
|
||||
const tasks = schema.targets.map(target => {
|
||||
const fields = target.map.map(field => {
|
||||
return `${field.toField}:afterData.${field.fromField}`;
|
||||
});
|
||||
return `if(afterData&&afterData.${target.docPath})await db.doc(afterData.${
|
||||
target.docPath
|
||||
}).set({${fields.join()}},{merge:true})`;
|
||||
return `const updates = {${fields.join()}}`;
|
||||
});
|
||||
|
||||
output = output.replace(TEMPLATE_KEYS.body, tasks.join());
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
/* tslint-disable */
|
||||
import * as functions from "firebase-functions";
|
||||
const admin = require("firebase-admin");
|
||||
const db = admin.firestore();
|
||||
import { db} from "./config";
|
||||
|
||||
export const <<COLLECTION_PATH>> = functions.firestore
|
||||
.document("<<COLLECTION_PATH>>/{id}")
|
||||
.<<TRIGGER_EVENT>>(async(change, context) => {
|
||||
const afterData = change.after.data();
|
||||
|
||||
/*<GENERATED_CODE>*/
|
||||
|
||||
if (afterData) {
|
||||
if( afterData.<<TARGET_DOC_PATH>>){
|
||||
/*<GENERATED_CODE>*/
|
||||
console.log(`updates FROM <<COLLECTION_PATH>>/${context.params.id} TO ${afterData.<<TARGET_DOC_PATH>>}`, updates)
|
||||
await db.doc(afterData.founder[0].docPath).set(updates, { merge: true });
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
13
cloud_functions/functions/src/config.ts
Normal file
13
cloud_functions/functions/src/config.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// Initialize Firebase Admin
|
||||
import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
admin.initializeApp();
|
||||
|
||||
// Initialize Cloud Firestore Database
|
||||
export const db = admin.firestore();
|
||||
// Initialize Auth
|
||||
export const auth = admin.auth();
|
||||
const settings = { timestampsInSnapshots: true };
|
||||
db.settings(settings);
|
||||
|
||||
export const env = functions.config();
|
||||
@@ -1,9 +1,7 @@
|
||||
import * as algolia from "algoliasearch";
|
||||
import * as functions from "firebase-functions";
|
||||
//import * as maps from "./maps";
|
||||
import * as admin from "firebase-admin";
|
||||
admin.initializeApp();
|
||||
const env = functions.config();
|
||||
import * as maps from "./maps";
|
||||
import { env, auth } from "./config";
|
||||
export const updateAlgoliaRecord = functions.https.onCall(
|
||||
async (data: any, context: any) => {
|
||||
const client = algolia(env.algolia.appid, env.algolia.apikey);
|
||||
@@ -35,12 +33,11 @@ exports.setUserAsAdmin = functions.auth.user().onCreate(async user => {
|
||||
user.email &&
|
||||
user.email.split("@")[1] === "antler.co"
|
||||
) {
|
||||
let additionalClaims = {
|
||||
const additionalClaims = {
|
||||
admin: true,
|
||||
};
|
||||
|
||||
await admin
|
||||
.auth()
|
||||
await auth
|
||||
.createCustomToken(user.uid, additionalClaims)
|
||||
.then(function(customToken) {
|
||||
// Send token back to client
|
||||
@@ -54,4 +51,4 @@ exports.setUserAsAdmin = functions.auth.user().onCreate(async user => {
|
||||
return true;
|
||||
});
|
||||
|
||||
//export const MAPS = maps;
|
||||
export const MAPS = maps;
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
/* tslint-disable */
|
||||
import * as functions from "firebase-functions";
|
||||
const admin = require("firebase-admin");
|
||||
const db = admin.firestore();
|
||||
import { db} from "./config";
|
||||
|
||||
export const users = functions.firestore
|
||||
.document("users/{id}")
|
||||
.onUpdate(async(change, context) => {
|
||||
const afterData = change.after.data();
|
||||
|
||||
if(afterData&&afterData.founder[0].docPath)await db.doc(afterData.founder[0].docPath).set({firstName:afterData.firstName,lastName:afterData.lastName,preferredName:afterData.preferredName,background:afterData.personalBio,role:afterData.role},{merge:true})
|
||||
|
||||
if (afterData) {
|
||||
if( afterData.founder[0].docPath){
|
||||
const updates = {firstName:afterData.firstName,lastName:afterData.lastName,preferredName:afterData.preferredName,background:afterData.personalBio,role:afterData.role}
|
||||
console.log(`updates FROM users/${context.params.id} TO ${afterData.founder[0].docPath}`, updates)
|
||||
await db.doc(afterData.founder[0].docPath).set(updates, { merge: true });
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -74,27 +74,26 @@
|
||||
// Disallow duplicate imports in the same file.
|
||||
"no-duplicate-imports": true,
|
||||
|
||||
|
||||
// -- Strong Warnings --
|
||||
// These rules should almost never be needed, but may be included due to legacy code.
|
||||
// They are left as a warning to avoid frustration with blocked deploys when the developer
|
||||
// understand the warning and wants to deploy anyway.
|
||||
|
||||
// Warn when an empty interface is defined. These are generally not useful.
|
||||
"no-empty-interface": {"severity": "warning"},
|
||||
"no-empty-interface": { "severity": "warning" },
|
||||
|
||||
// Warn when an import will have side effects.
|
||||
"no-import-side-effect": {"severity": "warning"},
|
||||
"no-import-side-effect": { "severity": "warning" },
|
||||
|
||||
// Warn when variables are defined with var. Var has subtle meaning that can lead to bugs. Strongly prefer const for
|
||||
// most values and let for values that will change.
|
||||
"no-var-keyword": {"severity": "warning"},
|
||||
"no-var-keyword": { "severity": "warning" },
|
||||
|
||||
// Prefer === and !== over == and !=. The latter operators support overloads that are often accidental.
|
||||
"triple-equals": {"severity": "warning"},
|
||||
"triple-equals": { "severity": "warning" },
|
||||
|
||||
// Warn when using deprecated APIs.
|
||||
"deprecation": {"severity": "warning"},
|
||||
"deprecation": { "severity": "warning" },
|
||||
|
||||
// -- Light Warnings --
|
||||
// These rules are intended to help developers use better style. Simpler code has fewer bugs. These would be "info"
|
||||
@@ -102,17 +101,19 @@
|
||||
|
||||
// prefer for( ... of ... ) to an index loop when the index is only used to fetch an object from an array.
|
||||
// (Even better: check out utils like .map if transforming an array!)
|
||||
"prefer-for-of": {"severity": "warning"},
|
||||
"prefer-for-of": { "severity": "warning" },
|
||||
|
||||
// Warns if function overloads could be unified into a single function with optional or rest parameters.
|
||||
"unified-signatures": {"severity": "warning"},
|
||||
"unified-signatures": { "severity": "warning" },
|
||||
|
||||
// Prefer const for values that will not change. This better documents code.
|
||||
"prefer-const": {"severity": "warning"},
|
||||
"prefer-const": { "severity": "warning" },
|
||||
|
||||
// Multi-line object literals and function calls should have a trailing comma. This helps avoid merge conflicts.
|
||||
"trailing-comma": {"severity": "warning"}
|
||||
"trailing-comma": { "severity": "warning" }
|
||||
},
|
||||
"linterOptions": {
|
||||
"exclude": ["./generator/templates/**"]
|
||||
},
|
||||
|
||||
"defaultSeverity": "error"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user