Browse Source

Updates as per review comments.

master
mike12345567 6 years ago
parent
commit
39dbf78359
  1. 25
      packages/server/src/middleware/joi-validator.js
  2. 4
      packages/server/src/workflows/thread.js

25
packages/server/src/middleware/joi-validator.js

@ -1,18 +1,19 @@
function validate(schema, property) { function validate(schema, property) {
// Return a Koa middleware function // Return a Koa middleware function
return (ctx, next) => { return (ctx, next) => {
if (schema) { if (!schema) {
let params = return next()
ctx[property] != null }
? ctx[property] let params = null
: ctx.request[property] != null if (ctx[property] != null) {
? ctx.request[property] params = ctx[property]
: null } else if (ctx.request[property] != null) {
const { error } = schema.validate(params) params = ctx.request[property]
if (error) { }
ctx.throw(400, `Invalid ${property} - ${error.message}`) const { error } = schema.validate(params)
return if (error) {
} ctx.throw(400, `Invalid ${property} - ${error.message}`)
return
} }
return next() return next()
} }

4
packages/server/src/workflows/thread.js

@ -10,8 +10,8 @@ function cleanMustache(string) {
"]": "", "]": "",
} }
let regex = new RegExp(/{{[^}}]*}}/g) let regex = new RegExp(/{{[^}}]*}}/g)
let match let matches = [...string.matchAll(regex)]
while ((match = regex.exec(string)) !== null) { for (let match of matches) {
let baseIdx = string.indexOf(match) let baseIdx = string.indexOf(match)
for (let key of Object.keys(charToReplace)) { for (let key of Object.keys(charToReplace)) {
let idxChar = match[0].indexOf(key) let idxChar = match[0].indexOf(key)

Loading…
Cancel
Save