Skip to content

Commit

Permalink
Merge pull request #84 from UoaWDCC/Fix/CI-Pipeline
Browse files Browse the repository at this point in the history
MAKE CI PIPELINE GREAT AGAIN
  • Loading branch information
GBHU753 authored Aug 6, 2024
2 parents 93c1da6 + e5f1f8f commit 2eaeef0
Show file tree
Hide file tree
Showing 79 changed files with 3,198 additions and 7,634 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/full/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
},
"workspaceFolder": "/repo",
"postCreateCommand": "yarn install && yarn prepare",
"postCreateCommand": "yarn install:all && yarn prepare",
"postStartCommand": "",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generate-api-client.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Build API Client

on:
pull_request:
types: [opened, reopened, closed]
push

jobs:
build:
Expand All @@ -27,5 +26,6 @@ jobs:
commit_user_name: "github-api-actions[bot]"
commit_user_email: "github-api-actions[bot]@users.noreply.github.com"
commit_author: Author <[email protected]>
commit_options: '--no-verify'


22 changes: 22 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Continuous Integration

# This action works with pull requests and pushes
on:
push

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}

- name: Prettify code
uses: creyD/[email protected]
with:
# This part is also where you can pass other options, for example:
commit_message: "Chore: Prettify code"
2 changes: 1 addition & 1 deletion backend/api/paths/events/{eventId}.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function (eventsService) {
try {
const updatedEvent = await eventsService.updateEvent(
req.params.eventId,
req.body
req.body,
);
res.json(updatedEvent);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/api/paths/events/{eventId}/allTickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function (eventsService) {

async function GET(req, res, next) {
const allTickets = await eventsService.getAllEventTickets(
req.params.eventId
req.params.eventId,
);
if (!allTickets) {
res.status(204).json({ message: "No tickets in event" });
Expand Down
2 changes: 1 addition & 1 deletion backend/api/paths/events/{eventId}/paidTickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function (eventsService) {

async function GET(req, res, next) {
const paidTickets = await eventsService.getAllPaidEventTickets(
req.params.eventId
req.params.eventId,
);
if (!paidTickets) {
res.status(204).json({ message: "No paid tickets in event" });
Expand Down
2 changes: 1 addition & 1 deletion backend/api/paths/events/{eventId}/totalTicketNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function (eventsService) {

async function GET(req, res, next) {
const numberOfTickets = await eventsService.getNumberOfEventTickets(
req.params.eventId
req.params.eventId,
);
if (!numberOfTickets) {
res.status(204).json({ message: "No tickets in event" });
Expand Down
2 changes: 1 addition & 1 deletion backend/api/paths/events/{eventId}/unpaidTickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function (eventsService) {

async function GET(req, res, next) {
const unpaidTickets = await eventsService.getAllUnpaidEventTickets(
req.params.eventId
req.params.eventId,
);
if (!unpaidTickets) {
res.status(204).json({ message: "No unpaid tickets in event" });
Expand Down
9 changes: 5 additions & 4 deletions backend/api/paths/users.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export default function (usersService) {
let operations = {
GET, POST
GET,
POST,
};

async function GET(req, res, next) {
res.json(await usersService.getAllUsers());
}

async function POST(req, res, next) {
if (req.body.role === 'admin') {
if (req.body.role === "admin") {
res.status(401).json({ message: "Cannot create admin users." });
}
res.json(await usersService.createUser(req.body));
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function (usersService) {
message:
type: string
default: 'Cannot create admin users.'
`
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/allNames.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand All @@ -23,4 +23,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/totalNumber.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand All @@ -21,4 +21,4 @@ export default function (usersService) {
`;

return operations;
}
}
11 changes: 7 additions & 4 deletions backend/api/paths/users/{id}.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function (usersService) {
let operations = {
GET, PUT
GET,
PUT,
};

async function GET(req, res, next) {
Expand All @@ -14,7 +15,9 @@ export default function (usersService) {

async function PUT(req, res, next) {
if (req.body.role) {
res.status(401).json({ message: "Cannot update user role using this endpoint." });
res
.status(401)
.json({ message: "Cannot update user role using this endpoint." });
}
try {
const user = await usersService.updateUser(req.params.id, req.body);
Expand Down Expand Up @@ -117,7 +120,7 @@ export default function (usersService) {
message:
type: string
default: 'User not found.'
`
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/allEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/allTickets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/paidTickets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/pastEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/unpaidTickets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
4 changes: 2 additions & 2 deletions backend/api/paths/users/{id}/upcomingEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (usersService) {
let operations = {
GET
GET,
};

async function GET(req, res, next) {
Expand Down Expand Up @@ -28,4 +28,4 @@ export default function (usersService) {
`;

return operations;
}
}
12 changes: 6 additions & 6 deletions backend/api/services/usersService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient } from '@prisma/client';
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

Expand All @@ -22,7 +22,7 @@ const usersService = {
// GET /users/allNames
async getAllUserNames() {
const userNames = await this.getAllUsers();
return userNames.map(user => `${user.firstName} ${user.lastName}`);
return userNames.map((user) => `${user.firstName} ${user.lastName}`);
},

// GET /users/totalNumber
Expand Down Expand Up @@ -53,7 +53,7 @@ const usersService = {
// GET /users/{id}/allEvents
async getAllEventsByUserId(id) {
const userTickets = await this.getAllTicketsByUserId(id);
const eventIds = userTickets.map(ticket => ticket.eventId);
const eventIds = userTickets.map((ticket) => ticket.eventId);
const events = await prisma.event.findMany({
where: {
id: {
Expand All @@ -67,7 +67,7 @@ const usersService = {
// GET /users/{id}/upcomingEvents
async getUpcomingEventsByUserId(id) {
const userTickets = await this.getAllTicketsByUserId(id);
const eventIds = userTickets.map(ticket => ticket.eventId);
const eventIds = userTickets.map((ticket) => ticket.eventId);
const events = await prisma.event.findMany({
where: {
id: {
Expand All @@ -84,7 +84,7 @@ const usersService = {
// GET /users/{id}/pastEvents
async getPastEventsByUserId(id) {
const userTickets = await this.getAllTicketsByUserId(id);
const eventIds = userTickets.map(ticket => ticket.eventId);
const eventIds = userTickets.map((ticket) => ticket.eventId);
const events = await prisma.event.findMany({
where: {
id: {
Expand Down Expand Up @@ -131,4 +131,4 @@ const usersService = {
},
};

export default usersService;
export default usersService;
39 changes: 22 additions & 17 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import express from 'express';
import { initialize } from 'express-openapi';
import swaggerUi from 'swagger-ui-express';
import yamljs from 'yamljs';

import eventsService from './api/services/eventsService.js';
import usersService from './api/services/usersService.js';
import express from "express";
import { initialize } from "express-openapi";
import swaggerUi from "swagger-ui-express";
import yamljs from "yamljs";

import eventsService from "./api/services/eventsService.js";
import usersService from "./api/services/usersService.js";

// initialise openapi with express, serving api docs at '/api-docs-json' as json :(
const app = express();

// middleware
app.use(express.json());

const apiDoc = yamljs.load('./api/api-doc.yml');
const apiDoc = yamljs.load("./api/api-doc.yml");
initialize({
app,
apiDoc: apiDoc,
dependencies: {
eventsService: eventsService,
usersService: usersService
usersService: usersService,
},
paths: './api/paths',
docsPath: '/api-docs-json',
paths: "./api/paths",
docsPath: "/api-docs-json",
});

// convert from json and serve api docs with a pretty ui using swagger-ui :)
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(null, {
swaggerOptions: {
url: '/api-docs-json',
},
}));
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(null, {
swaggerOptions: {
url: "/api-docs-json",
},
}),
);

app.listen(3000, () => {
console.log('Server running, API docs available at http://localhost:3000/api-docs');
console.log(
"Server running, API docs available at http://localhost:3000/api-docs",
);
});
Loading

0 comments on commit 2eaeef0

Please sign in to comment.