Extract find and fetch
This commit is contained in:
parent
dc47037dbb
commit
53d6219b79
|
@ -1,5 +1,5 @@
|
|||
import * as triggers from "../../automations/triggers"
|
||||
import { getAutomationParams, DocumentType } from "../../db/utils"
|
||||
import { DocumentType } from "../../db/utils"
|
||||
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
||||
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
|
||||
import { context, cache, events, db as dbCore } from "@budibase/backend-core"
|
||||
|
@ -74,18 +74,11 @@ export async function update(ctx: UserCtx) {
|
|||
}
|
||||
|
||||
export async function fetch(ctx: UserCtx) {
|
||||
const db = context.getAppDB()
|
||||
const response = await db.allDocs(
|
||||
getAutomationParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
ctx.body = response.rows.map(row => row.doc)
|
||||
ctx.body = await sdk.automations.fetch()
|
||||
}
|
||||
|
||||
export async function find(ctx: UserCtx) {
|
||||
const db = context.getAppDB()
|
||||
ctx.body = await db.get(ctx.params.id)
|
||||
ctx.body = await sdk.automations.get(ctx.params.id)
|
||||
}
|
||||
|
||||
export async function destroy(ctx: UserCtx<void, DeleteAutomationResponse>) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { context, events, HTTPError } from "@budibase/backend-core"
|
|||
import { Automation } from "@budibase/types"
|
||||
import { checkForWebhooks } from "src/automations/utils"
|
||||
import { MetadataTypes } from "src/constants"
|
||||
import { generateAutomationID } from "src/db/utils"
|
||||
import { generateAutomationID, getAutomationParams } from "src/db/utils"
|
||||
import { deleteEntityMetadata } from "src/utilities"
|
||||
|
||||
function getDb() {
|
||||
|
@ -63,6 +63,22 @@ async function handleStepEvents(
|
|||
}
|
||||
}
|
||||
|
||||
export async function fetch() {
|
||||
const db = getDb()
|
||||
const response = await db.allDocs<Automation>(
|
||||
getAutomationParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
return response.rows.map(row => row.doc)
|
||||
}
|
||||
|
||||
export async function get(automationId: string) {
|
||||
const db = getDb()
|
||||
const result = await db.get<Automation>(automationId)
|
||||
return result
|
||||
}
|
||||
|
||||
export async function create(automation: Automation) {
|
||||
automation = { ...automation }
|
||||
const db = getDb()
|
||||
|
@ -133,7 +149,7 @@ export async function update(automation: Automation) {
|
|||
}
|
||||
|
||||
export async function remove(automationId: string, rev: string) {
|
||||
const db = context.getAppDB()
|
||||
const db = getDb()
|
||||
const existing = await db.get<Automation>(automationId)
|
||||
await checkForWebhooks({
|
||||
oldAuto: existing,
|
||||
|
|
Loading…
Reference in New Issue