From db8558254f371dbe786cf4e274a0abf9d901122c Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 29 Jan 2020 10:48:51 -0300 Subject: [PATCH] fix(customer-satisfaction.gbapp): Improvements on answer. --- .../services/CSService.ts | 22 +++++++++++++++---- packages/kb.gbapp/services/KBService.ts | 20 ++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/packages/customer-satisfaction.gbapp/services/CSService.ts b/packages/customer-satisfaction.gbapp/services/CSService.ts index 74ba2706..c403e052 100644 --- a/packages/customer-satisfaction.gbapp/services/CSService.ts +++ b/packages/customer-satisfaction.gbapp/services/CSService.ts @@ -32,22 +32,36 @@ import { GuaribasConversation } from '../../analytics.gblib/models'; import { GuaribasQuestionAlternate } from '../models'; +import { GuaribasQuestion } from 'packages/kb.gbapp/models'; /** * Customer Satisfaction Service Layer. */ export class CSService { - public async resolveQuestionAlternate( + public async getQuestionFromAlternateText( instanceId: number, - questionTyped: string): Promise { + text: string): Promise { - return GuaribasQuestionAlternate.findOne({ + let questionAlternate = await GuaribasQuestionAlternate.findOne({ where: { instanceId: instanceId, - questionTyped: questionTyped + questionTyped: text } }); + + let question: GuaribasQuestion = null; + + if (questionAlternate !== null) { + + question = await GuaribasQuestion.findOne({ + where: { + instanceId: instanceId, + questionId: questionAlternate.questionTyped; + } + }); + } + return question; } public async insertQuestionAlternate( diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 7ef444db..1d5057e4 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -56,6 +56,7 @@ import { GuaribasAnswer, GuaribasQuestion, GuaribasSubject } from '../models'; import { Messages } from '../strings'; import { GBConfigService } from './../../core.gbapp/services/GBConfigService'; import { GBServer } from '../../../src/app'; +import { CSService } from '../../customer-satisfaction.gbapp/services/CSService'; /** @@ -117,12 +118,19 @@ export class KBService { } public async getAnswerByText(instanceId: number, text: string): Promise { - const question = await GuaribasQuestion.findOne({ - where: { - instanceId: instanceId, - content: { [Op.like]: `%${text.trim()}%` } - } - }); + + text = text.trim(); + const service = new CSService(); + let question = await service.getQuestionFromAlternateText(instanceId, text); + + if (question !== null) { + question = await GuaribasQuestion.findOne({ + where: { + instanceId: instanceId, + content: { [Op.like]: `%${text}%` } + } + }); + } if (question !== null) { const answer = await GuaribasAnswer.findOne({