/ask POST fixes

This commit is contained in:
mrfry 2020-12-19 15:27:18 +01:00
parent c6da65ce40
commit 0654a36d21

View file

@ -1106,9 +1106,15 @@ function GetApp(): ModuleType {
return getResult(question, subj, null, req.query) return getResult(question, subj, null, req.query)
}) })
Promise.all(resultPromises).then((result) => { Promise.all(resultPromises).then((results) => {
console.log(result) res.json(
res.json(result) results.map((result: any) => {
return {
answers: result.result,
question: result.question,
}
})
)
}) })
}) })
@ -1145,6 +1151,8 @@ function GetApp(): ModuleType {
function getResult(question, subj, recData, recievedData) { function getResult(question, subj, recData, recievedData) {
return new Promise((resolve) => { return new Promise((resolve) => {
// searchIn could be [0], [1], ... to search every db in different thread. Put this into a
// forEach(qdbs) to achieve this
doALongTask({ doALongTask({
type: 'work', type: 'work',
data: { data: {
@ -1154,17 +1162,17 @@ function GetApp(): ModuleType {
questionData: recData, questionData: recData,
}, },
}) })
.then((result) => { .then((taskResult) => {
console.log(result)
try { try {
logger.DebugLog( logger.DebugLog(
`Question result length: ${result.length}`, `Question result length: ${taskResult.length}`,
'ask', 'ask',
1 1
) )
logger.DebugLog(result, 'ask', 2) logger.DebugLog(taskResult, 'ask', 2)
resolve({ resolve({
result: result, question: question,
result: taskResult.result,
success: true, success: true,
}) })
} catch (err) { } catch (err) {