Skip to content

Commit

Permalink
fix id is expected to be a number
Browse files Browse the repository at this point in the history
  • Loading branch information
IhsenBouallegue committed Oct 29, 2023
1 parent bdbbfc7 commit 0254cbb
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/app/api/footerlinks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) {
const hubId = req.nextUrl.searchParams.get("hubId");
try {
let items;
if (hubId && !Number.isNaN(hubId)) {
if (hubId) {
items = await db.query.footerLinks.findMany({
where: eq(footerLinks.hubId, Number(hubId)),
where: eq(footerLinks.hubId, hubId),
});
} else {
items = await db.query.footerLinks.findMany();
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/hubs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) {
const hubId = req.nextUrl.searchParams.get("hubId");
try {
let items;
if (hubId && !Number.isNaN(hubId)) {
if (hubId) {
items = await db.query.hubs.findFirst({
where: eq(hubs.id, Number(hubId)),
where: eq(hubs.id, hubId),
});
}
return NextResponse.json(items);
Expand Down
18 changes: 2 additions & 16 deletions src/app/api/hubspaces/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ import { hubSpaces } from "@/lib/schema/app";
import { eq } from "drizzle-orm";
import { NextRequest, NextResponse } from "next/server";

// export async function GET(
// req: NextRequest,
// context: { params: { id: string } }
// ) {
// try {
// const item = await db.query.hubs.findFirst({
// where: eq(hubs.id, Number(context.params.id)),
// });
// return NextResponse.json(item);
// } catch (error) {
// return NextResponse.json({ error });
// }
// }

export async function PATCH(
req: NextRequest,
context: { params: { id: string } }
Expand All @@ -26,7 +12,7 @@ export async function PATCH(
const item = await db
.update(hubSpaces)
.set(body)
.where(eq(hubSpaces.id, Number(context.params.id)));
.where(eq(hubSpaces.id, context.params.id));
return NextResponse.json(item);
} catch (error) {
return NextResponse.json({ error });
Expand All @@ -40,7 +26,7 @@ export async function DELETE(
try {
const item = await db
.delete(hubSpaces)
.where(eq(hubSpaces.id, Number(context.params.id)));
.where(eq(hubSpaces.id, context.params.id));
return NextResponse.json(item);
} catch (error) {
return NextResponse.json({ error });
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/linkgroups/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) {
const hubId = req.nextUrl.searchParams.get("hubId");
try {
let items;
if (hubId && !Number.isNaN(hubId)) {
if (hubId) {
items = await db.query.linkGroups.findMany({
where: eq(linkGroups.hubId, Number(hubId)),
where: eq(linkGroups.hubId, hubId),
});
} else {
items = await db.query.linkGroups.findMany();
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/links/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) {
const hubId = req.nextUrl.searchParams.get("hubId");
try {
let items;
if (hubId && !Number.isNaN(hubId)) {
if (hubId) {
items = await db.query.links.findMany({
where: eq(links.hubId, Number(hubId)),
where: eq(links.hubId, hubId),
});
} else {
items = await db.query.links.findMany();
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/link-add-card/link-add-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function LinkAddCard({
hubId,
linkGroupId,
}: {
hubId: number;
hubId: string;
linkGroupId: number;
}) {
const [opened, setOpened] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IconPlus } from "@tabler/icons-react";
import { motion } from "framer-motion";
import { useState } from "react";

export function LinkGroupAddCard({ hubId }: { hubId: number }) {
export function LinkGroupAddCard({ hubId }: { hubId: string }) {
const [opened, setOpened] = useState(false);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { create } from "zustand";
type Settings = {
editMode: boolean;
compactMode: boolean;
hubId: number | null;
hubSpaceId: number | null;
hubId: string | null;
hubSpaceId: string | null;
createModalOpened: boolean;
};
type Actions = {
setEditMode: (editMode: boolean) => void;
setCompactMode: (compactMode: boolean) => void;
setHubId: (hubId: number) => void;
setHubId: (hubId: string) => void;
setCreateModalOpened: (createModalOpened: boolean) => void;
};
export const useHubOneStore = create<Settings & Actions>((set) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/lib/schema/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ export const links = mysqlTable("links", {
link: varchar("link", { length: 256 }).notNull(),
isInternal: boolean("is_internal").default(false).notNull(),
linkGroupId: int("link_group_id"),
hubId: int("hub_id").notNull(),
hubId: varchar("hub_id", { length: 128 }).notNull(),
});

export const footerLinks = mysqlTable("footer_links", {
id: serial("id").primaryKey().notNull(),
title: varchar("title", { length: 256 }).notNull(),
link: varchar("link", { length: 256 }).notNull(),
hubId: int("hub_id").notNull(),
hubId: varchar("hub_id", { length: 128 }).notNull(),
});

export const linkGroups = mysqlTable("link_groups", {
id: serial("id").primaryKey().notNull(),
title: varchar("title", { length: 256 }).notNull(),
hubId: int("hub_id").notNull(),
hubId: varchar("hub_id", { length: 128 }).notNull(),
});

export const hubsRelations = relations(hubs, ({ one, many }) => ({
Expand Down
10 changes: 6 additions & 4 deletions src/lib/useQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const API_URL = `${process.env.NEXT_PUBLIC_SERVER_BASE_URL || ""}/api/`;

async function simpleFetchByHubId<T>(
QUERY_NAME: string,
hubId: number
hubId: string
): Promise<T[]> {
const res = await fetch(`${API_URL}${QUERY_NAME}?hubId=${hubId}`, {
headers: {
Expand All @@ -24,7 +24,7 @@ async function simpleFetchByHubId<T>(

export function useFetchByHubId<T>(
QUERY_NAME: string,
hubId: number,
hubId: string,
config?: Partial<{
enabled: boolean;
onSuccess: (data: T[]) => void;
Expand All @@ -40,7 +40,7 @@ export function useFetchByHubId<T>(

export function useFetchItem<T>(
QUERY_NAME: string,
itemId: number,
itemId: number | string,
config?: Partial<{ onSuccess: (data: T) => void; initialData: T }>
) {
return useQuery<T>(
Expand Down Expand Up @@ -128,7 +128,9 @@ export function usePost<T>(QUERY_NAME: string) {
return mutate;
}

export function useUpdate<T extends { id: number }>(QUERY_NAME: string) {
export function useUpdate<T extends { id: string | number }>(
QUERY_NAME: string
) {
const queryClient = useQueryClient();
const { mutate } = useMutation(
(newItem: T) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function HubCreateModal({
description:
"Tired of keeping track of new websites? Tired of having to update your bookmarks every few weeks? Access all sites from this one page. Everything is up to date. No need to clutter your life anymore!",
hubSpaceId,
} as Hub,
} as unknown as Hub,
});

const mutate = usePost<Hub>("hubs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IconPlus } from "@tabler/icons-react";
import { motion } from "framer-motion";
import classes from "./footer-link-add-card.module.css";

export function FooterLinkAddCard({ hubId }: { hubId: number }) {
export function FooterLinkAddCard({ hubId }: { hubId: string }) {
const mutate = usePost<FooterLink>("footerlinks");
const handleSubmit = () => {
mutate({ hubId, title: "change me", link: "/" } as FooterLink);
Expand Down
2 changes: 1 addition & 1 deletion src/modals/hub-modals/hub-edit-modal/hub-edit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function HubEditModal({
hubId={footerLink.hubId}
/>
))}
<FooterLinkAddCard hubId={id as number} />
<FooterLinkAddCard hubId={id} />
</Stack>
</Tabs.Panel>
</Tabs>
Expand Down
4 changes: 2 additions & 2 deletions src/modals/link-group-modal/link-group-add-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function AddLinkGroupModal({
}: {
opened: boolean;
setOpened: (open: boolean) => void;
hubId: number;
hubId: string;
}) {
const form = useForm<LinkGroup>({
initialValues: {
title: "",
hubId,
} as LinkGroup,
} as unknown as LinkGroup,
});
const mutate = usePost<LinkGroup>("linkgroups");
const handleSubmit = (values: LinkGroup) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function LinkGroupGrid({
linkGroupId,
}: {
links: Link[];
hubId: number;
hubId: string;
linkGroupId: number;
}) {
const editMode = useHubOneStore((state) => state.editMode);
Expand Down

1 comment on commit 0254cbb

@vercel
Copy link

@vercel vercel bot commented on 0254cbb Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.