first commit
This commit is contained in:
23
resources/js/plugins/fake-api/handlers/pages/faq/index.js
Normal file
23
resources/js/plugins/fake-api/handlers/pages/faq/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import is from '@sindresorhus/is'
|
||||
import { rest } from 'msw'
|
||||
import { db } from '@db/pages/faq/db'
|
||||
|
||||
export const handlerPagesFaq = [
|
||||
rest.get(('/api/pages/faq'), (req, res, ctx) => {
|
||||
const q = req.url.searchParams.get('q') ?? ''
|
||||
const searchQuery = is.string(q) ? q : undefined
|
||||
const queryLowered = (searchQuery ?? '').toString().toLowerCase()
|
||||
const filteredData = []
|
||||
|
||||
Object.entries(db.faqs).forEach(([_, faqObj]) => {
|
||||
const filteredQAndA = faqObj.faqs.filter(obj => {
|
||||
return obj.question.toLowerCase().includes(queryLowered)
|
||||
})
|
||||
|
||||
if (filteredQAndA.length)
|
||||
filteredData.push({ ...faqObj, faqs: filteredQAndA })
|
||||
})
|
||||
|
||||
return res(ctx.status(200), ctx.json(filteredData))
|
||||
}),
|
||||
]
|
Reference in New Issue
Block a user