Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create endpoint for admins to edit an event #788

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion server/src/middleware/tests/AdminController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ describe("AdminController endpoint tests", () => {
start_date: dateToFirestoreTimeStamp(new Date()),
end_date: dateToFirestoreTimeStamp(new Date())
}
const eventService = new EventService()

it("should let admins create an event", async () => {
const res = await request
Expand All @@ -827,7 +828,18 @@ describe("AdminController endpoint tests", () => {
expect(res.status).toEqual(201)

// There should not be more than 1, even if we request more
expect((await new EventService().getAllEvents(69)).events).toHaveLength(1)
expect((await eventService.getAllEvents(69)).events).toHaveLength(1)
})
it("should let admins edit an event", async () => {
const newEvent = await eventService.createEvent(event1)
const res = await request
.patch("/admin/events/" + newEvent.id)
.set("Authorization", `Bearer ${adminToken}`)
.send({ title: "Cool event!", location: "UoA" } as Partial<Event>)
expect(res.status).toEqual(200)
const fetchedEvent = await eventService.getEventById(newEvent.id)
expect(fetchedEvent.title).toEqual("Cool event!")
expect(fetchedEvent.location).toEqual("UoA")
})
})
})
24 changes: 23 additions & 1 deletion server/src/service-layer/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
firestoreTimestampToDate,
timestampsInRange
} from "data-layer/adapters/DateUtils"
import { UserAdditionalInfo } from "data-layer/models/firebase"
import { UserAdditionalInfo, Event } from "data-layer/models/firebase"
import BookingDataService from "data-layer/services/BookingDataService"
import BookingSlotService from "data-layer/services/BookingSlotsService"
import UserDataService from "data-layer/services/UserDataService"
Expand Down Expand Up @@ -710,4 +710,26 @@ export class AdminController extends Controller {
this.setStatus(500)
}
}

/**
* Endpoint for admints to edit an event.
*/
@SuccessResponse("200", "Successfully edited the event!")
@Patch("events/{id}")
public async editEvent(
@Path() id: string,
@Body() requestBody: Partial<Event>
) {
const eventService = new EventService()
const fetchedEvent = await eventService.getEventById(id)
if (!fetchedEvent) {
this.setStatus(404)
}
try {
eventService.updateEvent(id, requestBody)
} catch (e) {
this.setStatus(500)
}
this.setStatus(200)
}
}
Loading