change routes and add todos
This commit is contained in:
parent
26997475fd
commit
da0533ac36
|
@ -13,6 +13,7 @@ type Props = {
|
|||
onClose: Function;
|
||||
};
|
||||
|
||||
// TODO: Make this work
|
||||
export default function EditLinkModal({ onClose }: Props) {
|
||||
const { updateLink, updateLinksById } = useLinkStore();
|
||||
const [submitLoader, setSubmitLoader] = useState(false);
|
||||
|
|
|
@ -3,6 +3,7 @@ import { prisma } from "@/lib/api/db";
|
|||
import getPermission from "@/lib/api/getPermission";
|
||||
import { UsersAndCollections } from "@prisma/client";
|
||||
|
||||
// Need to fix this
|
||||
export default async function updateLinksById(userId: number, linkIds: number[], data: LinkIncludingShortenedCollectionAndTags) {
|
||||
if (!linkIds || linkIds.length === 0) {
|
||||
return { response: "Please choose valid links.", status: 401 };
|
||||
|
|
|
@ -3,6 +3,8 @@ import getLinks from "@/lib/api/controllers/links/getLinks";
|
|||
import postLink from "@/lib/api/controllers/links/postLink";
|
||||
import { LinkRequestQuery } from "@/types/global";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
import deleteLinksById from "@/lib/api/controllers/links/bulk/deleteLinksById";
|
||||
import updateLinksById from "@/lib/api/controllers/links/bulk/updateLinksById";
|
||||
|
||||
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await verifyUser({ req, res });
|
||||
|
@ -39,5 +41,15 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
|||
return res.status(newlink.status).json({
|
||||
response: newlink.response,
|
||||
});
|
||||
} else if (req.method === "PUT") {
|
||||
const updated = await updateLinksById(user.id, req.body.linkIds, req.body.data);
|
||||
return res.status(updated.status).json({
|
||||
response: updated.response,
|
||||
});
|
||||
} else if (req.method === "DELETE") {
|
||||
const deleted = await deleteLinksById(user.id, req.body.linkIds);
|
||||
return res.status(deleted.status).json({
|
||||
response: deleted.response,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
|||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
updateLinksById: async (linkIds, data) => {
|
||||
const response = await fetch("/api/v1/links/bulk", {
|
||||
const response = await fetch("/api/v1/links", {
|
||||
body: JSON.stringify({ linkIds, data }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -172,7 +172,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
|||
return { ok: response.ok, data: data.response };
|
||||
},
|
||||
deleteLinksById: async (linkIds: number[]) => {
|
||||
const response = await fetch("/api/v1/links/bulk", {
|
||||
const response = await fetch("/api/v1/links", {
|
||||
body: JSON.stringify({ linkIds }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
Ŝarĝante…
Reference in New Issue