mirror of https://github.com/Budibase/budibase.git
nocodelowcodelow-codedockerdocker-composeinternal-projectinternal-toolinternal-toolslow-code-developmentlow-code-development-platformopensourceselfhostedweb-devweb-developmentweb-development-toolswebdevwebdevelopmentworkflow-automationautomationdeveloper-tools
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.4 KiB
101 lines
2.4 KiB
const recordController = require("../../api/controllers/record")
|
|
const automationUtils = require("../automationUtils")
|
|
const environment = require("../../environment")
|
|
const usage = require("../../utilities/usageQuota")
|
|
|
|
module.exports.definition = {
|
|
name: "Create Row",
|
|
tagline: "Create a {{inputs.enriched.model.name}} row",
|
|
icon: "ri-save-3-fill",
|
|
description: "Add a row to your database",
|
|
type: "ACTION",
|
|
stepId: "CREATE_RECORD",
|
|
inputs: {},
|
|
schema: {
|
|
inputs: {
|
|
properties: {
|
|
record: {
|
|
type: "object",
|
|
properties: {
|
|
modelId: {
|
|
type: "string",
|
|
customType: "model",
|
|
},
|
|
},
|
|
customType: "record",
|
|
title: "Table",
|
|
required: ["modelId"],
|
|
},
|
|
},
|
|
required: ["record"],
|
|
},
|
|
outputs: {
|
|
properties: {
|
|
record: {
|
|
type: "object",
|
|
customType: "record",
|
|
description: "The new row",
|
|
},
|
|
response: {
|
|
type: "object",
|
|
description: "The response from the table",
|
|
},
|
|
success: {
|
|
type: "boolean",
|
|
description: "Whether the action was successful",
|
|
},
|
|
id: {
|
|
type: "string",
|
|
description: "The identifier of the new row",
|
|
},
|
|
revision: {
|
|
type: "string",
|
|
description: "The revision of the new row",
|
|
},
|
|
},
|
|
required: ["success", "id", "revision"],
|
|
},
|
|
},
|
|
}
|
|
|
|
module.exports.run = async function({ inputs, instanceId, apiKey }) {
|
|
// TODO: better logging of when actions are missed due to missing parameters
|
|
if (inputs.record == null || inputs.record.modelId == null) {
|
|
return
|
|
}
|
|
inputs.record = await automationUtils.cleanUpRecord(
|
|
instanceId,
|
|
inputs.record.modelId,
|
|
inputs.record
|
|
)
|
|
// have to clean up the record, remove the model from it
|
|
const ctx = {
|
|
params: {
|
|
modelId: inputs.record.modelId,
|
|
},
|
|
request: {
|
|
body: inputs.record,
|
|
},
|
|
user: { instanceId },
|
|
}
|
|
|
|
try {
|
|
if (environment.CLOUD) {
|
|
await usage.update(apiKey, usage.Properties.RECORD, 1)
|
|
}
|
|
await recordController.save(ctx)
|
|
return {
|
|
record: inputs.record,
|
|
response: ctx.body,
|
|
id: ctx.body._id,
|
|
revision: ctx.body._rev,
|
|
success: ctx.status === 200,
|
|
}
|
|
} catch (err) {
|
|
console.error(err)
|
|
return {
|
|
success: false,
|
|
response: err,
|
|
}
|
|
}
|
|
}
|
|
|