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 0d2f7759ee
commit e2791d832b
6 changed files with 203 additions and 32 deletions

View File

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

View File

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

View File

@ -1,28 +1,72 @@
let accessLevels = require("../../../utilities/accessLevels")
let conditions = require("../../../workflows/logic").LogicConditions
const ACTION = { const ACTION = {
SAVE_RECORD: { SAVE_RECORD: {
name: "Save Record", name: "Save Record",
tagline: "<b>Save</b> a <b>{{record.model.name}}</b> record", tagline: "<b>Save</b> a <b>{{record.model.name}}</b> record",
icon: "ri-save-3-fill", icon: "ri-save-3-fill",
description: "Save a record to your database.", description: "Save a record to your database",
params: {
record: "record",
},
args: {
record: {},
},
type: "ACTION", 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: { DELETE_RECORD: {
description: "Delete a record from your database.", description: "Delete a record from your database",
icon: "ri-delete-bin-line", icon: "ri-delete-bin-line",
name: "Delete Record", name: "Delete Record",
tagline: "<b>Delete</b> a <b>{{record.model.name}}</b> record", tagline: "<b>Delete</b> a <b>{{record.model.name}}</b> record",
params: {},
args: {},
type: "ACTION", 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: { CREATE_USER: {
description: "Create a new user.", description: "Create a new user",
tagline: "Create user <b>{{username}}</b>", tagline: "Create user <b>{{username}}</b>",
icon: "ri-user-add-fill", icon: "ri-user-add-fill",
name: "Create User", name: "Create User",
@ -35,6 +79,40 @@ const ACTION = {
accessLevelId: "POWER_USER", accessLevelId: "POWER_USER",
}, },
type: "ACTION", 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: { SEND_EMAIL: {
description: "Send an email.", description: "Send an email.",
@ -48,6 +126,34 @@ const ACTION = {
text: "longText", text: "longText",
}, },
type: "ACTION", 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", name: "Filter",
tagline: "{{filter}} <b>{{condition}}</b> {{value}}", tagline: "{{filter}} <b>{{condition}}</b> {{value}}",
icon: "ri-git-branch-line", 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: { params: {
filter: "string", filter: "string",
condition: ["equals"], condition: ["equals"],
@ -66,14 +172,38 @@ const LOGIC = {
condition: "equals", condition: "equals",
}, },
type: "LOGIC", 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: { DELAY: {
name: "Delay", name: "Delay",
icon: "ri-time-fill", icon: "ri-time-fill",
tagline: "Delay for <b>{{time}}</b> milliseconds", tagline: "Delay for <b>{{time}}</b> milliseconds",
description: "Delay the workflow until an amount of time has passed.", description: "Delay the workflow until an amount of time has passed",
params: { input: {
time: "number", time: {
type: "number",
label: "The duration of the delay in milliseconds",
},
}, },
type: "LOGIC", type: "LOGIC",
}, },
@ -85,9 +215,18 @@ const TRIGGER = {
event: "record:save", event: "record:save",
icon: "ri-save-line", icon: "ri-save-line",
tagline: "Record is added to <b>{{model.name}}</b>", tagline: "Record is added to <b>{{model.name}}</b>",
description: "Fired when a record is saved to your database.", description: "Fired when a record is saved to your database",
params: { input: {
model: "model", 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", type: "TRIGGER",
}, },
@ -96,9 +235,18 @@ const TRIGGER = {
event: "record:delete", event: "record:delete",
icon: "ri-delete-bin-line", icon: "ri-delete-bin-line",
tagline: "Record is deleted from <b>{{model.name}}</b>", tagline: "Record is deleted from <b>{{model.name}}</b>",
description: "Fired when a record is deleted from your database.", description: "Fired when a record is deleted from your database",
params: { input: {
model: "model", 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", type: "TRIGGER",
}, },

View File

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

View File

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

View File

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