-
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 #5 from ReflectionsProjections/dev/riyap/events
merging events i think
- Loading branch information
Showing
5 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
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,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 . |
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 |
---|---|---|
@@ -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; |
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,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, | ||
}, | ||
}); |