Skip to content

Commit

Permalink
SAVE
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Nov 18, 2024
1 parent c7cf434 commit a8a14ac
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 100 deletions.
12 changes: 12 additions & 0 deletions apps/e2e/features/exchanges/studient_filters.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#language: fr
Fonctionnalité: Posez une question

Scénario: Poser une question sur le forum
Soit une base de données nourrie au grain
* je navigue sur la page
* je me connecte en tant que "[email protected]"
* je clique sur "Échanges"
* je vois dans le titre "Exchange :: Serkels"

Quand je clique sur "Mes cercles"
Alors je vois "P'tit pause café avec l'ami Jackie"
9 changes: 6 additions & 3 deletions apps/www/app/(main)/exchanges/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
///

import { AsideFilter } from ":components/shell/AsideFilter";
import { TrpcRootProvider } from ":trpc/root";
import { Exchanges_Filter } from ":widgets/exchanges/filter";
import { SearchForm } from ":widgets/exchanges/list";
import { Grid } from "@1.ui/react/grid";
Expand All @@ -27,10 +28,12 @@ export default async function Layout({

{categories}
</AsideFilter>
<div className="col-span-full md:col-span-6 md:my-10">{children}</div>
{/* <aside className="mt-10 hidden xl:col-span-3 xl:block xl:px-10">
<TrpcRootProvider>
<div className="col-span-full md:col-span-6 md:my-10">{children}</div>
</TrpcRootProvider>
<aside className="mt-10 hidden xl:col-span-3 xl:block xl:px-10">
{see_also}
</aside> */}
</aside>
</Grid>
);
}
15 changes: 9 additions & 6 deletions apps/www/app/(main)/exchanges/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//

import { TrpcRootProvider } from ":trpc/root";
import { TRPC_Hydrate } from ":trpc/server";
import { List } from ":widgets/exchanges/list";
import { trpc_server } from "@1.infra/trpc/react-query/server";
Expand Down Expand Up @@ -50,13 +51,15 @@ export default async function Page({
});

return (
<TRPC_Hydrate>
<main>
<NewExchangeSection />
<TrpcRootProvider>
<TRPC_Hydrate>
<main>
<NewExchangeSection />

<List key="list" />
</main>
</TRPC_Hydrate>
<List key="list" />
</main>
</TRPC_Hydrate>
</TrpcRootProvider>
);
}

Expand Down
6 changes: 4 additions & 2 deletions apps/www/app/(main)/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Notification_DotIndicator,
} from ":components/navbar/notification_indicator.client";
import { MobileNavBar } from ":components/shell/MobileNavBar";
import { TrpcRootProvider } from ":trpc/root";
import { TRPC_SSR } from ":trpc/server";
import { auth } from "@1.modules/auth.next";
import { PROFILE_ROLES, type AuthProfile } from "@1.modules/profile.domain";
Expand All @@ -32,8 +33,9 @@ export default function UserBar() {
</figure>

<MobileNavBar className="left-0 right-0 z-50 hidden h-16 sm:z-auto sm:col-auto sm:h-full md:col-span-4 md:block xl:col-span-6 sm:[&>ul]:w-full lg:[&>ul]:w-auto" />

<UserNavGroup className="h-full md:col-span-2 xl:col-span-3" />
<TrpcRootProvider>
<UserNavGroup className="h-full md:col-span-2 xl:col-span-3" />
</TrpcRootProvider>
</Grid>
</header>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/www/components/shell/RootProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { LegalProvider } from ":components/terms/context";
import { TrpcRootProvider } from ":trpc/root";
import { TrpcProvider } from ":trpc/client";
import { SessionProvider } from "@1.modules/auth.next/react";
import { useMediaQuery } from "@react-hookz/web";
import {
Expand All @@ -27,7 +27,7 @@ export function RootProviders({ children }: PropsWithChildren) {
<LegalProvider>
<AuthSessionProvider>
<ReactQueryClientProvider>
<TrpcRootProvider>{children}</TrpcRootProvider>
<TrpcProvider>{children}</TrpcProvider>
</ReactQueryClientProvider>
</AuthSessionProvider>
</LegalProvider>
Expand Down
4 changes: 2 additions & 2 deletions apps/www/widgets/exchanges/card/actions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//

import { TRPC_React } from ":trpc/client";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import { useSession } from "@1.modules/auth.next/react";
import { Exchange_TypeSchema, type Exchange } from "@1.modules/exchange.domain";
import { Exchange_Ask_Modal } from "@1.modules/exchange.ui/ask/modal";
Expand Down Expand Up @@ -32,7 +32,7 @@ export function Exchange_Actions() {

function Exchange_Action_Ask(exchange: Exchange) {
const { is_studient } = useExchangeMeta();
const query = TRPC_React.exchanges.me.deal_by_exchange_id.useQuery(
const query = trpc_client.exchanges.me.deal_by_exchange_id.useQuery(
exchange.id,
{ enabled: is_studient },
);
Expand Down
8 changes: 4 additions & 4 deletions apps/www/widgets/exchanges/card/bookmark.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//

import { AppToastOptions } from ":components/toast";
import { TRPC_React } from ":trpc/client";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import { useSession } from "@1.modules/auth.next/react";
import type { BookmarkButton_Props } from "@1.modules/bookmark.ui/BookmarkButton";
import { useExchange } from "@1.modules/exchange.ui/Card/context";
Expand All @@ -21,7 +21,7 @@ export function Exchange_Bookmark() {
const { data: session } = useSession();

const is_student = session?.profile.role === PROFILE_ROLES.Enum.STUDENT;
const query = TRPC_React.bookmarks.check.useQuery(
const query = trpc_client.bookmarks.check.useQuery(
{
target_id: exchange.id,
type: "exchange",
Expand Down Expand Up @@ -54,8 +54,8 @@ export function Exchange_Bookmark() {

function BookmarkItem_Toggle_Mutation(props: BookmarkButton_Props) {
const { className, target_id, type, variants } = props;
const toggle = TRPC_React.bookmarks.toggle.useMutation();
const utils = TRPC_React.useUtils();
const toggle = trpc_client.bookmarks.toggle.useMutation();
const utils = trpc_client.useUtils();
const { base, icon } = style({ ...variants });
return (
<button
Expand Down
8 changes: 4 additions & 4 deletions apps/www/widgets/exchanges/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { ReactMarkdown } from ":components/markdown";
import { AppToastOptions } from ":components/toast";
import { TRPC_React } from ":trpc/client";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import type { Exchange } from "@1.modules/exchange.domain";
import { Card } from "@1.modules/exchange.ui/Card/Card";
import { Card_Deleting } from "@1.modules/exchange.ui/Card/Card_Deleting";
Expand Down Expand Up @@ -72,11 +72,11 @@ function Card_Outlet({ children }: PropsWithChildren) {

function Deleting({ children }: PropsWithChildren) {
const { id: exchange_id } = useExchange();
const utils = TRPC_React.useUtils();
const delete_exchange = TRPC_React.exchanges.me.delete.useMutation();
const utils = trpc_client.useUtils();
const delete_exchange = trpc_client.exchanges.me.delete.useMutation();

useTimeoutEffect(async () => {
await delete_exchange.mutateAsync(exchange_id);
await delete_exchange.mutateAsync({ exchange_id });

await Promise.all([
utils.exchanges.by_id.invalidate(exchange_id),
Expand Down
6 changes: 1 addition & 5 deletions apps/www/widgets/exchanges/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,14 @@ function Item({ id }: Entity) {

//

function useQueryExchangeById(id: string) {
return trpc_client.exchanges.by_id.useQuery(id);
}

function Exchange_byId({
children,
id,
}: {
id: string;
children: (exchange: Exchange) => ReactNode;
}) {
const info = useQueryExchangeById(id);
const info = trpc_client.exchanges.by_id.useQuery(id);
return (
<Exchange_AsyncCard
info={info as ComponentProps<typeof Exchange_AsyncCard>["info"]}
Expand Down
4 changes: 2 additions & 2 deletions packages/@1/modules/auth/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { mergeRouters } from "@1.modules/trpc";
import signup_router from "./signup";
import verify_router from "./verify";
import { verify_api_router } from "./verify";

//

export default mergeRouters(signup_router, verify_router);
export default mergeRouters(signup_router, verify_api_router);
16 changes: 1 addition & 15 deletions packages/@1/modules/auth/api/src/verify/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
//

import { procedure, router } from "@1.modules/trpc";
import { z } from "zod";

//

export default router({
verify: procedure
.input(z.object({ email: z.string() }))
.mutation(async ({ ctx: { prisma }, input: { email } }) => {
return prisma.user.findUnique({
select: { id: true },
where: { email },
});
}),
});
export { default as verify_api_router } from "./verify";
2 changes: 1 addition & 1 deletion packages/@1/modules/auth/api/src/verify/verify.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { create_douglas_student } from "@1.infra/database/seeding";
import prisma, { empty_database, migrate } from "@1.infra/database/testing";
import { createCallerFactory } from "@1.modules/trpc";
import { beforeAll, expect, test } from "bun:test";
import verify_router from "./index";
import verify_router from "./verify";

//

Expand Down
17 changes: 17 additions & 0 deletions packages/@1/modules/auth/api/src/verify/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//

import { procedure, router } from "@1.modules/trpc";
import { z } from "zod";

//

export default router({
verify: procedure
.input(z.object({ email: z.string() }))
.mutation(async ({ ctx: { prisma }, input: { email } }) => {
return prisma.user.findUnique({
select: { id: true },
where: { email },
});
}),
});
1 change: 1 addition & 0 deletions packages/@1/modules/bookmark/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@1.config/typescript": "workspace:*",
"@1.infra/database": "workspace:*",
"@types/node": "22.8.1",
"typescript": "5.6.3"
}
Expand Down
66 changes: 66 additions & 0 deletions packages/@1/modules/bookmark/api/src/check/check.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//

import {
create_douglas_student,
create_film_category,
create_the_creator_exchange,
} from "@1.infra/database/seeding";
import prisma, { empty_database, migrate } from "@1.infra/database/testing";
import { createCallerFactory } from "@1.modules/trpc";
import { douglas_student_session } from "@1.modules/trpc/testing";
import { afterEach, beforeAll, beforeEach, expect, test } from "bun:test";
import api_router from "./check";

//

beforeAll(empty_database);
beforeAll(migrate);

//

test("return false when an exchange is not bookmarked", async () => {
const caller = createCallerFactory(api_router);
const trpc = caller({
auth: () => douglas_student_session,
prisma,
} as any);
const data = await trpc.check({
target_id: "the_creator_exchange_id",
type: "exchange",
});
expect(data).toBeFalse();
});

test("return true when an exchange is bookmarked", async () => {
const caller = createCallerFactory(api_router);
const trpc = caller({
auth: () => douglas_student_session,
prisma,
} as any);

await prisma.bookmark.create({
data: {
owner_id: "douglas_profile_id",
exchange_id: "the_creator_exchange_id",
},
});

const data = await trpc.check({
target_id: "the_creator_exchange_id",
type: "exchange",
});
expect(data).toBeTrue();
});

//

beforeEach(async function seed() {
await create_douglas_student(prisma);
await create_film_category(prisma);
await create_the_creator_exchange(prisma, "douglas_student_id");
});

afterEach(async function empty_delete_entries() {
await prisma.category.deleteMany();
await prisma.user.deleteMany();
});
32 changes: 32 additions & 0 deletions packages/@1/modules/bookmark/api/src/check/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//

import { Bookmark_Category } from "@1.modules/bookmark.domain";
import { router } from "@1.modules/trpc";
import { match } from "ts-pattern";
import { z } from "zod";
import { bookmark_type_procedure } from "../procedure";

//

export default router({
check: bookmark_type_procedure
.input(z.object({ target_id: z.string() }))
.query(async ({ ctx: { prisma, session }, input: { target_id, type } }) => {
const { id: owner_id } = session.profile;

const where = match(type)
.with(Bookmark_Category.Enum.exchange, () => ({
exchange_id: target_id,
}))
.with(Bookmark_Category.Enum.opportunity, () => ({
opportunity_id: target_id,
}))
.exhaustive();

const count = await prisma.bookmark.count({
where: { owner_id, ...where },
});

return count === 1;
}),
});
3 changes: 3 additions & 0 deletions packages/@1/modules/bookmark/api/src/check/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export { default as check_api_router } from "./check";
Loading

0 comments on commit a8a14ac

Please sign in to comment.