Skip to content

Commit

Permalink
🎨 🐛 Refractor a bunch of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AJR07 authored and SebassNoob committed Aug 23, 2024
1 parent adfeff5 commit 4785887
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 65 deletions.
2 changes: 1 addition & 1 deletion interapp-backend/api/routes/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function validateRequiredFields<T extends z.ZodType<ReqBody | ReqQuery>>(
export async function verifyJWT(req: Request, res: Response, next: NextFunction) {
const authHeader = req.headers.authorization;

if (!authHeader || !authHeader.startsWith('Bearer ')) {
if (!authHeader?.startsWith('Bearer ')) {
throw new HTTPError(
'Missing JWT',
'You must provide a JWT token in the Authorization header',
Expand Down
74 changes: 16 additions & 58 deletions interapp-backend/tests/unit/ServiceModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ const suite = testSuites[SUITE_NAME];
const signUpUser = async (id: number, name: string) =>
await AuthModel.signUp(id, name, 'sfsajhjkh@fdjfas', 'pass');

const createSession = async (id: number) => {
const now = new Date();
const inOneHour = new Date();
inOneHour.setHours(now.getHours() + 1);
const sessionData = {
service_id: 1,
start_time: now.toISOString(),
end_time: inOneHour.toISOString(),
ad_hoc_enabled: true,
service_hours: 1,
};
const sessionId = await ServiceModel.createServiceSession(sessionData);
expect(sessionId).toBe(id);
};

suite.createService = [
{
name: 'should create a service',
Expand Down Expand Up @@ -501,20 +516,6 @@ suite.createServiceSession = [
expect(id).toBe(1);
// create service sessions

const createSession = async (id: number) => {
const now = new Date();
const inOneHour = new Date();
inOneHour.setHours(now.getHours() + 1);
const sessionData = {
service_id: 1,
start_time: now.toISOString(),
end_time: inOneHour.toISOString(),
ad_hoc_enabled: true,
service_hours: 1,
};
const sessionId = await ServiceModel.createServiceSession(sessionData);
expect(sessionId).toBe(id);
};
for (let i = 1; i <= 10; i++) {
await createSession(i);
}
Expand Down Expand Up @@ -890,21 +891,6 @@ suite.createServiceSessionUser = [
const serviceId = await ServiceModel.createService(serviceData);
expect(serviceId).toBe(1);

const createSession = async (id: number) => {
const now = new Date();
const inOneHour = new Date();
inOneHour.setHours(now.getHours() + 1);
const sessionData = {
service_id: 1,
start_time: now.toISOString(),
end_time: inOneHour.toISOString(),
ad_hoc_enabled: true,
service_hours: 1,
};
const sessionId = await ServiceModel.createServiceSession(sessionData);
expect(sessionId).toBe(id);
};

for (let i = 1; i <= 10; i++) {
await createSession(i);
}
Expand Down Expand Up @@ -972,21 +958,6 @@ suite.createServiceSessionUsers = [
const serviceId = await ServiceModel.createService(serviceData);
expect(serviceId).toBe(1);

const createSession = async (id: number) => {
const now = new Date();
const inOneHour = new Date();
inOneHour.setHours(now.getHours() + 1);
const sessionData = {
service_id: 1,
start_time: now.toISOString(),
end_time: inOneHour.toISOString(),
ad_hoc_enabled: true,
service_hours: 1,
};
const sessionId = await ServiceModel.createServiceSession(sessionData);
expect(sessionId).toBe(id);
};

for (let i = 1; i <= 10; i++) {
await createSession(i);
}
Expand Down Expand Up @@ -1331,21 +1302,8 @@ suite.getAllServiceSessions = [
};
const id = await ServiceModel.createService(serviceData);
expect(id).toBe(1);

// create service sessions
const createSession = async (id: number) => {
const now = new Date();
const inOneHour = new Date();
inOneHour.setHours(now.getHours() + 1);
const sessionData = {
service_id: 1,
start_time: now.toISOString(),
end_time: inOneHour.toISOString(),
ad_hoc_enabled: true,
service_hours: 1,
};
const sessionId = await ServiceModel.createServiceSession(sessionData);
expect(sessionId).toBe(id);
};
for (let i = 1; i <= 10; i++) {
await createSession(i);
}
Expand Down
3 changes: 1 addition & 2 deletions interapp-frontend/src/app/admin/AdminTable/AdminTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ const AdminTable = () => {
</Table.Td>
<Table.Td>
<div className='admin-table-permissions'>
{user.permissions &&
user.permissions.map((perm) => (
{user.permissions?.map((perm) => (
<Pill key={perm} className='admin-table-permission'>
{permissionsMap[perm]}
</Pill>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ async function updateServiceHours(

// if the user was previously not attended and is now attended, add the hours
if (oldValue !== 'Attended' && value === 'Attended') offset += formValues.service_hours;
} else {
if (value === 'Attended') offset += formValues.service_hours;
} else if (value === 'Attended') {
offset += formValues.service_hours;
}

return [key, offset];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const NavbarNotifications = () => {
return unreadAnnouncements + activeSessions + verified;
}, [userNotifications]);

if (!user || !user.permissions.includes(Permissions.CLUB_MEMBER)) return <div></div>;
if (!user?.permissions.includes(Permissions.CLUB_MEMBER)) return <div></div>;
return (
<>
<div
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
const constructedSearchParams = Object.entries(Object.fromEntries(params))
.map(([key, value]) => `${key}=${value}`)
.join('&');
const fullPath = `${pathname}${constructedSearchParams ? `?${constructedSearchParams}` : ''}`;

const constructedSearchParamsParsed = constructedSearchParams ? `?${constructedSearchParams}` : '';
const fullPath = `${pathname}${constructedSearchParamsParsed}`;
router.push(`/auth/login?redirectTo=${encodeURIComponent(fullPath)}`);

return;
Expand Down

0 comments on commit 4785887

Please sign in to comment.