Skip to content

Commit

Permalink
fix(qna): questions-filter is case-insensitive (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Oct 3, 2018
1 parent c8dd522 commit 03fa755
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
26 changes: 9 additions & 17 deletions packages/functionals/botpress-qna/src/index.js
Expand Up @@ -171,7 +171,11 @@ module.exports = {
const filteredQuestions = allQuestions.filter(({ questions, metadata }) => {
const category = getFieldFromMetadata(metadata, 'category')

const isRightId = questions.join('\n').indexOf(question) !== -1
const isRightId =
questions
.join('\n')
.toLowerCase()
.indexOf(question.toLowerCase()) !== -1

if (!categories.length) {
return isRightId
Expand Down Expand Up @@ -208,15 +212,10 @@ module.exports = {
return { items, count }
}

router.get('/', async ({ query: { limit, offset } }, res) => {
router.get('/', async ({ query: { question = '', categories = [], limit, offset } }, res) => {
try {
const items = await this.storage.all({
limit: limit ? parseInt(limit) : undefined,
offset: offset ? parseInt(offset) : undefined
})

const overallItemsCount = await this.storage.count()
res.send({ items, overallItemsCount, hasCategory: !!this.isMicrosoftMakerUsed })
const items = await getQuestions({ question, categories }, { limit, offset })
res.send({ ...items, hasCategory: !!this.isMicrosoftMakerUsed })
} catch (e) {
logger.error('QnA Error', e, e.stack)
res.status(500).send(e.message || 'Error')
Expand Down Expand Up @@ -328,15 +327,8 @@ module.exports = {
res.end(csvUploadStatuses[req.params.csvUploadStatusId])
})

router.get('/category/list', (req, res) => {
router.get('/categories', (req, res) => {
res.send({ categories })
})

router.get('/questions/filter', async (req, res) => {
const { query: { question = '', categories = [], limit, offset } } = req
const questionsData = await getQuestions({ question, categories }, { limit, offset })

res.send(questionsData)
})
}
}
4 changes: 2 additions & 2 deletions packages/functionals/botpress-qna/src/views/index.js
Expand Up @@ -74,7 +74,7 @@ export default class QnaAdmin extends Component {
}

fetchCategories() {
this.props.bp.axios.get('/api/botpress-qna/category/list').then(({ data: { categories } }) => {
this.props.bp.axios.get('/api/botpress-qna/categories').then(({ data: { categories } }) => {
const categoriesOptions = categories.map(category => ({ label: category, value: category }))

this.setState({ categoriesOptions })
Expand All @@ -97,7 +97,7 @@ export default class QnaAdmin extends Component {
const categories = filterCategory.map(({ value }) => value)

this.props.bp.axios
.get('/api/botpress-qna/questions/filter', {
.get('/api/botpress-qna/', {
params: {
question,
categories,
Expand Down

0 comments on commit 03fa755

Please sign in to comment.