mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
fix derivatives "-" nameing error
This commit is contained in:
@@ -2,7 +2,7 @@ import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
|
||||
import { db } from "../config";
|
||||
import config, { collectionPath } from "../functionConfig";
|
||||
import config, { collectionPath, functionName } from "../functionConfig";
|
||||
// generated using generateConfig.ts
|
||||
|
||||
const incrementor = (v: number) => admin.firestore.FieldValue.increment(v);
|
||||
@@ -75,7 +75,7 @@ const subDocTrigger = async (
|
||||
};
|
||||
|
||||
export const FT_aggregates = {
|
||||
[collectionPath.replace("-", "_")]: functions.firestore
|
||||
[functionName]: functions.firestore
|
||||
.document(`${collectionPath}/{parentId}/{subCollectionId}/{docId}`)
|
||||
.onWrite(subDocTrigger),
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as functions from "firebase-functions";
|
||||
|
||||
import { db } from "../config";
|
||||
import config, { collectionPath } from "../functionConfig";
|
||||
import config, { collectionPath, functionName } from "../functionConfig";
|
||||
// generated using generateConfig.ts
|
||||
const functionConfig: any = config;
|
||||
|
||||
@@ -67,10 +67,7 @@ export const derivativeOnUpdate = async (
|
||||
};
|
||||
|
||||
export const FT_derivatives = {
|
||||
[collectionPath
|
||||
.replace("-", "_")
|
||||
.replace(/\//g, "_")
|
||||
.replace(/_{.*?}_/g, "_")]: {
|
||||
[functionName]: {
|
||||
u: functions.firestore
|
||||
.document(`${collectionPath}/{docId}`)
|
||||
.onUpdate(derivativeOnUpdate),
|
||||
|
||||
@@ -1,2 +1,20 @@
|
||||
export default [];
|
||||
export const collectionPath = "";
|
||||
export default [
|
||||
{
|
||||
fieldName: "team",
|
||||
eval: (db) => async ({ row, ref }) => {
|
||||
if (row.portfolio && row.portfolio[0]) {
|
||||
return {
|
||||
...row.portfolio[0],
|
||||
docPath: row.portfolio[0].docPath.replace("portfolio", "myTeam"),
|
||||
};
|
||||
}
|
||||
},
|
||||
listenerFields: ["portfolio"],
|
||||
},
|
||||
];
|
||||
export const collectionPath =
|
||||
"founders-reonboarding/{founders_reonboardingDocId}/invites";
|
||||
export const functionName = collectionPath
|
||||
.replace("-", "_")
|
||||
.replace(/\//g, "_")
|
||||
.replace(/_{.*?}_/g, "_");
|
||||
|
||||
@@ -39,7 +39,7 @@ const main = async (functionType: string, configString: string) => {
|
||||
const pathTables = path.split("/subTables/");
|
||||
const subcollection = pathTables.pop();
|
||||
return `${pathTables
|
||||
.map((t) => `${t}/{${t}DocId}`)
|
||||
.map((t) => `${t}/{${t.replace(/-/g, "_")}DocId}`)
|
||||
.join("/")}/${subcollection}`;
|
||||
})(collectionPath)
|
||||
: collectionPath
|
||||
@@ -75,6 +75,9 @@ const main = async (functionType: string, configString: string) => {
|
||||
configData = `export default ${configString}\n export const collectionPath=''`;
|
||||
break;
|
||||
}
|
||||
configData =
|
||||
configData +
|
||||
'\nexport const functionName = collectionPath.replace("-", "_").replace(/\\//g, "_").replace(/_{.*?}_/g, "_")';
|
||||
console.log({ configData });
|
||||
fs.writeFileSync("./src/functionConfig.ts", configData);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user