Companies are now listing properly

This commit is contained in:
2026-02-13 17:02:03 -06:00
parent 24d0c066fd
commit 628dc35dea
13 changed files with 123 additions and 15 deletions
+19 -13
View File
@@ -10,22 +10,28 @@ export default createRoute(
"get",
["/companies"],
async (c) => {
/**
*
*
* @TODO MAKE THIS WORK
*
*
*
*/
const page = new Number(c.req.query("page") ?? 1) as number;
const rpp = new Number(c.req.query("rpp") ?? 30) as number; // Records Per Page
const companyQty = await companies.count();
const company = await companies.fetch(c.req.param("identifier"));
const data = await companies.fetchPages(page, rpp);
const response = apiResponse.successful(
"Company Fetched Successfully!",
company,
let response = apiResponse.successful(
"Companies Fetched Successfully!",
data,
{
pagination: {
previousPage: page == 1 ? null : page - 1, // Previous Page
currentPage: page, // Current Page
nextPage: page >= companyQty / rpp ? null : page + 1, // Next Page
totalPages: Math.ceil(companyQty / rpp), // Total Number of Pages
totalRecords: companyQty, // Total Number of Records
listedRecords: rpp, // Total Number of Records being recieved at time of request.
},
},
);
return c.json(response, response.status as ContentfulStatusCode);
},
authMiddleware({ permissions: ["company.fetch"] }),
authMiddleware({ permissions: ["company.fetch.many"] }),
);