prevent failed document update from returning error

This commit is contained in:
shamsmosowi
2021-08-16 20:36:02 +10:00
parent ae5c411aa7
commit 1be0c56858
2 changed files with 34 additions and 25 deletions

View File

@@ -78,27 +78,40 @@ export const actionScript = functions.https.onCall(
action === "undo" ? config["undo.script"] : script
}}`
)({ row, db, auth, utilFns, ref, actionParams, context });
if (result.success){
const cellValue = {
redo: config["redo.enabled"],
status: result.status,
completedAt: serverTimestamp(),
ranBy: context.auth!.token.email,
undo: config["undo.enabled"],
}
const userDoc = await db.collection("_FT_USERS").doc(context.auth!.uid).get()
const user = userDoc?.get('user')
await db.doc(ref.path).update({[column.key]:cellValue, _ft_updatedBy:user? {
...user,
...context.auth!,
timestamp: new Date(),
}:null })
return {
...result,
cellValue,
}
}
else return {
if (result.success) {
const cellValue = {
redo: config["redo.enabled"],
status: result.status,
completedAt: serverTimestamp(),
ranBy: context.auth!.token.email,
undo: config["undo.enabled"],
};
try {
const userDoc = await db
.collection("_FT_USERS")
.doc(context.auth!.uid)
.get();
const user = userDoc?.get("user");
await db.doc(ref.path).update({
[column.key]: cellValue,
_ft_updatedBy: user
? {
...user,
...context.auth!,
timestamp: new Date(),
}
: null,
});
} catch (error) {
// handle failed edit log update
}
return {
...result,
cellValue,
};
} else
return {
success: false,
message: result.message,
};

View File

@@ -65,10 +65,6 @@ export default function ActionFab({
const callableName: string =
(column as any).callableName ?? config.callableName ?? "actionScript";
const handleRun = (actionParams = null) => {
if (!ref.path || !ref.id) {
snack.open({ message: "no ref set", variant: "error" });
return;
}
setIsRunning(true);
const data = {
ref: { path: ref.path, id: ref.id, tablePath: window.location.pathname },