Companies are now listing properly
This commit is contained in:
@@ -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"] }),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user