Skip to content

Commit

Permalink
Merge pull request #5 from ReflectionsProjections/dev/riyap/events
Browse files Browse the repository at this point in the history
merging events i think
  • Loading branch information
riyap authored Apr 11, 2024
2 parents 0f2fed0 + e4072a8 commit 6cb1eae
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 24 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: Prettier on Push and PR

on:
push:
branches:
- 'main'
- 'dev**'
pull_request:
branches:
- 'main'

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install dependencies
run: yarn
- name: Run Prettier
run: npx prettier --write .
name: Prettier on Push and PR

on:
push:
branches:
- "main"
- "dev**"
pull_request:
branches:
- "main"

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
- name: Install dependencies
run: yarn
- name: Run Prettier
run: npx prettier --write .
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import bodyParser from "body-parser";
import errorHandler from "./middleware/error-handler";

import authRouter from "./services/auth/auth-router";
import eventRouter from "./services/events/events-router";
import subscriptionRouter from "./services/subscription/subscription-router";

const app = express();
Expand All @@ -23,6 +24,7 @@ app.use("/", bodyParser.json());

// API routes
app.use("/auth", authRouter);
app.use("/event", eventRouter);
app.use("/subscription", subscriptionRouter);

app.get("/status", (_, res) => {
Expand Down
2 changes: 2 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mongoose, { Schema } from "mongoose";
import { RoleInfo, RoleSchema } from "./services/auth/auth-schema";
import { EventSchema, EventValidator } from "./services/events/events-schema";
import {
SubscriptionValidator,
SubscriptionSchema,
Expand Down Expand Up @@ -36,6 +37,7 @@ function initializeModel(
// Example usage
export const Database = {
ROLES: initializeModel("roles", RoleSchema, RoleInfo),
EVENTS: initializeModel("events", EventSchema, EventValidator),
SUBSCRIPTION: initializeModel(
"subscription",
SubscriptionSchema,
Expand Down
19 changes: 19 additions & 0 deletions src/services/events/events-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Router } from "express";
import { StatusCodes } from "http-status-codes";
import { EventValidator } from "./events-schema";
import { Database } from "../../database";

const eventRouter = Router();

eventRouter.post("/", async (req, res, next) => {
try {
const validatedData = EventValidator.parse(req.body);
const event = new Database.EVENTS(validatedData);
await event.save();
return res.status(StatusCodes.CREATED).json(event.toObject());
} catch (error) {
next(error);
}
});

export default eventRouter;
35 changes: 35 additions & 0 deletions src/services/events/events-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Schema } from "mongoose";
import { z } from "zod";

export const EventValidator = z.object({
eventId: z.coerce.string(),
name: z.string(),
startTime: z.coerce.date(),
endTime: z.coerce.date(),
points: z.number().min(0),
});

export const EventSchema = new Schema({
eventId: {
type: String,
required: true,
unique: true,
},
name: {
type: String,
required: true,
},
startTime: {
type: Date,
required: true,
},
endTime: {
type: Date,
required: true,
},

points: {
type: Number,
required: true,
},
});

0 comments on commit 6cb1eae

Please sign in to comment.