-
Notifications
You must be signed in to change notification settings - Fork 2
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
Delete item #52
base: main
Are you sure you want to change the base?
Delete item #52
Changes from 3 commits
203205d
27c6cfb
1a44e59
1f792f0
5bd172e
b44a940
587683e
286277e
c34d5f1
f1580a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import { z, ZodError } from "zod"; | ||
import { Items, List, Prisma, PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
/* The point of this endpoint is to delete an item to a list. | ||
First check the name given against the database. | ||
Since there are multiple ways to spell something we are trying to remove | ||
a couple of letters at a time and see if there is a match | ||
When shorter than 3 letters we just put it in the Other list | ||
*/ | ||
export default async function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse | ||
) { | ||
if (request.method === "PATCH") { | ||
try { | ||
const { id } = inputQueryTest.parse(request.body); | ||
|
||
const listToBe = await prisma.items.update({ | ||
where: { | ||
id: id, | ||
}, | ||
data: { | ||
ListID: null, | ||
}, | ||
}); | ||
response.status(201).send("Removed Items"); | ||
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. 200 is more fitting here 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. 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. thanks going to change it to 200. |
||
} catch (err) { | ||
if (err instanceof ZodError) { | ||
response.status(400).send(`Wrong Data Sent =>${JSON.stringify(err)}`); | ||
} else { | ||
response.status(418).send("Something is wrong"); | ||
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. so you're a teapot? 😄 |
||
} | ||
} | ||
response.status(404).send(`Invalid method, need PATCH: ${request.method}`); | ||
} | ||
} | ||
|
||
const inputQueryTest = z.object({ | ||
id: z.string(), | ||
}); |
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.
please use
disconnect: true
instead of nulling the reference to the foreign key here.
https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#disconnect
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.
working, thanks.