This is a breaking change, it updates the block definitions to work with the new structure of inputs and outputs.

This commit is contained in:
mike12345567 2020-09-15 14:27:23 +01:00
parent 1930aa2296
commit 1382c3bb12
6 changed files with 203 additions and 32 deletions

View File

@ -53,7 +53,6 @@ exports.patch = async function(ctx) {
ctx.body = record
ctx.status = 200
ctx.message = `${model.name} updated successfully.`
return
}
exports.save = async function(ctx) {

View File

@ -58,6 +58,7 @@ exports.create = async function(ctx) {
ctx.message = "User created successfully."
ctx.body = {
_rev: response.rev,
_id: user._id,
username,
name,
}

View File

@ -1,28 +1,72 @@
let accessLevels = require("../../../utilities/accessLevels")
let conditions = require("../../../workflows/logic").LogicConditions
const ACTION = {
SAVE_RECORD: {
name: "Save Record",
tagline: "<b>Save</b> a <b>{{record.model.name}}</b> record",
icon: "ri-save-3-fill",
description: "Save a record to your database.",
params: {
record: "record",
},
args: {
record: {},
},
description: "Save a record to your database",
type: "ACTION",
input: {
record: {
type: "record",
label: "The record to be written",
default: {},
},
model: {
type: "model",
label: "The table to save a record to",
},
},
output: {
response: {
type: "object",
label: "The response from the table",
},
success: {
type: "boolean",
label: "Whether the action was successful",
},
id: {
type: "string",
label: "The identifier of the new record",
},
revision: {
type: "string",
label: "The revision of the new record",
},
},
},
DELETE_RECORD: {
description: "Delete a record from your database.",
description: "Delete a record from your database",
icon: "ri-delete-bin-line",
name: "Delete Record",
tagline: "<b>Delete</b> a <b>{{record.model.name}}</b> record",
params: {},
args: {},
type: "ACTION",
input: {
id: {
type: "string",
label: "The identifier of the record to be deleted",
},
revision: {
type: "string",
label: "The revision of the record to be deleted",
},
},
output: {
response: {
type: "object",
label: "The response from the table",
},
success: {
type: "boolean",
label: "Whether the action was successful",
},
},
},
CREATE_USER: {
description: "Create a new user.",
description: "Create a new user",
tagline: "Create user <b>{{username}}</b>",
icon: "ri-user-add-fill",
name: "Create User",
@ -35,6 +79,40 @@ const ACTION = {
accessLevelId: "POWER_USER",
},
type: "ACTION",
input: {
username: {
type: "string",
label: "The username of the new user to create",
},
password: {
type: "password",
label: "The password of the new user to create",
},
accessLevelId: {
type: "string",
label: "The level of access to the system the new user will have",
default: accessLevels.POWERUSER_LEVEL_ID,
options: accessLevels.ACCESS_LEVELS,
},
},
output: {
id: {
type: "string",
label: "The identifier of the new user",
},
revision: {
type: "string",
label: "The revision of the new user",
},
response: {
type: "object",
label: "The response from the user table",
},
success: {
type: "boolean",
label: "Whether the action was successful",
},
},
},
SEND_EMAIL: {
description: "Send an email.",
@ -48,6 +126,34 @@ const ACTION = {
text: "longText",
},
type: "ACTION",
input: {
to: {
type: "string",
label: "Email address to send email to",
},
from: {
type: "string",
label: "Email address to send email from",
},
subject: {
type: "string",
label: "The subject of the email",
},
contents: {
type: "string",
label: "The contents of the email",
},
},
output: {
success: {
type: "boolean",
label: "Whether the email was sent",
},
response: {
type: "object",
label: "A response from the email client, this may be an error",
},
},
},
}
@ -56,7 +162,7 @@ const LOGIC = {
name: "Filter",
tagline: "{{filter}} <b>{{condition}}</b> {{value}}",
icon: "ri-git-branch-line",
description: "Filter any workflows which do not meet certain conditions.",
description: "Filter any workflows which do not meet certain conditions",
params: {
filter: "string",
condition: ["equals"],
@ -66,14 +172,38 @@ const LOGIC = {
condition: "equals",
},
type: "LOGIC",
input: {
field: {
type: "string",
label: "The input to filter on",
},
condition: {
type: "string",
label: "The condition to use for filtering",
options: conditions,
},
value: {
type: "string",
label: "The value to compare against",
},
},
output: {
success: {
type: "boolean",
label: "Whether the logic block passed",
},
},
},
DELAY: {
name: "Delay",
icon: "ri-time-fill",
tagline: "Delay for <b>{{time}}</b> milliseconds",
description: "Delay the workflow until an amount of time has passed.",
params: {
time: "number",
description: "Delay the workflow until an amount of time has passed",
input: {
time: {
type: "number",
label: "The duration of the delay in milliseconds",
},
},
type: "LOGIC",
},
@ -85,9 +215,18 @@ const TRIGGER = {
event: "record:save",
icon: "ri-save-line",
tagline: "Record is added to <b>{{model.name}}</b>",
description: "Fired when a record is saved to your database.",
params: {
model: "model",
description: "Fired when a record is saved to your database",
input: {
model: {
type: "model",
label: "The table to trigger on when a new record is saved",
},
},
output: {
record: {
type: "record",
label: "The new record that was saved",
},
},
type: "TRIGGER",
},
@ -96,9 +235,18 @@ const TRIGGER = {
event: "record:delete",
icon: "ri-delete-bin-line",
tagline: "Record is deleted from <b>{{model.name}}</b>",
description: "Fired when a record is deleted from your database.",
params: {
model: "model",
description: "Fired when a record is deleted from your database",
input: {
model: {
type: "model",
label: "The table to trigger on when a record is deleted",
},
},
output: {
record: {
type: "record",
label: "The record that was deleted",
},
},
type: "TRIGGER",
},

View File

@ -87,6 +87,12 @@ module.exports = {
POWERUSER_LEVEL_ID,
BUILDER_LEVEL_ID,
ANON_LEVEL_ID,
ACCESS_LEVELS: [
ADMIN_LEVEL_ID,
POWERUSER_LEVEL_ID,
BUILDER_LEVEL_ID,
ANON_LEVEL_ID,
],
READ_MODEL,
WRITE_MODEL,
READ_VIEW,

View File

@ -17,14 +17,18 @@ let BUILTIN_ACTIONS = {
}
try {
const response = await userController.create(ctx)
await userController.create(ctx)
return {
user: response,
response: ctx.body,
id: ctx.body._id,
revision: ctx.body._rev,
success: ctx.status === 200,
}
} catch (err) {
console.error(err)
return {
user: null,
success: false,
response: err,
}
}
},
@ -45,13 +49,16 @@ let BUILTIN_ACTIONS = {
try {
await recordController.save(ctx)
return {
record: ctx.body,
response: ctx.body,
id: ctx.body._id,
revision: ctx.body._rev,
success: ctx.status === 200,
}
} catch (err) {
console.error(err)
return {
record: null,
error: err.message,
success: false,
response: err,
}
}
},
@ -67,13 +74,12 @@ let BUILTIN_ACTIONS = {
await sgMail.send(msg)
return {
success: true,
...args,
}
} catch (err) {
console.error(err)
return {
success: false,
error: err.message,
response: err,
}
}
},
@ -94,11 +100,15 @@ let BUILTIN_ACTIONS = {
try {
await recordController.destroy(ctx)
return {
response: ctx.body,
success: ctx.status === 200,
}
} catch (err) {
console.error(err)
return {
record: null,
error: err.message,
success: false,
response: err,
}
}
},

View File

@ -22,3 +22,10 @@ module.exports.getLogic = function(logicName) {
return LOGIC[logicName]
}
}
module.exports.LogicConditions = [
"equals",
"notEquals",
"greaterThan",
"lessThan",
]