Skip to content

Commit

Permalink
Admin dashboard pt2 (#13)
Browse files Browse the repository at this point in the history
* works one table ayo

Co-authored-by: rm41339 <[email protected]>

* finished (except header boxes)

* Task11/user boilerplate (#12)

* update user schema to contain city, state, and isAcceptingRequests

* update chapter and user routes

* update user schema with isActive field

* fix register function for admin to add new chapter

* fixing register function

* works one table ayo (rebasing)

Co-authored-by: rm41339 <[email protected]>

* finished (except header boxes)

* TO DELETE just fixing my computer

* added the two displays top right

* deleted comment blocks

* Delete .vscode/settings.json

* Delete client/tsconfig.json

* Delete package.json

---------

Co-authored-by: rm41339 <[email protected]>
Co-authored-by: kygchng <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2024
1 parent a1d9ed1 commit c1e9a61
Show file tree
Hide file tree
Showing 12 changed files with 4,034 additions and 3,399 deletions.
377 changes: 248 additions & 129 deletions client/src/AdminDashboard/TempAdminDashboardPage.tsx

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function App() {
{/* Routes accessed only if user is not authenticated */}
<Route element={<UnauthenticatedRoutesWrapper />}>
<Route path="/login" element={<LoginPage />} />
<Route path="/admin" element={<TempAdminDashboardPage />} />
{/* <Route path="/admin" element={<TempAdminDashboardPage />} /> */}
{/* <Route path="/admin" element={<TempAdminDashboardPage />} /> */}
<Route path="/register" element={<RegisterPage />} />
<Route
path="/verify-account/:token"
element={<VerifyAccountPage />}
Expand All @@ -62,6 +64,7 @@ function App() {
</Route>
<Route element={<AdminRoutesWrapper />}>
<Route path="/users" element={<AdminDashboardPage />} />
<Route path="/admin" element={<TempAdminDashboardPage />} />
</Route>

{/* Route which redirects to a different page depending on if the user is an authenticated or not by utilizing the DynamicRedirect component */}
Expand Down
21 changes: 0 additions & 21 deletions client/tsconfig.json

This file was deleted.

60 changes: 0 additions & 60 deletions package.json

This file was deleted.

31 changes: 30 additions & 1 deletion server/src/controllers/birthdayRequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getRequestById,
deleteRequestByID,
createBirthdayRequestByID,
getMonthlyOverviewByDate,
} from '../services/birthdayRequest.service.ts';
import { getUserById } from '../services/user.service.ts';
import {
Expand Down Expand Up @@ -312,4 +313,32 @@ const createRequest = async (
}
};

export { getAllRequests, updateRequestStatus, deleteRequest, createRequest };
const getMonthlyOverview = async (
req: express.Request,
res: express.Response,
next: express.NextFunction,
) => {
const { startDate, endDate } = req.query;

if (!startDate || !endDate) {
return next(ApiError.missingFields(['startDate', 'endDate']));
}

try {
const start = new Date(startDate as string);
const end = new Date(endDate as string);

const overview = await getMonthlyOverviewByDate(start, end);
res.status(StatusCode.OK).json(overview);
} catch (error) {
next(ApiError.internal('Failed to retrieve monthly overview.'));
}
};

export {
getAllRequests,
updateRequestStatus,
deleteRequest,
createRequest,
getMonthlyOverview,
};
34 changes: 32 additions & 2 deletions server/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import express from 'express';
import ApiError from '../util/apiError.ts';
import StatusCode from '../util/statusCode.ts';
import { toggleRequestByID } from '../services/user.service.ts';
import {
toggleRequestByID,
countActiveUsers,
countAcceptingRequestsUsers
} from '../services/user.service.ts';

const toggleRequest = async (
req: express.Request,
Expand All @@ -25,4 +29,30 @@ const toggleRequest = async (
});
};

export { toggleRequest };
const getActiveUserCount = async (
req: express.Request,
res: express.Response,
next: express.NextFunction,
) => {
try {
const count = await countActiveUsers();
res.status(StatusCode.OK).json({ activeUserCount: count });
} catch (e) {
next(ApiError.internal('Unable to get active user count.'));
}
};

const getAcceptingRequestsUserCount = async (
req: express.Request,
res: express.Response,
next: express.NextFunction,
) => {
try {
const count = await countAcceptingRequestsUsers();
res.status(StatusCode.OK).json({ acceptingRequestsUserCount: count });
} catch (e) {
next(ApiError.internal('Unable to get accepting requests user count.'));
}
};

export { toggleRequest, getActiveUserCount, getAcceptingRequestsUserCount };
2 changes: 1 addition & 1 deletion server/src/models/birthdayRequest.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose, { ObjectId } from 'mongoose';
import mongoose from 'mongoose';

enum ChildGender {
'Boy',
Expand Down
3 changes: 3 additions & 0 deletions server/src/routes/birthdayRequest.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
updateRequestStatus,
deleteRequest,
createRequest,
getMonthlyOverview,
} from '../controllers/birthdayRequest.controller.ts';
import { isAuthenticated } from '../controllers/auth.middleware.ts';
import 'dotenv/config';
Expand All @@ -20,4 +21,6 @@ router.delete('/deleterequest/:id', isAuthenticated, isAdmin, deleteRequest);

router.post('/createrequest', isAuthenticated, isAdmin, createRequest);

router.get('/monthly-overview', isAuthenticated, isAdmin, getMonthlyOverview);

export default router;
10 changes: 9 additions & 1 deletion server/src/routes/user.route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import express from 'express';
import { isAdmin } from '../controllers/admin.middleware.ts';
import { toggleRequest } from '../controllers/user.controller.ts';
import {
toggleRequest,
getActiveUserCount,
getAcceptingRequestsUserCount
} from '../controllers/user.controller.ts';
import { isAuthenticated } from '../controllers/auth.middleware.ts';
import 'dotenv/config';

const router = express.Router();

router.put('/toggleRequests/:id', isAuthenticated, isAdmin, toggleRequest);

router.get('/activeUserCount', isAuthenticated, isAdmin, getActiveUserCount);

router.get('/acceptingRequestsUserCount', isAuthenticated, isAdmin, getAcceptingRequestsUserCount);

export default router;
Loading

0 comments on commit c1e9a61

Please sign in to comment.