Skip to content

Commit

Permalink
fix: types problem for discounts and categories on populate depth
Browse files Browse the repository at this point in the history
  • Loading branch information
HoreKk committed Jan 9, 2024
1 parent 88e3cd2 commit 1b984c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
16 changes: 8 additions & 8 deletions webapp/src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function Dashboard() {
{isLoadingCategories ? (
<Text>Loading...</Text>
) : (
categories?.map((category: Category) => (
categories?.map((category) => (
<Flex key={category.id} flexDir="column" textAlign="center">
<Flex
justifyContent="center"
Expand All @@ -55,8 +55,8 @@ export default function Dashboard() {
height="74px"
>
<Image
src={category.icon.url}
alt={category.icon.alt}
src={category.icon.url ?? ""}
alt={category.icon.alt ?? ""}
width={40}
height={40}
/>
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function Dashboard() {
{isLoadingDiscounts ? (
<Text>Loading...</Text>
) : (
discounts?.map((discount: Discount) => (
discounts?.map((discount) => (
<Flex key={discount.id} flexDir="column" minW="250px">
<Flex
flexDir="column"
Expand All @@ -108,8 +108,8 @@ export default function Dashboard() {
<Flex alignItems="center" gap={4}>
<Box bgColor="white" borderRadius={6} p={1}>
<Image
src={discount.partner.icon.url}
alt={discount.partner.icon.alt}
src={discount.partner.icon.url ?? ""}
alt={discount.partner.icon.alt ?? ""}
width={40}
height={40}
/>
Expand All @@ -130,8 +130,8 @@ export default function Dashboard() {
p={1}
>
<Image
src={discount.category.icon.url}
alt={discount.partner.icon.alt}
src={discount.category.icon.url ?? ""}
alt={discount.partner.icon.alt ?? ""}
width={20}
height={20}
/>
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/server/api/routers/category.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { TRPCError } from "@trpc/server";
import APIError from "payload/dist/errors/APIError";
import { z } from "zod";
import type { Category, Media } from "~/payload/payload-types";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

interface CategoryIncluded extends Category {
icon: Media;
}

export const categoryRouter = createTRPCRouter({
getList: publicProcedure.query(async ({ ctx }) => {
const categories = await ctx.payload.find({
Expand All @@ -11,6 +13,6 @@ export const categoryRouter = createTRPCRouter({
limit: 100,
});

return { data: categories.docs };
return { data: categories.docs as CategoryIncluded[] };
}),
});
11 changes: 7 additions & 4 deletions webapp/src/server/api/routers/discount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { TRPCError } from "@trpc/server";
import APIError from "payload/dist/errors/APIError";
import { z } from "zod";
import { Category, Discount, Media, Partner } from "~/payload/payload-types";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

interface DiscountIncluded extends Discount {
partner: Partner & { icon: Media };
category: Category & { icon: Media };
}

export const discountRouter = createTRPCRouter({
getList: publicProcedure.query(async ({ ctx }) => {
const discounts = await ctx.payload.find({
collection: "discounts",
limit: 100,
});

return { data: discounts.docs };
return { data: discounts.docs as DiscountIncluded[] };
}),
});

0 comments on commit 1b984c3

Please sign in to comment.