fix(customer-satisfaction.gbapp): Improvements on answer.
This commit is contained in:
parent
414f29c1d2
commit
db8558254f
2 changed files with 32 additions and 10 deletions
|
@ -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<GuaribasQuestionAlternate> {
|
||||
text: string): Promise<GuaribasQuestion> {
|
||||
|
||||
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(
|
||||
|
|
|
@ -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<any> {
|
||||
const question = await GuaribasQuestion.findOne({
|
||||
|
||||
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.trim()}%` }
|
||||
content: { [Op.like]: `%${text}%` }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (question !== null) {
|
||||
const answer = await GuaribasAnswer.findOne({
|
||||
|
|
Loading…
Add table
Reference in a new issue