-
Notifications
You must be signed in to change notification settings - Fork 137
Tim Zoltie #140
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
Open
tzoltie
wants to merge
13
commits into
boolean-uk:main
Choose a base branch
from
tzoltie:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tim Zoltie #140
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6296f5b
get movies
tzoltie f7eaf92
post/movies
tzoltie e39e55f
get/movies, post/movies refactored to include screenings
tzoltie fb65582
get/movies/id
tzoltie 9ecc1ba
put/movies/id
tzoltie c820c60
put/customers
tzoltie 5d614ec
post/screens
tzoltie 8d2779a
get/movieswith runtime query params
tzoltie f35aa05
error catchers created, createTicket function started
tzoltie 90192d6
current work
tzoltie 0bc4e10
move and screens controllers refactored for error handlers
tzoltie 7dffc3c
tests for movie errors started
tzoltie 3328786
all tests for error status code created
tzoltie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,5 +1,5 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client") | ||
| const { createCustomerDb } = require('../domains/customer.js') | ||
| const { createCustomerDb, updateCustomer, getCustomerByID } = require('../domains/customer.js') | ||
|
|
||
| const createCustomer = async (req, res) => { | ||
| const { | ||
|
|
@@ -43,6 +43,42 @@ const createCustomer = async (req, res) => { | |
| } | ||
| } | ||
|
|
||
|
|
||
| const updateCustomerDetails = async (req, res) => { | ||
| const id = Number(req.params.id) | ||
| const { name, contact: {phone, email} = {} } = req.body | ||
| const foundCustomerId = await getCustomerByID(id) | ||
| if (!name) { | ||
| return res.status(400).json({ | ||
| error: "Customer name field missing" | ||
| }) | ||
| } | ||
| if (!foundCustomerId) { | ||
| return res.status(404).json({ | ||
| error: "Customer not found with that ID, choose another" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }) | ||
| } | ||
| try { | ||
| const updatedCustomer = await updateCustomer(id, name, phone, email) | ||
|
|
||
| res.status(201).json({ | ||
| customer: updatedCustomer | ||
| }) | ||
| } catch(e) { | ||
| if (e instanceof PrismaClientKnownRequestError) { | ||
| if(e.code === "P2001") { | ||
| return res.status(404).json({ | ||
| error: "Customer not found with that ID, choose another" | ||
| }) | ||
| } | ||
| } | ||
| res.status(500).json({ | ||
| error: e.message | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| createCustomer | ||
| createCustomer, | ||
| updateCustomerDetails | ||
| } | ||
This file contains hidden or 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,134 @@ | ||
| const { | ||
| getAllMovies, | ||
| createMovie, | ||
| updateMovie, | ||
| getAllMoviesByRuntimeLt, | ||
| getAllMoviesByRuntimeGt, | ||
| getMovieByTitle, | ||
| getMovieById | ||
| } = require('../domains/movie.js') | ||
|
|
||
| const { PrismaClientKnownRequestError } = require('@prisma/client/runtime/library') | ||
|
|
||
| const getAll = async (req, res) => { | ||
| const { runtimeLt,runtimeGt } = req.query | ||
| let allMovies | ||
|
|
||
| if(runtimeGt) { | ||
| allMovies = await getAllMoviesByRuntimeGt(Number(runtimeGt)) | ||
| } | ||
| if (runtimeLt) { | ||
| allMovies = await getAllMoviesByRuntimeLt(Number(runtimeLt)) | ||
| } | ||
| allMovies = await getAllMovies() | ||
|
|
||
| res.status(200).json({ | ||
| movies: allMovies | ||
| }) | ||
| } | ||
|
|
||
| const addMovie = async (req, res) => { | ||
| const { | ||
| title, | ||
| runtimeMins | ||
| } = req.body | ||
|
|
||
| const titleFound = await getMovieByTitle(title) | ||
|
|
||
| if (!title || !runtimeMins) { | ||
| return res.status(400).json({ | ||
| error: "Movie title or runtimeMins field missing" | ||
| }) | ||
| } | ||
| if (titleFound) { | ||
| return res.status(409).json({ | ||
| error: "Movie with that title already exists" | ||
| }) | ||
| } | ||
| try { | ||
| const newMovie = await createMovie(title, runtimeMins) | ||
|
|
||
| res.status(201).json({ | ||
| movie: newMovie | ||
| }) | ||
| } catch(e) { | ||
| if(e instanceof PrismaClientKnownRequestError) { | ||
| if(e.code === "P2002") { | ||
| return res.status(409).json({ | ||
| error: "Movie with that title already exists" | ||
| }) | ||
| } | ||
| res.status(500).json({ | ||
| error: e.message | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const findByID = async (req, res) => { | ||
| const id = Number(req.params.id) | ||
| const found = await getMovieById(id) | ||
| if (!found) { | ||
| return res.status(404).json({ | ||
| error: "Could not find movie with that ID" | ||
| }) | ||
| } else { | ||
| res.status(200).json({ | ||
| movie: found | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| const updateMovieByID = async (req, res) => { | ||
| const { | ||
| title, | ||
| runtimeMins | ||
| } = req.body | ||
| const id = Number(req.params.id) | ||
| const foundId = await getMovieById(id) | ||
| const foundTitle = await getMovieByTitle(title) | ||
| if (!title || !runtimeMins) { | ||
| return res.status(400).json({ | ||
| error: "Movie title or runtimeMins field missing" | ||
| }) | ||
| } | ||
| if (!foundId) { | ||
| return res.status(404).json({ | ||
| error: "Could not find movie with that ID" | ||
| }) | ||
| } | ||
| if (foundTitle) { | ||
| return res.status(409).json({ | ||
| error: "Movie with that title already exists" | ||
| }) | ||
| } | ||
| try { | ||
| const updatedMovie = await updateMovie(id, title, | ||
| runtimeMins) | ||
| res.status(201).json({ | ||
| movie: updatedMovie | ||
| }) | ||
| } catch(e) { | ||
| if (e instanceof PrismaClientKnownRequestError) { | ||
| if(e.code === "P2002") { | ||
| return res.status(409).json({ | ||
| error: "Movie with that title already exists" | ||
| }) | ||
| } else if (e.code === "P2001") { | ||
| return res.status(404).json({ | ||
| error: "Could not find movie with that ID" | ||
| }) | ||
| } | ||
| } | ||
| res.status(500).json({ | ||
| error: e.message | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| getAll, | ||
| addMovie, | ||
| findByID, | ||
| updateMovieByID | ||
| } |
This file contains hidden or 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 @@ | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client/runtime/library") | ||
| const { createScreen, findScreen } = require("../domains/screen") | ||
|
|
||
| const addScreen = async (req, res) => { | ||
| const { number } = req.body | ||
| const screenFound = await findScreen(number) | ||
| if (!number) { | ||
| return res.status(400).json({ | ||
| error: "Number field missing from screenings" | ||
| }) | ||
| } | ||
| if (screenFound) { | ||
| return res.status(409).json({ | ||
| error: "This screen already exists please select another screen" | ||
| }) | ||
| } | ||
| try { | ||
| const createdScreen = await createScreen(req) | ||
|
|
||
| res.status(201).json({ | ||
| screen: createdScreen | ||
| }) | ||
| } catch(e) { | ||
| if(e instanceof PrismaClientKnownRequestError) { | ||
| if(e.code === "P2002") { | ||
| return res.status(409).json({ | ||
| error: "This screen already exists please select another screen" | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| addScreen | ||
| } |
This file contains hidden or 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,45 @@ | ||
| const { error } = require("console") | ||
| const { getCustomerByID } = require("../domains/customer") | ||
| const { findScreeningById } = require("../domains/screen") | ||
| const { createTicket } = require("../../test/helpers/createTicket.js") | ||
| const { PrismaClientKnownRequestError } = require("@prisma/client/runtime/library") | ||
|
|
||
| const createTicketController = async (req, res) => { | ||
|
|
||
| const {screeningId, customerId} = req.body | ||
| const foundScreenId = await findScreeningById(screeningId) | ||
| const foundCustomerId = await getCustomerByID(customerId) | ||
|
|
||
| if (!screeningId || !customerId) { | ||
| return res.status(400).json({ | ||
| error: "Missing fields from the ticket" | ||
| }) | ||
| } | ||
| if (!foundScreenId || !foundCustomerId) { | ||
| return res.status(404).json({ | ||
| error: "The screen or customer does not exist, please select another ID" | ||
| }) | ||
| } | ||
| try { | ||
| const createdTicket = await createTicket(screeningId, customerId) | ||
| res.status(201).json({ | ||
| ticket: createdTicket | ||
| }) | ||
| } catch (e) { | ||
| if(e instanceof PrismaClientKnownRequestError) { | ||
| if(e.code === "P2001") { | ||
| return res.status(404).json({ | ||
| error: "The screen or customer does not exist, please select another ID" | ||
| }) | ||
| } | ||
| } | ||
| res.status(500).json({ | ||
| error: e.message | ||
| }) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| module.exports = { | ||
| createTicketController | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.