Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

move api route & update schema

Isaacf012eaee3345
diff --git a/components/InputSelect/types.ts b/components/InputSelect/types.ts
index d9b2c547..d2bdb74e 100644
--- a/components/InputSelect/types.ts
+++ b/components/InputSelect/types.ts
@@ -5,13 +5,12 @@ export interface Option {
}
export interface ArchivalTagOption extends Option {
- archiveAsScreenshot: boolean | null;
- archiveAsMonolith: boolean | null;
- archiveAsPDF: boolean | null;
- archiveAsReadable: boolean | null;
- archiveAsWaybackMachine: boolean | null;
- aiTag: boolean | null;
- newTag: boolean | null;
+ archiveAsScreenshot?: boolean | null;
+ archiveAsMonolith?: boolean | null;
+ archiveAsPDF?: boolean | null;
+ archiveAsReadable?: boolean | null;
+ archiveAsWaybackMachine?: boolean | null;
+ aiTag?: boolean | null;
}
export type ArchivalOptionKeys = keyof Omit<
diff --git a/hooks/store/tags.tsx b/hooks/store/tags.tsx
index 424c7963..32d653ae 100644
--- a/hooks/store/tags.tsx
+++ b/hooks/store/tags.tsx
@@ -58,7 +58,7 @@ const useUpdateArchivalTags = () => {
return useMutation({
mutationFn: async (tags: ArchivalTagOption[]) => {
- const response = await fetch("/api/v1/tags/archival", {
+ const response = await fetch("/api/v1/tags", {
body: JSON.stringify({ tags }),
headers: {
"Content-Type": "application/json",
diff --git a/hooks/useArchivalTags.ts b/hooks/useArchivalTags.ts
index ade2ace4..62b98573 100644
--- a/hooks/useArchivalTags.ts
+++ b/hooks/useArchivalTags.ts
@@ -24,14 +24,12 @@ const useArchivalTags = (initialTags: Tag[]) => {
const transformTag = (tag: Tag): ArchivalTagOption => ({
label: tag.name,
- value: tag.id,
archiveAsScreenshot: tag.archiveAsScreenshot || false,
archiveAsMonolith: tag.archiveAsMonolith || false,
archiveAsPDF: tag.archiveAsPDF || false,
archiveAsReadable: tag.archiveAsReadable || false,
archiveAsWaybackMachine: tag.archiveAsWaybackMachine || false,
aiTag: tag.aiTag || false,
- newTag: false,
});
const archival = initialTags.filter(isArchivalTag).map(transformTag);
@@ -49,9 +47,8 @@ const useArchivalTags = (initialTags: Tag[]) => {
(newTag) =>
!archivalTags.some((existing) => existing.label === newTag.label)
)
- .map(({ __isNew__, ...tag }) => ({
+ .map(({ __isNew__, value, ...tag }) => ({
...tag,
- value: __isNew__ ? undefined : tag.value,
archiveAsScreenshot: __isNew__ ? false : tag.archiveAsScreenshot,
archiveAsMonolith: __isNew__ ? false : tag.archiveAsMonolith,
archiveAsPDF: __isNew__ ? false : tag.archiveAsPDF,
@@ -60,7 +57,6 @@ const useArchivalTags = (initialTags: Tag[]) => {
? false
: tag.archiveAsWaybackMachine,
aiTag: __isNew__ ? false : tag.aiTag,
- newTag: __isNew__ ? true : false,
}));
setArchivalTags((prev) => [...prev, ...uniqueNewTags]);
@@ -87,14 +83,14 @@ const useArchivalTags = (initialTags: Tag[]) => {
prev.map((t) =>
t.label === tagToDelete.label
? {
- ...t,
- archiveAsScreenshot: null,
- archiveAsMonolith: null,
- archiveAsPDF: null,
- archiveAsReadable: null,
- archiveAsWaybackMachine: null,
- aiTag: null,
- }
+ ...t,
+ archiveAsScreenshot: null,
+ archiveAsMonolith: null,
+ archiveAsPDF: null,
+ archiveAsReadable: null,
+ archiveAsWaybackMachine: null,
+ aiTag: null,
+ }
: t
)
);
@@ -119,29 +115,29 @@ const useArchivalTags = (initialTags: Tag[]) => {
icon: string;
label: string;
}[] = [
- { type: "aiTag", icon: "bi-tag", label: t("ai_tagging") },
- {
- type: "archiveAsScreenshot",
- icon: "bi-file-earmark-image",
- label: t("screenshot"),
- },
- {
- type: "archiveAsMonolith",
- icon: "bi-filetype-html",
- label: t("webpage"),
- },
- { type: "archiveAsPDF", icon: "bi-file-earmark-pdf", label: t("pdf") },
- {
- type: "archiveAsReadable",
- icon: "bi-file-earmark-text",
- label: t("readable"),
- },
- {
- type: "archiveAsWaybackMachine",
- icon: "bi-archive",
- label: t("archive_org_snapshot"),
- },
- ];
+ { type: "aiTag", icon: "bi-tag", label: t("ai_tagging") },
+ {
+ type: "archiveAsScreenshot",
+ icon: "bi-file-earmark-image",
+ label: t("screenshot"),
+ },
+ {
+ type: "archiveAsMonolith",
+ icon: "bi-filetype-html",
+ label: t("webpage"),
+ },
+ { type: "archiveAsPDF", icon: "bi-file-earmark-pdf", label: t("pdf") },
+ {
+ type: "archiveAsReadable",
+ icon: "bi-file-earmark-text",
+ label: t("readable"),
+ },
+ {
+ type: "archiveAsWaybackMachine",
+ icon: "bi-archive",
+ label: t("archive_org_snapshot"),
+ },
+ ];
return {
ARCHIVAL_OPTIONS,
diff --git a/lib/api/controllers/tags/createOrUpdateTags.ts b/lib/api/controllers/tags/createOrUpdateTags.ts
new file mode 100644
index 00000000..3d010450
--- /dev/null
+++ b/lib/api/controllers/tags/createOrUpdateTags.ts
@@ -0,0 +1,48 @@
+
+
+import { prisma } from "@/lib/api/db";
+import { PostTagSchemaType } from "@/lib/shared/schemaValidation";
+import { TagIncludingLinkCount } from "@/types/global";
+
+export default async function createOrUpdateTags(
+ userId: number,
+ tags: PostTagSchemaType["tags"]
+): Promise<TagIncludingLinkCount[]> {
+ const updatedTags: TagIncludingLinkCount[] = [];
+
+ for (const tag of tags) {
+ const updatedTag = await prisma.tag.upsert({
+ where: {
+ name_ownerId: {
+ name: tag.label,
+ ownerId: userId,
+ },
+ },
+ update: {
+ archiveAsScreenshot: tag.archiveAsScreenshot,
+ archiveAsMonolith: tag.archiveAsMonolith,
+ archiveAsPDF: tag.archiveAsPDF,
+ archiveAsReadable: tag.archiveAsReadable,
+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine,
+ aiTag: tag.aiTag,
+ },
+ create: {
+ name: tag.label,
+ ownerId: userId,
+ archiveAsScreenshot: tag.archiveAsScreenshot,
+ archiveAsMonolith: tag.archiveAsMonolith,
+ archiveAsPDF: tag.archiveAsPDF,
+ archiveAsReadable: tag.archiveAsReadable,
+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine,
+ aiTag: tag.aiTag,
+ },
+ include: {
+ _count: true,
+ },
+ });
+
+ updatedTags.push(updatedTag);
+ }
+
+ return updatedTags;
+}
diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.ts
index 68110792..b9b91ef4 100644
--- a/lib/shared/schemaValidation.ts
+++ b/lib/shared/schemaValidation.ts
@@ -41,12 +41,12 @@ export const PostUserSchema = () => {
username: emailEnabled
? z.string().optional()
: z
- .string()
- .trim()
- .toLowerCase()
- .min(3)
- .max(50)
- .regex(/^[a-z0-9_-]{3,50}$/),
+ .string()
+ .trim()
+ .toLowerCase()
+ .min(3)
+ .max(50)
+ .regex(/^[a-z0-9_-]{3,50}$/),
invite: z.boolean().optional(),
});
};
@@ -225,22 +225,22 @@ export const PostRssSubscriptionSchema = z.object({
collectionName: z.string().max(50).optional(),
});
-export const PostArchivalTagSchema = z.object({
+export const PostTagSchema = z.object({
tags: z.array(
z.object({
- value: z.number().optional(),
label: z.string(),
- newTag: z.boolean(),
- archiveAsScreenshot: z.boolean().nullable(),
- archiveAsMonolith: z.boolean().nullable(),
- archiveAsPDF: z.boolean().nullable(),
- archiveAsReadable: z.boolean().nullable(),
- archiveAsWaybackMachine: z.boolean().nullable(),
- aiTag: z.boolean().nullable(),
+ archiveAsScreenshot: z.boolean().nullish(),
+ archiveAsMonolith: z.boolean().nullish(),
+ archiveAsPDF: z.boolean().nullish(),
+ archiveAsReadable: z.boolean().nullish(),
+ archiveAsWaybackMachine: z.boolean().nullish(),
+ aiTag: z.boolean().nullish(),
})
),
});
+export type PostTagSchemaType = z.infer<typeof PostTagSchema>;
+
export const LinkArchiveActionSchema = z.object({
action: z.enum(["allAndRePreserve", "allAndIgnore", "allBroken"]),
});
diff --git a/pages/api/v1/archives/[linkId].ts b/pages/api/v1/archives/[linkId].ts
index 34b1e9e7..d558308f 100644
--- a/pages/api/v1/archives/[linkId].ts
+++ b/pages/api/v1/archives/[linkId].ts
@@ -158,7 +158,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
// Verify user and collection permissions
const user = await verifyUser({ req, res });
- if (!user) return; // verifyUser already handles the response on failure
+ if (!user) return res.status(401).json({ response: "Unauthorized" }); // verifyUser already handles the response on failure
const collectionPermissions = await getPermission({
userId: user.id,
diff --git a/pages/api/v1/collections/[id].ts b/pages/api/v1/collections/[id].ts
index 94090317..df95f737 100644
--- a/pages/api/v1/collections/[id].ts
+++ b/pages/api/v1/collections/[id].ts
@@ -9,7 +9,7 @@ export default async function collections(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
const collectionId = Number(req.query.id);
diff --git a/pages/api/v1/collections/index.ts b/pages/api/v1/collections/index.ts
index 3198ea5e..6631635a 100644
--- a/pages/api/v1/collections/index.ts
+++ b/pages/api/v1/collections/index.ts
@@ -8,7 +8,7 @@ export default async function collections(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const collections = await getCollections(user.id);
diff --git a/pages/api/v1/dashboard/index.ts b/pages/api/v1/dashboard/index.ts
index e4abcba5..0073b93c 100644
--- a/pages/api/v1/dashboard/index.ts
+++ b/pages/api/v1/dashboard/index.ts
@@ -8,7 +8,7 @@ export default async function dashboard(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const convertedData: LinkRequestQuery = {
diff --git a/pages/api/v1/links/[id]/archive/index.ts b/pages/api/v1/links/[id]/archive/index.ts
index 2b9589b4..9c1199fc 100644
--- a/pages/api/v1/links/[id]/archive/index.ts
+++ b/pages/api/v1/links/[id]/archive/index.ts
@@ -10,7 +10,7 @@ const RE_ARCHIVE_LIMIT = Number(process.env.RE_ARCHIVE_LIMIT) || 5;
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
const link = await prisma.link.findUnique({
where: {
@@ -48,15 +48,14 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
if (
link?.lastPreserved &&
getTimezoneDifferenceInMinutes(new Date(), link?.lastPreserved) <
- RE_ARCHIVE_LIMIT
+ RE_ARCHIVE_LIMIT
)
return res.status(400).json({
- response: `This link is currently being saved or has already been preserved. Please retry in ${
- RE_ARCHIVE_LIMIT -
+ response: `This link is currently being saved or has already been preserved. Please retry in ${RE_ARCHIVE_LIMIT -
Math.floor(
getTimezoneDifferenceInMinutes(new Date(), link?.lastPreserved)
)
- } minutes or create a new one.`,
+ } minutes or create a new one.`,
});
if (!link.url || !isValidUrl(link.url))
diff --git a/pages/api/v1/links/[id]/index.ts b/pages/api/v1/links/[id]/index.ts
index 7f33c662..4354e884 100644
--- a/pages/api/v1/links/[id]/index.ts
+++ b/pages/api/v1/links/[id]/index.ts
@@ -6,7 +6,7 @@ import verifyUser from "@/lib/api/verifyUser";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const updated = await getLinkById(user.id, Number(req.query.id));
diff --git a/pages/api/v1/links/archive/index.ts b/pages/api/v1/links/archive/index.ts
index 07ffe02c..c83b05d1 100644
--- a/pages/api/v1/links/archive/index.ts
+++ b/pages/api/v1/links/archive/index.ts
@@ -11,7 +11,7 @@ import { ArchivalSettings } from "@/lib/api/archiveHandler";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
const isServerAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
@@ -23,9 +23,8 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
const dataValidation = LinkArchiveActionSchema.safeParse(req.body);
if (!dataValidation.success) {
return res.status(400).json({
- response: `Error: ${
- dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
+ response: `Error: ${dataValidation.error.issues[0].message
+ } [${dataValidation.error.issues[0].path.join(", ")}]`,
});
}
@@ -101,24 +100,24 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
> =
archivalTags.length > 0
? {
- archiveAsScreenshot: archivalTags.some(
- (tag) => tag.archiveAsScreenshot
- ),
- archiveAsMonolith: archivalTags.some(
- (tag) => tag.archiveAsMonolith
- ),
- archiveAsPDF: archivalTags.some((tag) => tag.archiveAsPDF),
- archiveAsReadable: archivalTags.some(
- (tag) => tag.archiveAsReadable
- ),
- }
+ archiveAsScreenshot: archivalTags.some(
+ (tag) => tag.archiveAsScreenshot
+ ),
+ archiveAsMonolith: archivalTags.some(
+ (tag) => tag.archiveAsMonolith
+ ),
+ archiveAsPDF: archivalTags.some((tag) => tag.archiveAsPDF),
+ archiveAsReadable: archivalTags.some(
+ (tag) => tag.archiveAsReadable
+ ),
+ }
: {
- archiveAsScreenshot:
- link.createdBy?.archiveAsScreenshot || false,
- archiveAsMonolith: link.createdBy?.archiveAsMonolith || false,
- archiveAsPDF: link.createdBy?.archiveAsPDF || false,
- archiveAsReadable: link.createdBy?.archiveAsReadable || false,
- };
+ archiveAsScreenshot:
+ link.createdBy?.archiveAsScreenshot || false,
+ archiveAsMonolith: link.createdBy?.archiveAsMonolith || false,
+ archiveAsPDF: link.createdBy?.archiveAsPDF || false,
+ archiveAsReadable: link.createdBy?.archiveAsReadable || false,
+ };
const needsReprocessing =
(link.image === "unavailable" && shouldArchive.archiveAsScreenshot) ||
@@ -133,7 +132,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
data: {
image:
shouldArchive.archiveAsScreenshot &&
- link.image === "unavailable"
+ link.image === "unavailable"
? null
: link.image,
pdf:
@@ -142,12 +141,12 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
: link.pdf,
readable:
shouldArchive.archiveAsReadable &&
- link.readable === "unavailable"
+ link.readable === "unavailable"
? null
: link.readable,
monolith:
shouldArchive.archiveAsMonolith &&
- link.monolith === "unavailable"
+ link.monolith === "unavailable"
? null
: link.monolith,
},
diff --git a/pages/api/v1/links/index.ts b/pages/api/v1/links/index.ts
index dc7a2173..dd6eef38 100644
--- a/pages/api/v1/links/index.ts
+++ b/pages/api/v1/links/index.ts
@@ -8,7 +8,7 @@ import updateLinks from "@/lib/api/controllers/links/bulk/updateLinks";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
// Convert the type of the request query to "LinkRequestQuery"
diff --git a/pages/api/v1/migration/index.ts b/pages/api/v1/migration/index.ts
index d7c52ffb..09e022b6 100644
--- a/pages/api/v1/migration/index.ts
+++ b/pages/api/v1/migration/index.ts
@@ -19,7 +19,7 @@ export const config = {
export default async function users(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const data = await exportData(user.id);
diff --git a/pages/api/v1/rss/[id].ts b/pages/api/v1/rss/[id].ts
index 14de272c..b434424f 100644
--- a/pages/api/v1/rss/[id].ts
+++ b/pages/api/v1/rss/[id].ts
@@ -7,7 +7,7 @@ export default async function handler(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
const rssId = Number(req.query.id);
diff --git a/pages/api/v1/rss/index.ts b/pages/api/v1/rss/index.ts
index 1a4ea6fe..28610c35 100644
--- a/pages/api/v1/rss/index.ts
+++ b/pages/api/v1/rss/index.ts
@@ -9,7 +9,7 @@ export default async function handler(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const response = await prisma.rssSubscription.findMany({
@@ -33,9 +33,8 @@ export default async function handler(
if (!dataValidation.success) {
return res.status(400).json({
- response: `Error: ${
- dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
+ response: `Error: ${dataValidation.error.issues[0].message
+ } [${dataValidation.error.issues[0].path.join(", ")}]`,
});
}
diff --git a/pages/api/v1/tags/[id].ts b/pages/api/v1/tags/[id].ts
index 6aa8194d..91ae8d6b 100644
--- a/pages/api/v1/tags/[id].ts
+++ b/pages/api/v1/tags/[id].ts
@@ -5,7 +5,7 @@ import deleteTagById from "@/lib/api/controllers/tags/tagId/deleteTagById";
export default async function tags(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
const tagId = Number(req.query.id);
diff --git a/pages/api/v1/tags/archival/index.ts b/pages/api/v1/tags/archival/index.ts
deleted file mode 100644
index e46ddfd4..00000000
--- a/pages/api/v1/tags/archival/index.ts
+++ /dev/null
@@ -1,94 +0,0 @@
-import { prisma } from "@/lib/api/db";
-import verifyUser from "@/lib/api/verifyUser";
-import { PostArchivalTagSchema } from "@/lib/shared/schemaValidation";
-import { Tag } from "@prisma/client";
-import { NextApiRequest, NextApiResponse } from "next";
-
-export default async function archivalTags(
- req: NextApiRequest,
- res: NextApiResponse
-) {
- const user = await verifyUser({ req, res });
- if (!user) return;
-
- if (req.method === "POST") {
- const dataValidation = PostArchivalTagSchema.safeParse(req.body);
-
- if (!dataValidation.success) {
- return res.status(400).json({
- response: `Error: ${
- dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
- });
- }
-
- const { tags } = dataValidation.data;
- const updatedTags: Tag[] = [];
-
- for (const tag of tags) {
- if (tag.newTag) {
- const tagNameIsTaken = await prisma.tag.findFirst({
- where: {
- ownerId: user.id,
- name: tag.label,
- },
- });
-
- // If the tag name is already taken by the user, skip creating a new tag
- if (tagNameIsTaken) return;
-
- const newTag = await prisma.tag.create({
- data: {
- name: tag.label,
- ownerId: user.id,
- archiveAsScreenshot: tag.archiveAsScreenshot,
- archiveAsMonolith: tag.archiveAsMonolith,
- archiveAsPDF: tag.archiveAsPDF,
- archiveAsReadable: tag.archiveAsReadable,
- archiveAsWaybackMachine: tag.archiveAsWaybackMachine,
- aiTag: tag.aiTag,
- },
- include: {
- _count: true,
- },
- });
- updatedTags.push(newTag);
- } else {
- const targetTag = await prisma.tag.findUnique({
- where: {
- name_ownerId: {
- name: tag.label,
- ownerId: user.id,
- },
- },
- });
-
- // If the tag is not found or the ownerId does not match, skip updating
- if (targetTag && targetTag.ownerId !== user.id) return;
-
- const updatedTag = await prisma.tag.update({
- where: {
- name_ownerId: {
- name: tag.label,
- ownerId: user.id,
- },
- },
- data: {
- archiveAsScreenshot: tag.archiveAsScreenshot,
- archiveAsMonolith: tag.archiveAsMonolith,
- archiveAsPDF: tag.archiveAsPDF,
- archiveAsReadable: tag.archiveAsReadable,
- archiveAsWaybackMachine: tag.archiveAsWaybackMachine,
- aiTag: tag.aiTag,
- },
- include: {
- _count: true,
- },
- });
- updatedTags.push(updatedTag);
- }
- }
-
- return res.status(200).json({ response: updatedTags });
- }
-}
diff --git a/pages/api/v1/tags/index.ts b/pages/api/v1/tags/index.ts
index dd5382f7..95b1bb23 100644
--- a/pages/api/v1/tags/index.ts
+++ b/pages/api/v1/tags/index.ts
@@ -1,10 +1,12 @@
import type { NextApiRequest, NextApiResponse } from "next";
import getTags from "@/lib/api/controllers/tags/getTags";
import verifyUser from "@/lib/api/verifyUser";
+import { PostTagSchema } from "@/lib/shared/schemaValidation";
+import createOrUpdateTags from "@/lib/api/controllers/tags/createOrUpdateTags";
export default async function tags(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const tags = await getTags({
@@ -13,4 +15,21 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
return res.status(tags?.status || 500).json({ response: tags?.response });
}
+
+ if (req.method === "POST") {
+ const dataValidation = PostTagSchema.safeParse(req.body);
+
+ if (!dataValidation.success) {
+ return res.status(400).json({
+ response: `Error: ${dataValidation.error.issues[0].message
+ } [${dataValidation.error.issues[0].path.join(", ")}]`,
+ });
+ }
+
+ const { tags } = dataValidation.data;
+
+ const newOrUpdatedTags = await createOrUpdateTags(user.id, tags);
+
+ return res.status(200).json({ response: newOrUpdatedTags });
+ }
}
diff --git a/pages/api/v1/tokens/[id].ts b/pages/api/v1/tokens/[id].ts
index c4501fb8..7ecab61d 100644
--- a/pages/api/v1/tokens/[id].ts
+++ b/pages/api/v1/tokens/[id].ts
@@ -4,7 +4,7 @@ import deleteToken from "@/lib/api/controllers/tokens/tokenId/deleteTokenById";
export default async function token(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "DELETE") {
if (process.env.NEXT_PUBLIC_DEMO === "true")
diff --git a/pages/api/v1/tokens/index.ts b/pages/api/v1/tokens/index.ts
index e0f75ce8..a775d7d5 100644
--- a/pages/api/v1/tokens/index.ts
+++ b/pages/api/v1/tokens/index.ts
@@ -8,7 +8,7 @@ export default async function tokens(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "POST") {
if (process.env.NEXT_PUBLIC_DEMO === "true")
diff --git a/pages/api/v2/dashboard/index.ts b/pages/api/v2/dashboard/index.ts
index 0cd5cd29..3dee7d08 100644
--- a/pages/api/v2/dashboard/index.ts
+++ b/pages/api/v2/dashboard/index.ts
@@ -8,7 +8,7 @@ export default async function dashboard(
res: NextApiResponse
) {
const user = await verifyUser({ req, res });
- if (!user) return;
+ if (!user) return res.status(401).json({ response: "Unauthorized" });
if (req.method === "GET") {
const convertedData: LinkRequestQuery = {