generated from UoaWDCC/ssr-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from UoaWDCC/fix/code
Added test cases and code to handle error in mapping function
- Loading branch information
Showing
61 changed files
with
4,161 additions
and
2,717 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.