Trim data
This commit is contained in:
parent
7bc92fef24
commit
2839bd5ece
|
@ -1,4 +1,9 @@
|
||||||
import { Automation, Webhook, WebhookActionType } from "@budibase/types"
|
import {
|
||||||
|
Automation,
|
||||||
|
RequiredKeys,
|
||||||
|
Webhook,
|
||||||
|
WebhookActionType,
|
||||||
|
} from "@budibase/types"
|
||||||
import { generateAutomationID, getAutomationParams } from "../../../db/utils"
|
import { generateAutomationID, getAutomationParams } from "../../../db/utils"
|
||||||
import { deleteEntityMetadata } from "../../../utilities"
|
import { deleteEntityMetadata } from "../../../utilities"
|
||||||
import { MetadataTypes } from "../../../constants"
|
import { MetadataTypes } from "../../../constants"
|
||||||
|
@ -76,17 +81,20 @@ export async function fetch() {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
return response.rows.map(row => row.doc)
|
return response.rows
|
||||||
|
.map(row => row.doc)
|
||||||
|
.filter(doc => !!doc)
|
||||||
|
.map(trimUnexpectedObjectFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(automationId: string) {
|
export async function get(automationId: string) {
|
||||||
const db = getDb()
|
const db = getDb()
|
||||||
const result = await db.get<Automation>(automationId)
|
const result = await db.get<Automation>(automationId)
|
||||||
return result
|
return trimUnexpectedObjectFields(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create(automation: Automation) {
|
export async function create(automation: Automation) {
|
||||||
automation = { ...automation }
|
automation = trimUnexpectedObjectFields({ ...automation })
|
||||||
const db = getDb()
|
const db = getDb()
|
||||||
|
|
||||||
// Respect existing IDs if recreating a deleted automation
|
// Respect existing IDs if recreating a deleted automation
|
||||||
|
@ -111,8 +119,7 @@ export async function create(automation: Automation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update(automation: Automation) {
|
export async function update(automation: Automation) {
|
||||||
automation = { ...automation }
|
automation = trimUnexpectedObjectFields({ ...automation })
|
||||||
|
|
||||||
if (!automation._id || !automation._rev) {
|
if (!automation._id || !automation._rev) {
|
||||||
throw new HTTPError("_id or _rev fields missing", 400)
|
throw new HTTPError("_id or _rev fields missing", 400)
|
||||||
}
|
}
|
||||||
|
@ -246,3 +253,23 @@ async function checkForWebhooks({ oldAuto, newAuto }: any) {
|
||||||
}
|
}
|
||||||
return newAuto
|
return newAuto
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimUnexpectedObjectFields(automation: Automation): Automation {
|
||||||
|
const result: RequiredKeys<Automation> = {
|
||||||
|
_id: automation._id,
|
||||||
|
_rev: automation._rev,
|
||||||
|
definition: automation.definition,
|
||||||
|
screenId: automation.screenId,
|
||||||
|
uiTree: automation.uiTree,
|
||||||
|
appId: automation.appId,
|
||||||
|
live: automation.live,
|
||||||
|
name: automation.name,
|
||||||
|
internal: automation.internal,
|
||||||
|
type: automation.type,
|
||||||
|
disabled: automation.disabled,
|
||||||
|
testData: automation.testData,
|
||||||
|
createdAt: automation.createdAt,
|
||||||
|
updatedAt: automation.updatedAt,
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue