fix(all): Code cleanup.

This commit is contained in:
Rodrigo Rodriguez 2020-08-19 13:00:21 -03:00
parent d7b72dbbc3
commit 8db05053d5
5 changed files with 21 additions and 21 deletions

View file

@ -164,7 +164,7 @@ export class GBAdminService implements IGBAdminService {
options.where = { key: key, instanceId: instanceId }; options.where = { key: key, instanceId: instanceId };
const obj = await GuaribasAdmin.findOne(options); const obj = await GuaribasAdmin.findOne(options);
return Promise.resolve(obj.value); return obj.value;
} }
public async acquireElevatedToken(instanceId: number): Promise<string> { public async acquireElevatedToken(instanceId: number): Promise<string> {

View file

@ -70,9 +70,9 @@ class SysClass {
try { try {
const res = await request(options); const res = await request(options);
return Promise.resolve(Buffer.from(res, 'binary').toString); return Buffer.from(res, 'binary').toString();
} catch (error) { } catch (error) {
return Promise.reject(new Error(error)); throw new Error(error);
} }
} }

View file

@ -250,7 +250,7 @@ export class GBConversationalService {
const params = { const params = {
audio: data, audio: data,
contentType: 'audio/l16; rate=44100', contentType: 'audio/l16; rate=44100',
model: "pt-BR_BroadbandModel" model: 'pt-BR_BroadbandModel'
}; };
speechToText speechToText
@ -476,13 +476,13 @@ export class GBConversationalService {
if (error.statusCode === 404) { if (error.statusCode === 404) {
GBLog.warn('NLP application still not publish and there are no other options for answering.'); GBLog.warn('NLP application still not publish and there are no other options for answering.');
return Promise.resolve(false); return false;
} else { } else {
const msg = `Error calling NLP, check if you have a published model and assigned keys. Error: ${ const msg = `Error calling NLP, check if you have a published model and assigned keys. Error: ${
error.statusCode ? error.statusCode : '' error.statusCode ? error.statusCode : ''
} {error.message; }`; } {error.message; }`;
return Promise.reject(new Error(msg)); throw new Error(msg);
} }
// tslint:enable:no-unsafe-any // tslint:enable:no-unsafe-any
} }
@ -506,7 +506,7 @@ export class GBConversationalService {
// tslint:ensable:no-unsafe-any // tslint:ensable:no-unsafe-any
if (intent === 'None') { if (intent === 'None') {
return Promise.resolve(false); return false;
} }
GBLog.info(`NLP called: ${intent} ${firstEntity}`); GBLog.info(`NLP called: ${intent} ${firstEntity}`);
@ -514,15 +514,15 @@ export class GBConversationalService {
try { try {
await step.replaceDialog(`/${intent}`, nlp.entities); await step.replaceDialog(`/${intent}`, nlp.entities);
return Promise.resolve(true); return true;
} catch (error) { } catch (error) {
const msg = `Error finding dialog associated to NLP event: ${intent}: ${error.message}`; const msg = `Error finding dialog associated to NLP event: ${intent}: ${error.message}`;
return Promise.reject(new Error(msg)); throw new Error(msg);
} }
} }
return Promise.resolve(false); return false;
} }
async translate(min: GBMinInstance, key: string, endPoint: string, text: string, language: string): Promise<string> { async translate(min: GBMinInstance, key: string, endPoint: string, text: string, language: string): Promise<string> {

View file

@ -397,7 +397,7 @@ export class GBMinService {
try { try {
const json = await request(options); const json = await request(options);
return Promise.resolve(JSON.parse(json)); return JSON.parse(json);
} catch (error) { } catch (error) {
const msg = `[botId:${ const msg = `[botId:${
instance.botId instance.botId

View file

@ -150,10 +150,10 @@ export class KBService implements IGBKBService {
} }
}); });
return Promise.resolve({ question: question, answer: answer }); return { question: question, answer: answer };
} }
return Promise.resolve(undefined); return undefined;
} }
public async addAnswer(obj: GuaribasAnswer): Promise<GuaribasAnswer> { public async addAnswer(obj: GuaribasAnswer): Promise<GuaribasAnswer> {
@ -197,17 +197,17 @@ export class KBService implements IGBKBService {
if (values && values.length > 0 && values[0]['@search.score'] >= searchScore) { if (values && values.length > 0 && values[0]['@search.score'] >= searchScore) {
const value = await this.getAnswerById(instance.instanceId, values[0].answerId); const value = await this.getAnswerById(instance.instanceId, values[0].answerId);
if (value !== null) { if (value !== null) {
return Promise.resolve({ answer: value, questionId: values[0].questionId }); return { answer: value, questionId: values[0].questionId };
} else { } else {
return Promise.resolve({ answer: undefined, questionId: 0 }); return { answer: undefined, questionId: 0 };
} }
} }
} else { } else {
const data = await this.getAnswerByText(instance.instanceId, query); const data = await this.getAnswerByText(instance.instanceId, query);
if (data) { if (data) {
return Promise.resolve({ answer: data.answer, questionId: data.question.questionId }); return { answer: data.answer, questionId: data.question.questionId };
} else { } else {
return Promise.resolve({ answer: undefined, questionId: 0 }); return { answer: undefined, questionId: 0 };
} }
} }
} }
@ -368,11 +368,11 @@ export class KBService implements IGBKBService {
lastAnswer = answer1; lastAnswer = answer1;
lastQuestionId = question1.questionId; lastQuestionId = question1.questionId;
return Promise.resolve(question1.questionId); return question1.questionId;
} else { } else {
// Skips the header. // Skips the header.
return Promise.resolve(undefined); return undefined;
} }
} }
}); });
@ -573,9 +573,9 @@ export class KBService implements IGBKBService {
}); });
if (item.children) { if (item.children) {
return Promise.resolve(doIt(item.children, value.subjectId)); return doIt(item.children, value.subjectId);
} else { } else {
return Promise.resolve(item); return item;
} }
}); });
}; };