Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases and code to handle error in mapping function #128

Merged
merged 33 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b33e262
Added test cases and code to handle error in mapping function
nroh555 Jul 1, 2024
ee46b79
Refactored introductions
nroh555 Jul 1, 2024
94b9b74
Refactored partners
nroh555 Jul 1, 2024
f7193e1
Refactored some photos component
nroh555 Jul 1, 2024
ab57ccc
Refactored values
nroh555 Jul 1, 2024
017c99b
Added prettier script
nroh555 Jul 1, 2024
fa56008
Made prettier run on every push
nroh555 Jul 1, 2024
eff51f8
Attempted to fix build issue
nroh555 Jul 1, 2024
327aaa3
Attempted 2
nroh555 Jul 1, 2024
68cea4a
Added explicit run
nroh555 Jul 1, 2024
0a6e914
Changed script name
nroh555 Jul 1, 2024
7e5af7e
Test again
nroh555 Jul 1, 2024
26b8340
Changed script so runs prettier write
nroh555 Jul 1, 2024
6c4bf61
Only change format for typescript files
nroh555 Jul 1, 2024
3dbfcdd
fix: Added ternary operator for presidents
Harsheel12 Jul 2, 2024
b744ef3
fix: Updated failing test case
Harsheel12 Jul 2, 2024
7a487dd
Purposely added not formatted code
nroh555 Jul 2, 2024
3f16ad0
Merge branch 'fix/code' of https://github.com/UoaWDCC/auis-portal int…
nroh555 Jul 2, 2024
be29cca
Test again
nroh555 Jul 2, 2024
0931190
Test again
nroh555 Jul 2, 2024
9e2327e
Formatted all the files with prettier
nroh555 Jul 2, 2024
121cf97
Added unformatted code
nroh555 Jul 2, 2024
bf28e7f
Modified prettier.yml file
nroh555 Jul 2, 2024
f842d2d
Format code with Prettier
github-actions[bot] Jul 2, 2024
a1fd0af
Modified prettier script again
nroh555 Jul 2, 2024
e2f84e4
Format code with Prettier
github-actions[bot] Jul 2, 2024
98b6c04
I want to kill myself
nroh555 Jul 2, 2024
e66915f
Merge branch 'fix/code' of https://github.com/UoaWDCC/auis-portal int…
nroh555 Jul 2, 2024
2d8348e
Deleted changes.txt
nroh555 Jul 2, 2024
c854564
testing unformatted code
Harsheel12 Jul 2, 2024
18becad
Format code with Prettier
github-actions[bot] Jul 2, 2024
863c9fc
Changed prettier settings
nroh555 Jul 2, 2024
e57dc80
Merge branch 'fix/code' of https://github.com/UoaWDCC/auis-portal int…
nroh555 Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
49 changes: 49 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Format Code

on:
push:
branches:
- "**"

jobs:
format:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Format code with Prettier
run: yarn format

- name: Check for changes
id: git_changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
if [ -n "$(git status --porcelain)" ]; then
echo "changes_detected=true" >> "$GITHUB_ENV"
else
echo "changes_detected=false" >> "$GITHUB_ENV"
fi

- name: Commit and push changes
if: ${{ env.changes_detected == 'true' }}
run: |
git add .
git commit -m "Format code with Prettier"
git push

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"endOfLine": "auto",
"printWidth": 80,
"plugins": ["prettier-plugin-tailwindcss"]
}
28 changes: 18 additions & 10 deletions api/controller/adminController.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import { Request, Response } from 'express';
import { Request, Response } from "express";
import asyncHandler from "../middleware/asyncHandler";

export const createNewEvent = asyncHandler(async (req: Request, res: Response) => {
export const createNewEvent = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});
}
);

export const getStagingEvents = asyncHandler(async (req: Request, res: Response) => {
export const getStagingEvents = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});
}
);

export const getEventInformation = asyncHandler(async (req: Request, res: Response) => {
export const getEventInformation = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});
}
);

export const updateEventInformation = asyncHandler(async (req: Request, res: Response) => {
export const updateEventInformation = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});
}
);

export const getMembers = asyncHandler(async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
throw new Error("Not implemented yet");
});
12 changes: 7 additions & 5 deletions api/controller/creditController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Request, Response } from 'express';
import { Request, Response } from "express";
import asyncHandler from "../middleware/asyncHandler";
export const getTeamInfo = asyncHandler(async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
throw new Error("Not implemented yet");
});

export const getCredits = asyncHandler(async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
throw new Error("Not implemented yet");
});

export const getOurPurpose = asyncHandler(async (req: Request, res: Response) => {
export const getOurPurpose = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});
}
);
23 changes: 13 additions & 10 deletions api/controller/eventController.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { Request, Response } from 'express';
import Events from '../db/sampleEvents';
import { Request, Response } from "express";
import Events from "../db/sampleEvents";
import asyncHandler from "../middleware/asyncHandler";

const getEvents = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const getEvents = asyncHandler(
async (req: Request, res: Response): Promise<void> => {
res.json(Events);
});
}
);


const getEventById = asyncHandler(async (req: Request, res: Response): Promise<void> => {
const getEventById = asyncHandler(
async (req: Request, res: Response): Promise<void> => {
const id = req.params.id;
const event = Events.find((event) => event._id === id);

if (event) {
res.json(event);
res.json(event);
} else {
res.status(404);
throw new Error('Event not found');
res.status(404);
throw new Error("Event not found");
}
});
}
);

export { getEvents, getEventById };
15 changes: 8 additions & 7 deletions api/controller/photoController.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// controllers/photoController.ts
import { Request, Response } from 'express';
import asyncHandler from "../middleware/asyncHandler";// Adjust the import path as necessary
import { Request, Response } from "express";
import asyncHandler from "../middleware/asyncHandler"; // Adjust the import path as necessary

export const uploadPhoto = asyncHandler(async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
throw new Error("Not implemented yet");
});

export const getPhotoById = asyncHandler(async (req: Request, res: Response) => {
export const getPhotoById = asyncHandler(
async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
});

}
);

export const deletePhoto = asyncHandler(async (req: Request, res: Response) => {
throw new Error("Not implemented yet");
throw new Error("Not implemented yet");
});
4 changes: 2 additions & 2 deletions api/db/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, model } from 'mongoose';
import { Schema, model } from "mongoose";

const userSchema = new Schema({
firstName: {
Expand All @@ -15,6 +15,6 @@ const userSchema = new Schema({
},
});

const User = model('User', userSchema);
const User = model("User", userSchema);

export default User;
1 change: 0 additions & 1 deletion api/db/config/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dotenv from "dotenv";

dotenv.config();

(function checkProcessEnvIntegrity() {
if (!process.env.DATABASE_HOST) {
throw Error(
Expand Down
9 changes: 5 additions & 4 deletions api/middleware/asyncHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Request, Response, NextFunction } from 'express';
import { Request, Response, NextFunction } from "express";

const asyncHandler = (
fn: (req: Request, res: Response, next: NextFunction) => Promise<any>) => (req: Request, res: Response, next: NextFunction) => {
const asyncHandler =
(fn: (req: Request, res: Response, next: NextFunction) => Promise<any>) =>
(req: Request, res: Response, next: NextFunction) => {
Promise.resolve(fn(req, res, next)).catch(next);
};
};

export default asyncHandler;
25 changes: 13 additions & 12 deletions api/middleware/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Request, Response, NextFunction } from 'express';
import { Request, Response, NextFunction } from "express";
import asyncHandler from "./asyncHandler";


export const protect = asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
export const protect = asyncHandler(
async (req: Request, res: Response, next: NextFunction) => {
// Authentication and authorization logic here
// If user is authenticated and authorized, call next()
// Otherwise, respond wit an error
next();
});
}
);

export const authorize = (...roles: string[]) => {
return (req: Request, res: Response, next: NextFunction) => {
// Authorization logic here
// Check if the authenticated user's role is in the allowed roles
// If so, call next()
// Otherwise, respond with an error
next();
};
};
return (req: Request, res: Response, next: NextFunction) => {
// Authorization logic here
// Check if the authenticated user's role is in the allowed roles
// If so, call next()
// Otherwise, respond with an error
next();
};
};
41 changes: 23 additions & 18 deletions api/middleware/errorMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { Request, Response, NextFunction } from 'express';
import { Error } from 'mongoose';
import dotenv from 'dotenv';
import { Request, Response, NextFunction } from "express";
import { Error } from "mongoose";
import dotenv from "dotenv";

dotenv.config();

const notFound = (req: Request, res: Response, next: NextFunction): void => {
const error = new Error(`Not Found - ${req.originalUrl}`);
res.status(404);
next(error);
const error = new Error(`Not Found - ${req.originalUrl}`);
res.status(404);
next(error);
};

const errorHandler = (err: Error & { name?: string; kind?: string }, req: Request, res: Response, next: NextFunction): void => {
let statusCode: number = res.statusCode === 200 ? 500 : res.statusCode;
let message: string = err.message;
const errorHandler = (
err: Error & { name?: string; kind?: string },
req: Request,
res: Response,
next: NextFunction
): void => {
let statusCode: number = res.statusCode === 200 ? 500 : res.statusCode;
let message: string = err.message;

if (err.name === 'CastError' && err.kind === 'ObjectId') {
statusCode = 404;
message = 'Resource not found';
}
if (err.name === "CastError" && err.kind === "ObjectId") {
statusCode = 404;
message = "Resource not found";
}

res.status(statusCode).json({
message: message,
stack: process.env.NODE_ENV === 'production' ? null : err.stack,
});
res.status(statusCode).json({
message: message,
stack: process.env.NODE_ENV === "production" ? null : err.stack,
});
};

export { notFound, errorHandler };
export { notFound, errorHandler };
34 changes: 20 additions & 14 deletions api/models/users.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { pgTable, serial, varchar, boolean, timestamp } from 'drizzle-orm/pg-core';
import {
pgTable,
serial,
varchar,
boolean,
timestamp,
} from "drizzle-orm/pg-core";

export const users = pgTable('users', {
user_id: serial('user_id').primaryKey(),
email: varchar('email', { length: 255 }).notNull().unique(),
uoa_id: varchar('uoa_id', { length: 50 }),
upi: varchar('upi', { length: 50 }),
institution: varchar('institution', { length: 50 }),
year: varchar('year', { length: 50 }),
study_field: varchar('study_field', { length: 255 }),
name: varchar('name', { length: 255 }),
is_admin: boolean('is_admin').default(false),
is_paid: boolean('is_paid').default(false),
is_info_confirmed: boolean('is_info_confirmed').default(false),
created_at: timestamp('created_at').defaultNow(),
export const users = pgTable("users", {
user_id: serial("user_id").primaryKey(),
email: varchar("email", { length: 255 }).notNull().unique(),
uoa_id: varchar("uoa_id", { length: 50 }),
upi: varchar("upi", { length: 50 }),
institution: varchar("institution", { length: 50 }),
year: varchar("year", { length: 50 }),
study_field: varchar("study_field", { length: 255 }),
name: varchar("name", { length: 255 }),
is_admin: boolean("is_admin").default(false),
is_paid: boolean("is_paid").default(false),
is_info_confirmed: boolean("is_info_confirmed").default(false),
created_at: timestamp("created_at").defaultNow(),
});
22 changes: 14 additions & 8 deletions api/routes/adminRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import express from 'express';
import { createNewEvent, getStagingEvents, getEventInformation, updateEventInformation, getMembers} from "../controller/adminController";
import { protect } from '../middleware/authMiddleware';
import express from "express";
import {
createNewEvent,
getStagingEvents,
getEventInformation,
updateEventInformation,
getMembers,
} from "../controller/adminController";
import { protect } from "../middleware/authMiddleware";

const router = express.Router();

router.use(protect);

router.post('/new-event', createNewEvent);
router.get('/staging', getStagingEvents);
router.get('/event-information', getEventInformation);
router.put('/event-information/:eventId', updateEventInformation);
router.get('/members', getMembers);
router.post("/new-event", createNewEvent);
router.get("/staging", getStagingEvents);
router.get("/event-information", getEventInformation);
router.put("/event-information/:eventId", updateEventInformation);
router.get("/members", getMembers);

export default router;
10 changes: 5 additions & 5 deletions api/routes/authRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express';
import {signUp, logIn, clerkSignUp} from "../controller/authController"
import express from "express";
import { signUp, logIn, clerkSignUp } from "../controller/authController";

const router = express.Router();

router.post('/sign-up', signUp);
router.post('/sign-in', logIn);
router.post('/clerk-sign-up', clerkSignUp);
router.post("/sign-up", signUp);
router.post("/sign-in", logIn);
router.post("/clerk-sign-up", clerkSignUp);

export default router;
Loading
Loading