Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobc2700 committed Jul 15, 2024
2 parents deca9dd + d632eed commit 41bae16
Show file tree
Hide file tree
Showing 23 changed files with 6,985 additions and 6,841 deletions.
16 changes: 0 additions & 16 deletions .env

This file was deleted.

38 changes: 19 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Test

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Build
run: yarn test
name: Test

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Build
run: yarn test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "jest --config=testing/jest.config.ts"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.21",
"@types/express-rate-limit": "^6.0.0",
Expand Down
8 changes: 5 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
cd /home/ubuntu/rp-api
yarn build
#!/bin/bash
cd /home/ubuntu/rp-api
sudo yarn build


25 changes: 14 additions & 11 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash
cd /home/ubuntu/rp-api
sudo yarn

sudo pm2 describe appname 2>&1 /dev/null
RUNNING=$?


if [ "${RUNNING}" -eq 0 ]; then
sudo pm2 start build/app.js --name RP_API -i 2 --wait-ready --listen-timeout 10000
fi;
#!/bin/bash
cd /home/ubuntu/rp-api
sudo yarn

sudo pm2 describe appname 2>&1 /dev/null
RUNNING=$?


if [ "${RUNNING}" -eq 0 ]; then
sudo pm2 start build/app.js --name RP_API -i 2 --wait-ready --listen-timeout 10000
fi;



7 changes: 4 additions & 3 deletions scripts/reload_server.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
cd /home/ubuntu/rp-api
sudo pm2 reload RP_API
#!/bin/bash
cd /home/ubuntu/rp-api
sudo pm2 reload RP_API

4 changes: 3 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import morgan from "morgan";
import bodyParser from "body-parser";
import errorHandler from "./middleware/error-handler";

import attendeeRouter from "./services/attendees/attendee-router";
import attendeeRouter from "./services/attendee/attendee-router";
import authRouter from "./services/auth/auth-router";
import eventsRouter from "./services/events/events-router";
import notificationsRouter from "./services/notifications/notifications-router";
import registrationRouter from "./services/registration/registration-router";
import s3Router from "./services/s3/s3-router";
import statsRouter from "./services/stats/stats-router";
import sponsorRouter from "./services/sponsor/sponsor-router";
import subscriptionRouter from "./services/subscription/subscription-router";

const app = express();
Expand All @@ -42,6 +43,7 @@ app.use("/notifications", databaseMiddleware, notificationsRouter);
app.use("/registration", databaseMiddleware, registrationRouter);
app.use("/s3", databaseMiddleware, s3Router);
app.use("/stats", databaseMiddleware, statsRouter);
app.use("/sponsor", databaseMiddleware, sponsorRouter);
app.use("/subscription", databaseMiddleware, subscriptionRouter);

app.get("/status", (_, res) => {
Expand Down
24 changes: 21 additions & 3 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import mongoose, { Schema, Document } from "mongoose";
import {
AttendeeSchema,
AttendeeValidator,
} from "./services/attendees/attendee-schema";
import { RoleValidator, RoleSchema } from "./services/auth/auth-schema";
} from "./services/attendee/attendee-schema";
import {
AttendeeAttendanceSchema,
AttendeeAttendanceValidator,
} from "./services/attendee/attendee-schema";
import {
EventSchema,
privateEventValidator,
} from "./services/events/events-schema";
import {
EventAttendanceSchema,
EventAttendanceValidator,
} from "./services/events/events-schema";
import { RoleValidator, RoleSchema } from "./services/auth/auth-schema";
import {
RegistrationSchema,
RegistrationValidator,
Expand Down Expand Up @@ -55,12 +63,22 @@ function initializeModel(
export const Database = {
ROLES: initializeModel("roles", RoleSchema, RoleValidator),
EVENTS: initializeModel("events", EventSchema, privateEventValidator),
EVENTS_ATTENDANCE: initializeModel(
"events_attendance",
EventAttendanceSchema,
EventAttendanceValidator
),
ATTENDEE: initializeModel("attendee", AttendeeSchema, AttendeeValidator),
ATTENDEE_ATTENDANCE: initializeModel(
"attendee_attendance",
AttendeeAttendanceSchema,
AttendeeAttendanceValidator
),
SUBSCRIPTIONS: initializeModel(
"subscriptions",
SubscriptionSchema,
SubscriptionSchemaValidator
),
ATTENDEES: initializeModel("attendees", AttendeeSchema, AttendeeValidator),
REGISTRATION: initializeModel(
"registration",
RegistrationSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { StatusCodes } from "http-status-codes";
import {
AttendeeValidator,
EventIdValidator,
PartialAttendeeFilter,
PartialAttendeeValidator,
} from "./attendee-schema";
import { Database } from "../../database";
import RoleChecker from "../../middleware/role-checker";
import { Role } from "../auth/auth-models";
import dotenv from "dotenv";
import { generateQrHash } from "./attendees-utils";
import { generateQrHash } from "../checkin/checkin-utils";

Check failure on line 12 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../checkin/checkin-utils' or its corresponding type declarations.

dotenv.config();

Expand All @@ -25,15 +25,15 @@ attendeeRouter.post(
const { eventId } = EventIdValidator.parse(req.params);

try {
const attendee = await Database.ATTENDEES.findOne({ userId });
const attendee = await Database.ATTENDEE.findOne({ userId });

if (!attendee) {
return res
.status(StatusCodes.NOT_FOUND)
.json({ error: "UserNotFound" });
}

await Database.ATTENDEES.updateOne(
await Database.ATTENDEE.updateOne(
{ userId: userId },
{ $addToSet: { favorites: eventId } }
);
Expand All @@ -55,15 +55,15 @@ attendeeRouter.delete(
const { eventId } = EventIdValidator.parse(req.params);

try {
const attendee = await Database.ATTENDEES.findOne({ userId });
const attendee = await Database.ATTENDEE.findOne({ userId });

if (!attendee) {
return res
.status(StatusCodes.NOT_FOUND)
.json({ error: "UserNotFound" });
}

await Database.ATTENDEES.updateOne(
await Database.ATTENDEE.updateOne(
{ userId: userId },
{ $pull: { favorites: eventId } }
);
Expand All @@ -84,7 +84,7 @@ attendeeRouter.get(
const userId = payload.userId;

try {
const attendee = await Database.ATTENDEES.findOne({ userId });
const attendee = await Database.ATTENDEE.findOne({ userId });

if (!attendee) {
return res
Expand All @@ -103,7 +103,7 @@ attendeeRouter.get(
attendeeRouter.post("/", async (req, res, next) => {
try {
const attendeeData = AttendeeValidator.parse(req.body);
const attendee = new Database.ATTENDEES(attendeeData);
const attendee = new Database.ATTENDEE(attendeeData);
await attendee.save();

return res.status(StatusCodes.CREATED).json(attendeeData);
Expand Down Expand Up @@ -139,7 +139,7 @@ attendeeRouter.get(
const userId = payload.userId;

// Check if the user exists in the database
const user = await Database.ATTENDEES.findOne({ userId });
const user = await Database.ATTENDEE.findOne({ userId });

if (!user) {
return res
Expand All @@ -155,13 +155,16 @@ attendeeRouter.get(
);

// Get attendees based on a partial filter in body
attendeeRouter.post(
attendeeRouter.get(
"/filter",
RoleChecker([Role.Enum.ADMIN]),
RoleChecker([Role.Enum.STAFF, Role.Enum.CORPORATE]),
async (req, res, next) => {
try {
const attendeeData = PartialAttendeeFilter.parse(req.body);
const attendees = await Database.ATTENDEES.find(attendeeData);
const attendeeData = PartialAttendeeValidator.parse(req.body);
const attendees = await Database.ATTENDEE.find(
attendeeData,
"userId"
);

return res.status(StatusCodes.OK).json(attendees);
} catch (error) {
Expand Down
92 changes: 92 additions & 0 deletions src/services/attendee/attendee-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Schema } from "mongoose";
import { z } from "zod";

// Zod schema for attendee
export const AttendeeValidator = z.object({
userId: z.string(),
name: z.string(),
email: z.string().email(),
events: z.array(z.string()).default([]),
dietaryRestrictions: z.string().array(),
allergies: z.string().array(),
hasCheckedIn: z.boolean().default(false),
points: z.number().min(0).default(0),
foodWave: z.number().int().min(0).default(0),
hasPriority: z
.object({
Mon: z.boolean().default(false),
Tue: z.boolean().default(false),
Wed: z.boolean().default(false),
Thu: z.boolean().default(false),
Fri: z.boolean().default(false),
Sat: z.boolean().default(false),
Sun: z.boolean().default(false),
})
.default({
Mon: false,
Tue: false,
Wed: false,
Thu: false,
Fri: false,
Sat: false,
Sun: false,
}),
});

// Mongoose schema for attendee
export const AttendeeSchema = new Schema({
userId: { type: String, required: true, unique: true },
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
events: [{ type: String, ref: "Event", default: [] }],
dietaryRestrictions: { type: [String], required: true },
allergies: { type: [String], required: true },
hasCheckedIn: { type: Boolean, default: false },
points: { type: Number, default: 0 },
foodWave: { type: Number, default: 0 },
hasPriority: {
type: new Schema(
{
Mon: { type: Boolean, default: false },
Tue: { type: Boolean, default: false },
Wed: { type: Boolean, default: false },
Thu: { type: Boolean, default: false },
Fri: { type: Boolean, default: false },
Sat: { type: Boolean, default: false },
Sun: { type: Boolean, default: false },
},
{ _id: false }
),
default: {
Mon: false,
Tue: false,
Wed: false,
Thu: false,
Fri: false,
Sat: false,
Sun: false,
},
},
favorites: [{ type: String }],
});

export const AttendeeAttendanceSchema = new Schema({
userId: {
type: String,
ref: "Attendee",
required: true,
},
eventsAttended: [{ type: String, ref: "Event", required: true }],
});

export const AttendeeAttendanceValidator = z.object({
userId: z.string(),
eventsAttended: z.array(z.string()),
});

export const EventIdValidator = z.object({
eventId: z.string().uuid(),
});

// Partial schema for attendee filter
export const PartialAttendeeValidator = AttendeeValidator.partial();
File renamed without changes.
Loading

0 comments on commit 41bae16

Please sign in to comment.