Skip to content

Commit

Permalink
fix(customer-satisfaction.gbapp): Improvements on answer.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jan 29, 2020
1 parent 414f29c commit db85582
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
22 changes: 18 additions & 4 deletions packages/customer-satisfaction.gbapp/services/CSService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 14 additions & 6 deletions packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -117,12 +118,19 @@ export class KBService {
}

public async getAnswerByText(instanceId: number, text: string): Promise<any> {
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({
Expand Down

0 comments on commit db85582

Please sign in to comment.