change routes and add todos

This commit is contained in:
Isaac Wise 2024-02-10 02:29:15 -06:00
parent 26997475fd
commit da0533ac36
4 changed files with 16 additions and 2 deletions

View File

@ -13,6 +13,7 @@ type Props = {
onClose: Function; onClose: Function;
}; };
// TODO: Make this work
export default function EditLinkModal({ onClose }: Props) { export default function EditLinkModal({ onClose }: Props) {
const { updateLink, updateLinksById } = useLinkStore(); const { updateLink, updateLinksById } = useLinkStore();
const [submitLoader, setSubmitLoader] = useState(false); const [submitLoader, setSubmitLoader] = useState(false);

View File

@ -3,6 +3,7 @@ import { prisma } from "@/lib/api/db";
import getPermission from "@/lib/api/getPermission"; import getPermission from "@/lib/api/getPermission";
import { UsersAndCollections } from "@prisma/client"; import { UsersAndCollections } from "@prisma/client";
// Need to fix this
export default async function updateLinksById(userId: number, linkIds: number[], data: LinkIncludingShortenedCollectionAndTags) { export default async function updateLinksById(userId: number, linkIds: number[], data: LinkIncludingShortenedCollectionAndTags) {
if (!linkIds || linkIds.length === 0) { if (!linkIds || linkIds.length === 0) {
return { response: "Please choose valid links.", status: 401 }; return { response: "Please choose valid links.", status: 401 };

View File

@ -3,6 +3,8 @@ import getLinks from "@/lib/api/controllers/links/getLinks";
import postLink from "@/lib/api/controllers/links/postLink"; import postLink from "@/lib/api/controllers/links/postLink";
import { LinkRequestQuery } from "@/types/global"; import { LinkRequestQuery } from "@/types/global";
import verifyUser from "@/lib/api/verifyUser"; 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) { export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res }); 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({ return res.status(newlink.status).json({
response: newlink.response, 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,
});
} }
} }

View File

@ -129,7 +129,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
return { ok: response.ok, data: data.response }; return { ok: response.ok, data: data.response };
}, },
updateLinksById: async (linkIds, data) => { updateLinksById: async (linkIds, data) => {
const response = await fetch("/api/v1/links/bulk", { const response = await fetch("/api/v1/links", {
body: JSON.stringify({ linkIds, data }), body: JSON.stringify({ linkIds, data }),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -172,7 +172,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
return { ok: response.ok, data: data.response }; return { ok: response.ok, data: data.response };
}, },
deleteLinksById: async (linkIds: number[]) => { deleteLinksById: async (linkIds: number[]) => {
const response = await fetch("/api/v1/links/bulk", { const response = await fetch("/api/v1/links", {
body: JSON.stringify({ linkIds }), body: JSON.stringify({ linkIds }),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",