generated from UoaWDCC/react-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 #18 from UoaWDCC/UADS-53-CMS
UADS-53/feat/CMS
- Loading branch information
Showing
36 changed files
with
2,342 additions
and
550 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,20 +1,38 @@ | ||
import { Request, Response } from "express"; | ||
import Event from "../models/Event"; | ||
import { Client } from "@notionhq/client"; | ||
import { EventRow, eventRowsStructured } from "../utils/BackendTypes"; | ||
import { config } from "dotenv"; | ||
config(); | ||
|
||
const notionSecret = process.env.NOTION_SECRET; | ||
const eventID = process.env.EVENT_DB_ID; | ||
|
||
const notion = new Client({ | ||
auth: notionSecret, | ||
}); | ||
|
||
const getEvents = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement GET endpoint"}); | ||
} | ||
if (!notionSecret || !eventID) { | ||
throw new Error("Missing creds"); | ||
} | ||
|
||
const query = await notion.databases.query({ | ||
database_id: eventID, | ||
}); | ||
|
||
// @ts-ignore | ||
const rows = query.results.map((res) => res.properties) as EventRow[]; | ||
|
||
const createEvent = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement POST endpoint"}); | ||
} | ||
const rowsStructured: eventRowsStructured = rows.map((row) => ({ | ||
name: row.Name.title[0].text.content, | ||
date: row.Date.date.start, | ||
description: row.Description.rich_text[0].text.content, | ||
image: row.Image.files[0].file.url, | ||
})); | ||
|
||
const deleteEvent = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement DELETE endpoint"}); | ||
} | ||
const orderedRowsStructured = rowsStructured.reverse(); | ||
|
||
const updateEvent = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement PATCH endpoint"}); | ||
} | ||
res.status(200).json(orderedRowsStructured); | ||
}; | ||
|
||
export {getEvents, createEvent, deleteEvent, updateEvent}; | ||
export { getEvents }; |
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,37 @@ | ||
import { Request, Response } from "express"; | ||
import { Client } from "@notionhq/client"; | ||
import { ExecRow, execRowsStructured } from "../utils/BackendTypes"; | ||
import { config } from "dotenv"; | ||
config(); | ||
|
||
const notionSecret = process.env.NOTION_SECRET; | ||
const execID = process.env.EXEC_DB_ID; | ||
|
||
const notion = new Client({ | ||
auth: notionSecret, | ||
}); | ||
|
||
const getExecs = async (req: Request, res: Response) => { | ||
if (!notionSecret || !execID) { | ||
throw new Error("Missing creds"); | ||
} | ||
|
||
const query = await notion.databases.query({ | ||
database_id: execID, | ||
}); | ||
|
||
// @ts-ignore | ||
const rows = query.results.map((res) => res.properties) as ExecRow[]; | ||
|
||
const rowsStructured: execRowsStructured = rows.map((row) => ({ | ||
name: row.Name.title[0].text.content, | ||
role: row.Role.rich_text[0].text.content, | ||
image: row.Image.files[0].file.url, | ||
})); | ||
|
||
const orderedRowsStructured = rowsStructured.reverse(); | ||
|
||
res.status(200).json(orderedRowsStructured); | ||
}; | ||
|
||
export { getExecs }; |
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,36 @@ | ||
import { Request, Response } from "express"; | ||
import { Client } from "@notionhq/client"; | ||
import { SocialRow, socialRowsStructured } from "../utils/BackendTypes"; | ||
import { config } from "dotenv"; | ||
config(); | ||
|
||
const notionSecret = process.env.NOTION_SECRET; | ||
const socialID = process.env.SOCIAL_DB_ID; | ||
|
||
const notion = new Client({ | ||
auth: notionSecret, | ||
}); | ||
|
||
const getSocials = async (req: Request, res: Response) => { | ||
if (!notionSecret || !socialID) { | ||
throw new Error("Missing creds"); | ||
} | ||
|
||
const query = await notion.databases.query({ | ||
database_id: socialID, | ||
}); | ||
|
||
// @ts-ignore | ||
const rows = query.results.map((res) => res.properties) as SocialRow[]; | ||
|
||
const rowsStructured: socialRowsStructured = rows.map((row) => ({ | ||
name: row.Name.title[0].text.content, | ||
link: row.Link.url, | ||
})); | ||
|
||
const orderedRowsStructured = rowsStructured.reverse(); | ||
|
||
res.status(200).json(orderedRowsStructured); | ||
}; | ||
|
||
export { getSocials }; |
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,37 @@ | ||
import { Request, Response } from "express"; | ||
import Sponsor from "../models/Sponsor"; | ||
import { Client } from "@notionhq/client"; | ||
import { SponsorRow, sponsorRowsStructured } from "../utils/BackendTypes"; | ||
import { config } from "dotenv"; | ||
config(); | ||
|
||
const notionSecret = process.env.NOTION_SECRET; | ||
const sponsorID = process.env.SPONSOR_DB_ID; | ||
|
||
const notion = new Client({ | ||
auth: notionSecret, | ||
}); | ||
|
||
const getSponsors = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement GET endpoint"}); | ||
} | ||
if (!notionSecret || !sponsorID) { | ||
throw new Error("Missing creds"); | ||
} | ||
|
||
const query = await notion.databases.query({ | ||
database_id: sponsorID, | ||
}); | ||
|
||
// @ts-ignore | ||
const rows = query.results.map((res) => res.properties) as SponsorRow[]; | ||
|
||
const createSponsor = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement POST endpoint"}); | ||
} | ||
const rowsStructured: sponsorRowsStructured = rows.map((row) => ({ | ||
name: row.Name.title[0].text.content, | ||
description: row.Description.rich_text[0].text.content, | ||
image: row.Image.files[0].file.url, | ||
})); | ||
|
||
const deleteSponsor = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement DELETE endpoint"}); | ||
} | ||
const orderedRowsStructured = rowsStructured.reverse(); | ||
|
||
const updateSponsor = async (req: Request, res: Response) => { | ||
res.json({msg: "Implement PATCH endpoint"}); | ||
} | ||
res.status(200).json(orderedRowsStructured); | ||
}; | ||
|
||
export {getSponsors, createSponsor, deleteSponsor, updateSponsor}; | ||
export { getSponsors }; |
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,25 +1,23 @@ | ||
import express, { json } from 'express'; | ||
import cors from 'cors'; | ||
import { connect } from 'mongoose'; | ||
import { config } from 'dotenv'; | ||
import express, { json } from "express"; | ||
import cors from "cors"; | ||
import router from "./routes/routes"; | ||
import { config } from "dotenv"; | ||
config(); | ||
|
||
// Import Routers | ||
import router from './routes/routes'; | ||
// Sets our port to the PORT .env value or 4000 by default if .env is not configured | ||
const PORT = process.env.PORT ?? 4000; | ||
|
||
// Creates the express server | ||
const app = express(); | ||
config(); | ||
|
||
// const databaseUrl: string = process.env.DATABASE_URL!; | ||
// connect(databaseUrl); | ||
|
||
// Express middleware | ||
app.use(json()); | ||
app.use(cors()); | ||
app.use(express.static('public')); | ||
app.use(express.static("public")); | ||
|
||
// Routes | ||
app.use('/', router); | ||
app.use("/", router); | ||
|
||
const port = Number.parseInt(process.env.PORT || '3000'); | ||
app.listen(port, () => { | ||
console.log(`Listening on port ${port}`); | ||
app.listen(PORT, () => { | ||
console.log(`Listening on port ${PORT}`); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 +1,9 @@ | ||
import { Router } from "express" | ||
import { getEvents, createEvent, deleteEvent, updateEvent } from "../controllers/EventController"; | ||
import { Router } from "express"; | ||
import { getEvents } from "../controllers/EventController"; | ||
|
||
const eventRoutes = Router(); | ||
|
||
// GET all users | ||
eventRoutes.get('/', getEvents); | ||
// Get all Events | ||
eventRoutes.get("/", getEvents); | ||
|
||
// CREATE new user | ||
eventRoutes.post('/', createEvent); | ||
|
||
// DELETE a user | ||
eventRoutes.delete('/:id', deleteEvent); | ||
|
||
// Update a user | ||
eventRoutes.patch('/:id', updateEvent); | ||
|
||
export default eventRoutes; | ||
export default eventRoutes; |
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 @@ | ||
import { Router } from "express"; | ||
import { getExecs } from "../controllers/ExecController"; | ||
|
||
const execRoutes = Router(); | ||
|
||
// Get all Execs | ||
execRoutes.get("/", getExecs); | ||
|
||
export default execRoutes; |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
import { Router } from "express"; | ||
import { getSocials } from "../controllers/SocialController"; | ||
|
||
const socialRoutes = Router(); | ||
|
||
// Get all Socials | ||
socialRoutes.get("/", getSocials); | ||
|
||
export default socialRoutes; |
Oops, something went wrong.