Skip to content

Commit

Permalink
Fix api type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-Dunker committed Jul 16, 2024
1 parent 92f42b3 commit 248ada5
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions pages/api/v1/applicants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const getHandler: NextApiHandler = async (req, res) => {
const params = req.query;

// assume page is 1 indexed
const page = Number(params?.page ?? 1);
const pageSize = Number(params?.pageSize ?? 10);
const filters = parseFilters(params?.filters);
const sort = parseSort(params?.sorter);
const page = Number(params.page ?? 1);
const pageSize = Number(params.pageSize ?? 10);
const filters = parseFilters(params.filters ?? '');
const sort = parseSort(params.sorter ?? '');

const { userDataCollection } = await connectToDatabase();
const data = userDataCollection
Expand All @@ -36,15 +36,11 @@ const getHandler: NextApiHandler = async (req, res) => {
.limit(pageSize);
const totalCount = await userDataCollection.countDocuments(filters);

return res
.status(200)
.json({ data: await data.toArray(), totalCount, page, pageSize });
return res.status(200).json({ data: await data.toArray(), totalCount, page, pageSize });
};

function parseFilters(queryString: string | string[]): Record<string, any> {
const filterString = Array.isArray(queryString)
? queryString[0]
: queryString;
const filterString = Array.isArray(queryString) ? queryString[0] : queryString;
const filters: Record<string, any> = JSON.parse(filterString);
for (const key in filters) {
const value = filters[key];
Expand All @@ -69,10 +65,10 @@ function parseSort(queryString: string | string[]): any {
}
export const config = {
api: {
bodyParser: {
sizeLimit: '3mb'
}
}
}
bodyParser: {
sizeLimit: '3mb',
},
},
};

export default protect(handler);

0 comments on commit 248ada5

Please sign in to comment.