MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / TussSearch

Function TussSearch

pages/api/tuss/v1/index.js:30–59  ·  view source on GitHub ↗
(request, response)

Source from the content-addressed store, hash-verified

28}
29
30async 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
61export default app().get(TussSearch);

Callers

nothing calls this directly

Calls 5

searchTussFunction · 0.90
getTussTermsFunction · 0.90
parseLimitFunction · 0.85
parseOffsetFunction · 0.85
paginateFunction · 0.85

Tested by

no test coverage detected