(request, response)
| 28 | } |
| 29 | |
| 30 | async function TussSearch(request, response) { |
| 31 | const { name, tuss, limit, offset } = request.query; |
| 32 | |
| 33 | const hasName = typeof name === 'string' && name.trim().length > 0; |
| 34 | const hasTuss = typeof tuss === 'string' && tuss.trim().length > 0; |
| 35 | |
| 36 | let data; |
| 37 | |
| 38 | if (hasName || hasTuss) { |
| 39 | data = searchTuss({ name, tuss }); |
| 40 | } else { |
| 41 | data = getTussTerms(); |
| 42 | } |
| 43 | |
| 44 | const limitNum = parseLimit(limit); |
| 45 | const offsetNum = parseOffset(offset); |
| 46 | |
| 47 | const total = Array.isArray(data) ? data.length : 0; |
| 48 | |
| 49 | const items = paginate(data, limitNum, offsetNum); |
| 50 | |
| 51 | const payload = { |
| 52 | total, |
| 53 | limit: typeof limitNum === 'number' ? limitNum : null, |
| 54 | offset: offsetNum, |
| 55 | items, |
| 56 | }; |
| 57 | |
| 58 | return response.status(200).json(payload); |
| 59 | } |
| 60 | |
| 61 | export default app().get(TussSearch); |
nothing calls this directly
no test coverage detected