This commit is contained in:
Leifer Mendez
2022-11-05 11:24:22 +01:00
parent 0a9e14c460
commit 0a9b1907d7
4 changed files with 40 additions and 15 deletions

View File

@@ -16,21 +16,19 @@ const addAnswer = (inCtx) => (answer, options) => {
const ctxAnswer = () => {
const ref = `ans_${generateRef()}`
const options = {
...getAnswerOptions(),
keyword: {},
}
const json = [].concat(inCtx.json).concat([
{
ref,
keyword: lastCtx.ref,
answer,
options,
},
])
/**
* Se guarda en db
*/
const options = {
answer: getAnswerOptions(),
keyword: {},
}
return { ...lastCtx, ref, answer, json, options }
}

View File

@@ -1,5 +1,6 @@
const { generateRef } = require('../utils')
const { addAnswer } = require('./addAnswer')
const { toJson } = require('./toJson')
/**
* addKeyword:
* Es necesario que genere id|hash
@@ -8,7 +9,7 @@ const { addAnswer } = require('./addAnswer')
/**
*
* @param {*} message `string | string[]`
* @param {*} options {sensitive:boolean} default
* @param {*} options {sensitive:boolean} default false
*/
const addKeyword = (keyword, options) => {
/**
@@ -18,7 +19,10 @@ const addKeyword = (keyword, options) => {
*/
const parseOptions = () => {
const defaultProperties = {
sensitive: options?.sensitive ?? true,
sensitive:
typeof options?.sensitive === 'boolean'
? options?.sensitive
: false,
}
return defaultProperties
@@ -31,6 +35,7 @@ const addKeyword = (keyword, options) => {
{
ref,
keyword,
options,
},
]
/**
@@ -46,6 +51,7 @@ const addKeyword = (keyword, options) => {
ctx,
ref: ctx.ref,
addAnswer: addAnswer(ctx),
toJson: toJson(ctx),
}
}