fix: refactor teams router (#1500)
This commit is contained in:
@@ -47,7 +47,7 @@
|
|||||||
"recharts": "^2.7.2",
|
"recharts": "^2.7.2",
|
||||||
"sharp": "0.32.6",
|
"sharp": "0.32.6",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lingui/loader": "^4.11.3",
|
"@lingui/loader": "^4.11.3",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"ua-parser-js": "^1.0.37",
|
"ua-parser-js": "^1.0.37",
|
||||||
"uqr": "^0.1.2",
|
"uqr": "^0.1.2",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@documenso/tailwind-config": "*",
|
"@documenso/tailwind-config": "*",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { Trans } from '@lingui/macro';
|
|||||||
import { PlusIcon } from 'lucide-react';
|
import { PlusIcon } from 'lucide-react';
|
||||||
|
|
||||||
import LogoIcon from '@documenso/assets/logo_icon.png';
|
import LogoIcon from '@documenso/assets/logo_icon.png';
|
||||||
import type { GetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import type { User } from '@documenso/prisma/client';
|
import type { User } from '@documenso/prisma/client';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@@ -19,7 +19,7 @@ import { Logo } from '~/components/branding/logo';
|
|||||||
|
|
||||||
type ProfileHeaderProps = {
|
type ProfileHeaderProps = {
|
||||||
user?: User | null;
|
user?: User | null;
|
||||||
teams?: GetTeamsResponse;
|
teams?: TGetTeamsResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ProfileHeader = ({ user, teams = [] }: ProfileHeaderProps) => {
|
export const ProfileHeader = ({ user, teams = [] }: ProfileHeaderProps) => {
|
||||||
@@ -58,7 +58,7 @@ export const ProfileHeader = ({ user, teams = [] }: ProfileHeaderProps) => {
|
|||||||
alt="Documenso Logo"
|
alt="Documenso Logo"
|
||||||
width={48}
|
width={48}
|
||||||
height={48}
|
height={48}
|
||||||
className="h-10 w-auto dark:invert sm:hidden"
|
className="h-10 w-auto sm:hidden dark:invert"
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
|
|
||||||
import { setupI18nSSR } from '@documenso/lib/client-only/providers/i18n.server';
|
import { setupI18nSSR } from '@documenso/lib/client-only/providers/i18n.server';
|
||||||
import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
||||||
import type { GetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
||||||
|
|
||||||
import { Header as AuthenticatedHeader } from '~/components/(dashboard)/layout/header';
|
import { Header as AuthenticatedHeader } from '~/components/(dashboard)/layout/header';
|
||||||
@@ -23,7 +23,7 @@ export default async function RecipientLayout({ children }: RecipientLayoutProps
|
|||||||
|
|
||||||
const { user, session } = await getServerComponentSession();
|
const { user, session } = await getServerComponentSession();
|
||||||
|
|
||||||
let teams: GetTeamsResponse = [];
|
let teams: TGetTeamsResponse = [];
|
||||||
|
|
||||||
if (user && session) {
|
if (user && session) {
|
||||||
teams = await getTeams({ userId: user.id });
|
teams = await getTeams({ userId: user.id });
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
|
|
||||||
import { setupI18nSSR } from '@documenso/lib/client-only/providers/i18n.server';
|
import { setupI18nSSR } from '@documenso/lib/client-only/providers/i18n.server';
|
||||||
import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
||||||
import type { GetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
||||||
|
|
||||||
import { Header as AuthenticatedHeader } from '~/components/(dashboard)/layout/header';
|
import { Header as AuthenticatedHeader } from '~/components/(dashboard)/layout/header';
|
||||||
@@ -17,7 +17,7 @@ export default async function SigningLayout({ children }: SigningLayoutProps) {
|
|||||||
|
|
||||||
const { user, session } = await getServerComponentSession();
|
const { user, session } = await getServerComponentSession();
|
||||||
|
|
||||||
let teams: GetTeamsResponse = [];
|
let teams: TGetTeamsResponse = [];
|
||||||
|
|
||||||
if (user && session) {
|
if (user && session) {
|
||||||
teams = await getTeams({ userId: user.id });
|
teams = await getTeams({ userId: user.id });
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { usePathname } from 'next/navigation';
|
|||||||
|
|
||||||
import { MenuIcon, SearchIcon } from 'lucide-react';
|
import { MenuIcon, SearchIcon } from 'lucide-react';
|
||||||
|
|
||||||
import type { GetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import { getRootHref } from '@documenso/lib/utils/params';
|
import { getRootHref } from '@documenso/lib/utils/params';
|
||||||
import type { User } from '@documenso/prisma/client';
|
import type { User } from '@documenso/prisma/client';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
@@ -22,7 +22,7 @@ import { MobileNavigation } from './mobile-navigation';
|
|||||||
|
|
||||||
export type HeaderProps = HTMLAttributes<HTMLDivElement> & {
|
export type HeaderProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
user: User;
|
user: User;
|
||||||
teams: GetTeamsResponse;
|
teams: TGetTeamsResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Header = ({ className, user, teams, ...props }: HeaderProps) => {
|
export const Header = ({ className, user, teams, ...props }: HeaderProps) => {
|
||||||
@@ -75,7 +75,7 @@ export const Header = ({ className, user, teams, ...props }: HeaderProps) => {
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
className="flex gap-x-4 md:ml-8"
|
className="flex gap-x-4 md:ml-8"
|
||||||
title={selectedTeam ? selectedTeam.name : user.name ?? ''}
|
title={selectedTeam ? selectedTeam.name : (user.name ?? '')}
|
||||||
>
|
>
|
||||||
<MenuSwitcher user={user} teams={teams} />
|
<MenuSwitcher user={user} teams={teams} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { signOut } from 'next-auth/react';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { TEAM_MEMBER_ROLE_MAP, TEAM_URL_REGEX } from '@documenso/lib/constants/teams';
|
import { TEAM_MEMBER_ROLE_MAP, TEAM_URL_REGEX } from '@documenso/lib/constants/teams';
|
||||||
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
||||||
import type { GetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
import type { TGetTeamsResponse } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
||||||
import { canExecuteTeamAction } from '@documenso/lib/utils/teams';
|
import { canExecuteTeamAction } from '@documenso/lib/utils/teams';
|
||||||
import type { User } from '@documenso/prisma/client';
|
import type { User } from '@documenso/prisma/client';
|
||||||
@@ -36,7 +36,7 @@ const MotionLink = motion(Link);
|
|||||||
|
|
||||||
export type MenuSwitcherProps = {
|
export type MenuSwitcherProps = {
|
||||||
user: User;
|
user: User;
|
||||||
teams: GetTeamsResponse;
|
teams: TGetTeamsResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MenuSwitcher = ({ user, teams: initialTeamsData }: MenuSwitcherProps) => {
|
export const MenuSwitcher = ({ user, teams: initialTeamsData }: MenuSwitcherProps) => {
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
import { createContext, useContext } from 'react';
|
import { createContext, useContext } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import type { GetTeamResponse } from '@documenso/lib/server-only/team/get-team';
|
import type { TGetTeamByIdResponse } from '@documenso/lib/server-only/team/get-team';
|
||||||
|
|
||||||
interface TeamProviderProps {
|
interface TeamProviderProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
team: GetTeamResponse;
|
team: TGetTeamByIdResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TeamContext = createContext<GetTeamResponse | null>(null);
|
const TeamContext = createContext<TGetTeamByIdResponse | null>(null);
|
||||||
|
|
||||||
export const useCurrentTeam = () => {
|
export const useCurrentTeam = () => {
|
||||||
const context = useContext(TeamContext);
|
const context = useContext(TeamContext);
|
||||||
|
|||||||
70
package-lock.json
generated
70
package-lock.json
generated
@@ -113,7 +113,7 @@
|
|||||||
"recharts": "^2.7.2",
|
"recharts": "^2.7.2",
|
||||||
"sharp": "0.32.6",
|
"sharp": "0.32.6",
|
||||||
"typescript": "5.2.2",
|
"typescript": "5.2.2",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lingui/loader": "^4.11.3",
|
"@lingui/loader": "^4.11.3",
|
||||||
@@ -485,7 +485,7 @@
|
|||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"ua-parser-js": "^1.0.37",
|
"ua-parser-js": "^1.0.37",
|
||||||
"uqr": "^0.1.2",
|
"uqr": "^0.1.2",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@documenso/tailwind-config": "*",
|
"@documenso/tailwind-config": "*",
|
||||||
@@ -14253,6 +14253,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/code-block-writer": {
|
||||||
|
"version": "12.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz",
|
||||||
|
"integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/color": {
|
"node_modules/color": {
|
||||||
"version": "4.2.3",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
|
||||||
@@ -19936,6 +19942,14 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/inngest/node_modules/zod": {
|
||||||
|
"version": "3.22.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.22.5.tgz",
|
||||||
|
"integrity": "sha512-HqnGsCdVZ2xc0qWPLdO25WnseXThh0kEYKIdV5F/hTHO75hNZFp8thxSeHhiPrHZKrFTo1SOgkAj9po5bexZlw==",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/input-otp": {
|
"node_modules/input-otp": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/input-otp/-/input-otp-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/input-otp/-/input-otp-1.2.4.tgz",
|
||||||
@@ -35337,9 +35351,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/zod": {
|
"node_modules/zod": {
|
||||||
"version": "3.22.4",
|
"version": "3.23.8",
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz",
|
||||||
"integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==",
|
"integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==",
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
@@ -35352,6 +35366,36 @@
|
|||||||
"zod": "^3.20.2"
|
"zod": "^3.20.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/zod-prisma-types": {
|
||||||
|
"version": "3.1.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod-prisma-types/-/zod-prisma-types-3.1.8.tgz",
|
||||||
|
"integrity": "sha512-5oe0ays3ur4u2GtuUqlhgCraKBcsuMaMI8o7VMV4YAnFeOuVid7K2zGvjI19V0ue9PeNF2ICyVREQVohaQm5dw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@prisma/generator-helper": "^5.14.0",
|
||||||
|
"code-block-writer": "^12.0.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"zod": "^3.23.8"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"zod-prisma-types": "dist/bin.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zod-prisma-types/node_modules/@prisma/debug": {
|
||||||
|
"version": "5.22.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.22.0.tgz",
|
||||||
|
"integrity": "sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/zod-prisma-types/node_modules/@prisma/generator-helper": {
|
||||||
|
"version": "5.22.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@prisma/generator-helper/-/generator-helper-5.22.0.tgz",
|
||||||
|
"integrity": "sha512-LwqcBQ5/QsuAaLNQZAIVIAJDJBMjHwMwn16e06IYx/3Okj/xEEfw9IvrqB2cJCl3b2mCBlh3eVH0w9WGmi4aHg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@prisma/debug": "5.22.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/zwitch": {
|
"node_modules/zwitch": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
|
||||||
@@ -35376,7 +35420,7 @@
|
|||||||
"superjson": "^1.13.1",
|
"superjson": "^1.13.1",
|
||||||
"swagger-ui-react": "^5.11.0",
|
"swagger-ui-react": "^5.11.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/api/node_modules/@ts-rest/next": {
|
"packages/api/node_modules/@ts-rest/next": {
|
||||||
@@ -35441,7 +35485,7 @@
|
|||||||
"next-auth": "4.24.5",
|
"next-auth": "4.24.5",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/email": {
|
"packages/email": {
|
||||||
@@ -36650,7 +36694,7 @@
|
|||||||
"sharp": "0.32.6",
|
"sharp": "0.32.6",
|
||||||
"stripe": "^12.7.0",
|
"stripe": "^12.7.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/browser-chromium": "1.43.0",
|
"@playwright/browser-chromium": "1.43.0",
|
||||||
@@ -36721,7 +36765,8 @@
|
|||||||
"dotenv-cli": "^7.3.0",
|
"dotenv-cli": "^7.3.0",
|
||||||
"prisma-kysely": "^1.8.0",
|
"prisma-kysely": "^1.8.0",
|
||||||
"tsx": "^4.11.0",
|
"tsx": "^4.11.0",
|
||||||
"typescript": "5.2.2"
|
"typescript": "5.2.2",
|
||||||
|
"zod-prisma-types": "^3.1.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/prisma/node_modules/ts-pattern": {
|
"packages/prisma/node_modules/ts-pattern": {
|
||||||
@@ -36787,9 +36832,8 @@
|
|||||||
"luxon": "^3.4.0",
|
"luxon": "^3.4.0",
|
||||||
"superjson": "^1.13.1",
|
"superjson": "^1.13.1",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
}
|
||||||
"devDependencies": {}
|
|
||||||
},
|
},
|
||||||
"packages/trpc/node_modules/@ts-rest/next": {
|
"packages/trpc/node_modules/@ts-rest/next": {
|
||||||
"version": "3.30.5",
|
"version": "3.30.5",
|
||||||
@@ -36868,7 +36912,7 @@
|
|||||||
"tailwind-merge": "^1.12.0",
|
"tailwind-merge": "^1.12.0",
|
||||||
"tailwindcss-animate": "^1.0.5",
|
"tailwindcss-animate": "^1.0.5",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@documenso/tailwind-config": "*",
|
"@documenso/tailwind-config": "*",
|
||||||
|
|||||||
@@ -25,6 +25,6 @@
|
|||||||
"superjson": "^1.13.1",
|
"superjson": "^1.13.1",
|
||||||
"swagger-ui-react": "^5.11.0",
|
"swagger-ui-react": "^5.11.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,6 @@
|
|||||||
"next-auth": "4.24.5",
|
"next-auth": "4.24.5",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
"sharp": "0.32.6",
|
"sharp": "0.32.6",
|
||||||
"stripe": "^12.7.0",
|
"stripe": "^12.7.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/browser-chromium": "1.43.0",
|
"@playwright/browser-chromium": "1.43.0",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const createTeamEmailVerification = async ({
|
|||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
data,
|
data,
|
||||||
}: CreateTeamEmailVerificationOptions) => {
|
}: CreateTeamEmailVerificationOptions): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await prisma.$transaction(
|
await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const createTeamMemberInvites = async ({
|
|||||||
userName,
|
userName,
|
||||||
teamId,
|
teamId,
|
||||||
invitations,
|
invitations,
|
||||||
}: CreateTeamMemberInvitesOptions) => {
|
}: CreateTeamMemberInvitesOptions): Promise<void> => {
|
||||||
const team = await prisma.team.findFirstOrThrow({
|
const team = await prisma.team.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: teamId,
|
id: teamId,
|
||||||
|
|||||||
@@ -31,14 +31,17 @@ export type CreateTeamOptions = {
|
|||||||
teamUrl: string;
|
teamUrl: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CreateTeamResponse =
|
export const ZCreateTeamResponseSchema = z.union([
|
||||||
| {
|
z.object({
|
||||||
paymentRequired: false;
|
paymentRequired: z.literal(false),
|
||||||
}
|
}),
|
||||||
| {
|
z.object({
|
||||||
paymentRequired: true;
|
paymentRequired: z.literal(true),
|
||||||
pendingTeamId: number;
|
pendingTeamId: z.number(),
|
||||||
};
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export type TCreateTeamResponse = z.infer<typeof ZCreateTeamResponseSchema>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a team or pending team depending on the user's subscription or application's billing settings.
|
* Create a team or pending team depending on the user's subscription or application's billing settings.
|
||||||
@@ -47,7 +50,7 @@ export const createTeam = async ({
|
|||||||
userId,
|
userId,
|
||||||
teamName,
|
teamName,
|
||||||
teamUrl,
|
teamUrl,
|
||||||
}: CreateTeamOptions): Promise<CreateTeamResponse> => {
|
}: CreateTeamOptions): Promise<TCreateTeamResponse> => {
|
||||||
const user = await prisma.user.findUniqueOrThrow({
|
const user = await prisma.user.findUniqueOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id: userId,
|
id: userId,
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { P, match } from 'ts-pattern';
|
import { P, match } from 'ts-pattern';
|
||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { TeamMemberInvite } from '@documenso/prisma/client';
|
import type { TeamMemberInvite } from '@documenso/prisma/client';
|
||||||
import { Prisma } from '@documenso/prisma/client';
|
import { Prisma } from '@documenso/prisma/client';
|
||||||
|
import { TeamMemberInviteSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
|
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
|
||||||
import type { FindResultSet } from '../../types/find-result-set';
|
import { type FindResultSet, ZFindResultSet } from '../../types/find-result-set';
|
||||||
|
|
||||||
export interface FindTeamMemberInvitesOptions {
|
export interface FindTeamMemberInvitesOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
@@ -19,6 +21,18 @@ export interface FindTeamMemberInvitesOptions {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ZFindTeamMemberInvitesResponseSchema = ZFindResultSet.extend({
|
||||||
|
data: TeamMemberInviteSchema.pick({
|
||||||
|
id: true,
|
||||||
|
teamId: true,
|
||||||
|
email: true,
|
||||||
|
role: true,
|
||||||
|
createdAt: true,
|
||||||
|
}).array(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TFindTeamMemberInvitesResponse = z.infer<typeof ZFindTeamMemberInvitesResponseSchema>;
|
||||||
|
|
||||||
export const findTeamMemberInvites = async ({
|
export const findTeamMemberInvites = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
@@ -26,7 +40,7 @@ export const findTeamMemberInvites = async ({
|
|||||||
page = 1,
|
page = 1,
|
||||||
perPage = 10,
|
perPage = 10,
|
||||||
orderBy,
|
orderBy,
|
||||||
}: FindTeamMemberInvitesOptions) => {
|
}: FindTeamMemberInvitesOptions): Promise<TFindTeamMemberInvitesResponse> => {
|
||||||
const orderByColumn = orderBy?.column ?? 'email';
|
const orderByColumn = orderBy?.column ?? 'email';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { P, match } from 'ts-pattern';
|
import { P, match } from 'ts-pattern';
|
||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { TeamMember } from '@documenso/prisma/client';
|
import type { TeamMember } from '@documenso/prisma/client';
|
||||||
import { Prisma } from '@documenso/prisma/client';
|
import { Prisma } from '@documenso/prisma/client';
|
||||||
|
import { TeamMemberSchema, UserSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
import type { FindResultSet } from '../../types/find-result-set';
|
import { type FindResultSet, ZFindResultSet } from '../../types/find-result-set';
|
||||||
|
|
||||||
export interface FindTeamMembersOptions {
|
export interface FindTeamMembersOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
@@ -18,6 +20,17 @@ export interface FindTeamMembersOptions {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ZFindTeamMembersResponseSchema = ZFindResultSet.extend({
|
||||||
|
data: TeamMemberSchema.extend({
|
||||||
|
user: UserSchema.pick({
|
||||||
|
name: true,
|
||||||
|
email: true,
|
||||||
|
}),
|
||||||
|
}).array(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TFindTeamMembersResponse = z.infer<typeof ZFindTeamMembersResponseSchema>;
|
||||||
|
|
||||||
export const findTeamMembers = async ({
|
export const findTeamMembers = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
@@ -25,7 +38,7 @@ export const findTeamMembers = async ({
|
|||||||
page = 1,
|
page = 1,
|
||||||
perPage = 10,
|
perPage = 10,
|
||||||
orderBy,
|
orderBy,
|
||||||
}: FindTeamMembersOptions) => {
|
}: FindTeamMembersOptions): Promise<TFindTeamMembersResponse> => {
|
||||||
const orderByColumn = orderBy?.column ?? 'name';
|
const orderByColumn = orderBy?.column ?? 'name';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { Team } from '@documenso/prisma/client';
|
import type { Team } from '@documenso/prisma/client';
|
||||||
import { Prisma } from '@documenso/prisma/client';
|
import { Prisma } from '@documenso/prisma/client';
|
||||||
|
import { TeamPendingSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
|
import { type FindResultSet, ZFindResultSet } from '../../types/find-result-set';
|
||||||
|
|
||||||
export interface FindTeamsPendingOptions {
|
export interface FindTeamsPendingOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
@@ -13,13 +18,19 @@ export interface FindTeamsPendingOptions {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ZFindTeamsPendingResponseSchema = ZFindResultSet.extend({
|
||||||
|
data: TeamPendingSchema.array(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TFindTeamsPendingResponse = z.infer<typeof ZFindTeamsPendingResponseSchema>;
|
||||||
|
|
||||||
export const findTeamsPending = async ({
|
export const findTeamsPending = async ({
|
||||||
userId,
|
userId,
|
||||||
term,
|
term,
|
||||||
page = 1,
|
page = 1,
|
||||||
perPage = 10,
|
perPage = 10,
|
||||||
orderBy,
|
orderBy,
|
||||||
}: FindTeamsPendingOptions) => {
|
}: FindTeamsPendingOptions): Promise<TFindTeamsPendingResponse> => {
|
||||||
const orderByColumn = orderBy?.column ?? 'name';
|
const orderByColumn = orderBy?.column ?? 'name';
|
||||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||||
|
|
||||||
@@ -54,5 +65,5 @@ export const findTeamsPending = async ({
|
|||||||
currentPage: Math.max(page, 1),
|
currentPage: Math.max(page, 1),
|
||||||
perPage,
|
perPage,
|
||||||
totalPages: Math.ceil(count / perPage),
|
totalPages: Math.ceil(count / perPage),
|
||||||
};
|
} satisfies FindResultSet<typeof data>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,26 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { TeamMemberInviteSchema, TeamSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
export type GetTeamInvitationsOptions = {
|
export type GetTeamInvitationsOptions = {
|
||||||
email: string;
|
email: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTeamInvitations = async ({ email }: GetTeamInvitationsOptions) => {
|
export const ZGetTeamInvitationsResponseSchema = TeamMemberInviteSchema.extend({
|
||||||
|
team: TeamSchema.pick({
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
url: true,
|
||||||
|
avatarImageId: true,
|
||||||
|
}),
|
||||||
|
}).array();
|
||||||
|
|
||||||
|
export type TGetTeamInvitationsResponse = z.infer<typeof ZGetTeamInvitationsResponseSchema>;
|
||||||
|
|
||||||
|
export const getTeamInvitations = async ({
|
||||||
|
email,
|
||||||
|
}: GetTeamInvitationsOptions): Promise<TGetTeamInvitationsResponse> => {
|
||||||
return await prisma.teamMemberInvite.findMany({
|
return await prisma.teamMemberInvite.findMany({
|
||||||
where: {
|
where: {
|
||||||
email,
|
email,
|
||||||
|
|||||||
@@ -1,14 +1,30 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { TeamMemberSchema, UserSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
export type GetTeamMembersOptions = {
|
export type GetTeamMembersOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ZGetTeamMembersResponseSchema = TeamMemberSchema.extend({
|
||||||
|
user: UserSchema.pick({
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
email: true,
|
||||||
|
}),
|
||||||
|
}).array();
|
||||||
|
|
||||||
|
export type TGetTeamMembersResponseSchema = z.infer<typeof ZGetTeamMembersResponseSchema>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all team members for a given team.
|
* Get all team members for a given team.
|
||||||
*/
|
*/
|
||||||
export const getTeamMembers = async ({ userId, teamId }: GetTeamMembersOptions) => {
|
export const getTeamMembers = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
}: GetTeamMembersOptions): Promise<TGetTeamMembersResponseSchema> => {
|
||||||
return await prisma.teamMember.findMany({
|
return await prisma.teamMember.findMany({
|
||||||
where: {
|
where: {
|
||||||
team: {
|
team: {
|
||||||
|
|||||||
@@ -1,19 +1,38 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { Prisma } from '@documenso/prisma/client';
|
import type { Prisma } from '@documenso/prisma/client';
|
||||||
|
import {
|
||||||
|
TeamEmailSchema,
|
||||||
|
TeamGlobalSettingsSchema,
|
||||||
|
TeamSchema,
|
||||||
|
} from '@documenso/prisma/generated/zod';
|
||||||
|
import { TeamMemberSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
export type GetTeamByIdOptions = {
|
export type GetTeamByIdOptions = {
|
||||||
userId?: number;
|
userId?: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetTeamResponse = Awaited<ReturnType<typeof getTeamById>>;
|
export const ZGetTeamByIdResponseSchema = TeamSchema.extend({
|
||||||
|
teamEmail: TeamEmailSchema.nullable(),
|
||||||
|
teamGlobalSettings: TeamGlobalSettingsSchema.nullable(),
|
||||||
|
currentTeamMember: TeamMemberSchema.pick({
|
||||||
|
role: true,
|
||||||
|
}).nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetTeamByIdResponse = z.infer<typeof ZGetTeamByIdResponseSchema>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a team given a teamId.
|
* Get a team given a teamId.
|
||||||
*
|
*
|
||||||
* Provide an optional userId to check that the user is a member of the team.
|
* Provide an optional userId to check that the user is a member of the team.
|
||||||
*/
|
*/
|
||||||
export const getTeamById = async ({ userId, teamId }: GetTeamByIdOptions) => {
|
export const getTeamById = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
}: GetTeamByIdOptions): Promise<TGetTeamByIdResponse> => {
|
||||||
const whereFilter: Prisma.TeamWhereUniqueInput = {
|
const whereFilter: Prisma.TeamWhereUniqueInput = {
|
||||||
id: teamId,
|
id: teamId,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { TeamMemberSchema, TeamSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
export type GetTeamsOptions = {
|
export type GetTeamsOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
};
|
};
|
||||||
export type GetTeamsResponse = Awaited<ReturnType<typeof getTeams>>;
|
|
||||||
|
|
||||||
export const getTeams = async ({ userId }: GetTeamsOptions) => {
|
export const ZGetTeamsResponseSchema = TeamSchema.extend({
|
||||||
|
currentTeamMember: TeamMemberSchema.pick({
|
||||||
|
role: true,
|
||||||
|
}),
|
||||||
|
}).array();
|
||||||
|
|
||||||
|
export type TGetTeamsResponse = z.infer<typeof ZGetTeamsResponseSchema>;
|
||||||
|
|
||||||
|
export const getTeams = async ({ userId }: GetTeamsOptions): Promise<TGetTeamsResponse> => {
|
||||||
const teams = await prisma.team.findMany({
|
const teams = await prisma.team.findMany({
|
||||||
where: {
|
where: {
|
||||||
members: {
|
members: {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export type LeaveTeamOptions = {
|
|||||||
teamId: number;
|
teamId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const leaveTeam = async ({ userId, teamId }: LeaveTeamOptions) => {
|
export const leaveTeam = async ({ userId, teamId }: LeaveTeamOptions): Promise<void> => {
|
||||||
await prisma.$transaction(
|
await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const team = await tx.team.findFirstOrThrow({
|
const team = await tx.team.findFirstOrThrow({
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const requestTeamOwnershipTransfer = async ({
|
|||||||
userName,
|
userName,
|
||||||
teamId,
|
teamId,
|
||||||
newOwnerUserId,
|
newOwnerUserId,
|
||||||
}: RequestTeamOwnershipTransferOptions) => {
|
}: RequestTeamOwnershipTransferOptions): Promise<void> => {
|
||||||
// Todo: Clear payment methods disabled for now.
|
// Todo: Clear payment methods disabled for now.
|
||||||
const clearPaymentMethods = false;
|
const clearPaymentMethods = false;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export type ResendTeamMemberInvitationOptions = {
|
|||||||
export const resendTeamEmailVerification = async ({
|
export const resendTeamEmailVerification = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
}: ResendTeamMemberInvitationOptions) => {
|
}: ResendTeamMemberInvitationOptions): Promise<void> => {
|
||||||
await prisma.$transaction(
|
await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const team = await tx.team.findUniqueOrThrow({
|
const team = await tx.team.findUniqueOrThrow({
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const resendTeamMemberInvitation = async ({
|
|||||||
userName,
|
userName,
|
||||||
teamId,
|
teamId,
|
||||||
invitationId,
|
invitationId,
|
||||||
}: ResendTeamMemberInvitationOptions) => {
|
}: ResendTeamMemberInvitationOptions): Promise<void> => {
|
||||||
await prisma.$transaction(
|
await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const team = await tx.team.findUniqueOrThrow({
|
const team = await tx.team.findUniqueOrThrow({
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { TeamMemberRole } from '@documenso/prisma/client';
|
import { TeamMemberRole } from '@documenso/prisma/client';
|
||||||
|
import { TeamGlobalSettingsSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
export type UpdateTeamBrandingSettingsOptions = {
|
export type UpdateTeamBrandingSettingsOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
@@ -13,11 +16,17 @@ export type UpdateTeamBrandingSettingsOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ZUpdateTeamBrandingSettingsResponseSchema = TeamGlobalSettingsSchema;
|
||||||
|
|
||||||
|
export type TUpdateTeamBrandingSettingsResponse = z.infer<
|
||||||
|
typeof ZUpdateTeamBrandingSettingsResponseSchema
|
||||||
|
>;
|
||||||
|
|
||||||
export const updateTeamBrandingSettings = async ({
|
export const updateTeamBrandingSettings = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
settings,
|
settings,
|
||||||
}: UpdateTeamBrandingSettingsOptions) => {
|
}: UpdateTeamBrandingSettingsOptions): Promise<TUpdateTeamBrandingSettingsResponse> => {
|
||||||
const { brandingEnabled, brandingLogo, brandingUrl, brandingCompanyDetails } = settings;
|
const { brandingEnabled, brandingLogo, brandingUrl, brandingCompanyDetails } = settings;
|
||||||
|
|
||||||
const member = await prisma.teamMember.findFirst({
|
const member = await prisma.teamMember.findFirst({
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { DocumentVisibility } from '@documenso/prisma/client';
|
import type { DocumentVisibility } from '@documenso/prisma/client';
|
||||||
import { TeamMemberRole } from '@documenso/prisma/client';
|
import { TeamMemberRole } from '@documenso/prisma/client';
|
||||||
|
import { TeamGlobalSettingsSchema } from '@documenso/prisma/generated/zod';
|
||||||
|
|
||||||
import type { SupportedLanguageCodes } from '../../constants/i18n';
|
import type { SupportedLanguageCodes } from '../../constants/i18n';
|
||||||
|
|
||||||
@@ -17,11 +20,17 @@ export type UpdateTeamDocumentSettingsOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ZUpdateTeamDocumentSettingsResponseSchema = TeamGlobalSettingsSchema;
|
||||||
|
|
||||||
|
export type TUpdateTeamDocumentSettingsResponse = z.infer<
|
||||||
|
typeof ZUpdateTeamDocumentSettingsResponseSchema
|
||||||
|
>;
|
||||||
|
|
||||||
export const updateTeamDocumentSettings = async ({
|
export const updateTeamDocumentSettings = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
settings,
|
settings,
|
||||||
}: UpdateTeamDocumentSettingsOptions) => {
|
}: UpdateTeamDocumentSettingsOptions): Promise<TUpdateTeamDocumentSettingsResponse> => {
|
||||||
const {
|
const {
|
||||||
documentVisibility,
|
documentVisibility,
|
||||||
documentLanguage,
|
documentLanguage,
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ export type UpdateTeamEmailOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateTeamEmail = async ({ userId, teamId, data }: UpdateTeamEmailOptions) => {
|
export const updateTeamEmail = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
data,
|
||||||
|
}: UpdateTeamEmailOptions): Promise<void> => {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
await tx.team.findFirstOrThrow({
|
await tx.team.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const updateTeamMember = async ({
|
|||||||
teamId,
|
teamId,
|
||||||
teamMemberId,
|
teamMemberId,
|
||||||
data,
|
data,
|
||||||
}: UpdateTeamMemberOptions) => {
|
}: UpdateTeamMemberOptions): Promise<void> => {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
// Find the team and validate that the user is allowed to update members.
|
// Find the team and validate that the user is allowed to update members.
|
||||||
const team = await tx.team.findFirstOrThrow({
|
const team = await tx.team.findFirstOrThrow({
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export type UpdateTeamOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateTeam = async ({ userId, teamId, data }: UpdateTeamOptions) => {
|
export const updateTeam = async ({ userId, teamId, data }: UpdateTeamOptions): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
const foundPendingTeamWithUrl = await tx.teamPending.findFirst({
|
const foundPendingTeamWithUrl = await tx.teamPending.findFirst({
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const ZFindResultSet = z.object({
|
||||||
|
data: z.union([z.array(z.unknown()), z.unknown()]),
|
||||||
|
count: z.number(),
|
||||||
|
currentPage: z.number(),
|
||||||
|
perPage: z.number(),
|
||||||
|
totalPages: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Can't infer generics from Zod.
|
||||||
export type FindResultSet<T> = {
|
export type FindResultSet<T> = {
|
||||||
data: T extends Array<unknown> ? T : T[];
|
data: T extends Array<unknown> ? T : T[];
|
||||||
count: number;
|
count: number;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"dotenv-cli": "^7.3.0",
|
"dotenv-cli": "^7.3.0",
|
||||||
"prisma-kysely": "^1.8.0",
|
"prisma-kysely": "^1.8.0",
|
||||||
"tsx": "^4.11.0",
|
"tsx": "^4.11.0",
|
||||||
"typescript": "5.2.2"
|
"typescript": "5.2.2",
|
||||||
|
"zod-prisma-types": "^3.1.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ generator client {
|
|||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generator zod {
|
||||||
|
provider = "zod-prisma-types"
|
||||||
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("NEXT_PRIVATE_DATABASE_URL")
|
url = env("NEXT_PRIVATE_DATABASE_URL")
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
"luxon": "^3.4.0",
|
"luxon": "^3.4.0",
|
||||||
"superjson": "^1.13.1",
|
"superjson": "^1.13.1",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
},
|
}
|
||||||
"devDependencies": {}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { TRPCError } from '@trpc/server';
|
import { TRPCError } from '@trpc/server';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { getTeamPrices } from '@documenso/ee/server-only/stripe/get-team-prices';
|
import { getTeamPrices } from '@documenso/ee/server-only/stripe/get-team-prices';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { acceptTeamInvitation } from '@documenso/lib/server-only/team/accept-team-invitation';
|
import { acceptTeamInvitation } from '@documenso/lib/server-only/team/accept-team-invitation';
|
||||||
import { createTeam } from '@documenso/lib/server-only/team/create-team';
|
import { ZCreateTeamResponseSchema, createTeam } from '@documenso/lib/server-only/team/create-team';
|
||||||
import { createTeamBillingPortal } from '@documenso/lib/server-only/team/create-team-billing-portal';
|
import { createTeamBillingPortal } from '@documenso/lib/server-only/team/create-team-billing-portal';
|
||||||
import { createTeamPendingCheckoutSession } from '@documenso/lib/server-only/team/create-team-checkout-session';
|
import { createTeamPendingCheckoutSession } from '@documenso/lib/server-only/team/create-team-checkout-session';
|
||||||
import { createTeamEmailVerification } from '@documenso/lib/server-only/team/create-team-email-verification';
|
import { createTeamEmailVerification } from '@documenso/lib/server-only/team/create-team-email-verification';
|
||||||
@@ -17,22 +18,43 @@ import { deleteTeamMembers } from '@documenso/lib/server-only/team/delete-team-m
|
|||||||
import { deleteTeamPending } from '@documenso/lib/server-only/team/delete-team-pending';
|
import { deleteTeamPending } from '@documenso/lib/server-only/team/delete-team-pending';
|
||||||
import { deleteTeamTransferRequest } from '@documenso/lib/server-only/team/delete-team-transfer-request';
|
import { deleteTeamTransferRequest } from '@documenso/lib/server-only/team/delete-team-transfer-request';
|
||||||
import { findTeamInvoices } from '@documenso/lib/server-only/team/find-team-invoices';
|
import { findTeamInvoices } from '@documenso/lib/server-only/team/find-team-invoices';
|
||||||
import { findTeamMemberInvites } from '@documenso/lib/server-only/team/find-team-member-invites';
|
import {
|
||||||
import { findTeamMembers } from '@documenso/lib/server-only/team/find-team-members';
|
ZFindTeamMemberInvitesResponseSchema,
|
||||||
|
findTeamMemberInvites,
|
||||||
|
} from '@documenso/lib/server-only/team/find-team-member-invites';
|
||||||
|
import {
|
||||||
|
ZFindTeamMembersResponseSchema,
|
||||||
|
findTeamMembers,
|
||||||
|
} from '@documenso/lib/server-only/team/find-team-members';
|
||||||
import { findTeams } from '@documenso/lib/server-only/team/find-teams';
|
import { findTeams } from '@documenso/lib/server-only/team/find-teams';
|
||||||
import { findTeamsPending } from '@documenso/lib/server-only/team/find-teams-pending';
|
import {
|
||||||
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
ZFindTeamsPendingResponseSchema,
|
||||||
|
findTeamsPending,
|
||||||
|
} from '@documenso/lib/server-only/team/find-teams-pending';
|
||||||
|
import { ZGetTeamByIdResponseSchema, getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||||
import { getTeamEmailByEmail } from '@documenso/lib/server-only/team/get-team-email-by-email';
|
import { getTeamEmailByEmail } from '@documenso/lib/server-only/team/get-team-email-by-email';
|
||||||
import { getTeamInvitations } from '@documenso/lib/server-only/team/get-team-invitations';
|
import {
|
||||||
import { getTeamMembers } from '@documenso/lib/server-only/team/get-team-members';
|
ZGetTeamInvitationsResponseSchema,
|
||||||
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
getTeamInvitations,
|
||||||
|
} from '@documenso/lib/server-only/team/get-team-invitations';
|
||||||
|
import {
|
||||||
|
ZGetTeamMembersResponseSchema,
|
||||||
|
getTeamMembers,
|
||||||
|
} from '@documenso/lib/server-only/team/get-team-members';
|
||||||
|
import { ZGetTeamsResponseSchema, getTeams } from '@documenso/lib/server-only/team/get-teams';
|
||||||
import { leaveTeam } from '@documenso/lib/server-only/team/leave-team';
|
import { leaveTeam } from '@documenso/lib/server-only/team/leave-team';
|
||||||
import { requestTeamOwnershipTransfer } from '@documenso/lib/server-only/team/request-team-ownership-transfer';
|
import { requestTeamOwnershipTransfer } from '@documenso/lib/server-only/team/request-team-ownership-transfer';
|
||||||
import { resendTeamEmailVerification } from '@documenso/lib/server-only/team/resend-team-email-verification';
|
import { resendTeamEmailVerification } from '@documenso/lib/server-only/team/resend-team-email-verification';
|
||||||
import { resendTeamMemberInvitation } from '@documenso/lib/server-only/team/resend-team-member-invitation';
|
import { resendTeamMemberInvitation } from '@documenso/lib/server-only/team/resend-team-member-invitation';
|
||||||
import { updateTeam } from '@documenso/lib/server-only/team/update-team';
|
import { updateTeam } from '@documenso/lib/server-only/team/update-team';
|
||||||
import { updateTeamBrandingSettings } from '@documenso/lib/server-only/team/update-team-branding-settings';
|
import {
|
||||||
import { updateTeamDocumentSettings } from '@documenso/lib/server-only/team/update-team-document-settings';
|
ZUpdateTeamBrandingSettingsResponseSchema,
|
||||||
|
updateTeamBrandingSettings,
|
||||||
|
} from '@documenso/lib/server-only/team/update-team-branding-settings';
|
||||||
|
import {
|
||||||
|
ZUpdateTeamDocumentSettingsResponseSchema,
|
||||||
|
updateTeamDocumentSettings,
|
||||||
|
} from '@documenso/lib/server-only/team/update-team-document-settings';
|
||||||
import { updateTeamEmail } from '@documenso/lib/server-only/team/update-team-email';
|
import { updateTeamEmail } from '@documenso/lib/server-only/team/update-team-email';
|
||||||
import { updateTeamMember } from '@documenso/lib/server-only/team/update-team-member';
|
import { updateTeamMember } from '@documenso/lib/server-only/team/update-team-member';
|
||||||
import { updateTeamPublicProfile } from '@documenso/lib/server-only/team/update-team-public-profile';
|
import { updateTeamPublicProfile } from '@documenso/lib/server-only/team/update-team-public-profile';
|
||||||
@@ -73,6 +95,7 @@ import {
|
|||||||
} from './schema';
|
} from './schema';
|
||||||
|
|
||||||
export const teamRouter = router({
|
export const teamRouter = router({
|
||||||
|
// Internal endpoint for now.
|
||||||
acceptTeamInvitation: authenticatedProcedure
|
acceptTeamInvitation: authenticatedProcedure
|
||||||
.input(ZAcceptTeamInvitationMutationSchema)
|
.input(ZAcceptTeamInvitationMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
@@ -82,6 +105,7 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Internal endpoint for now.
|
||||||
declineTeamInvitation: authenticatedProcedure
|
declineTeamInvitation: authenticatedProcedure
|
||||||
.input(ZDeclineTeamInvitationMutationSchema)
|
.input(ZDeclineTeamInvitationMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
@@ -91,6 +115,7 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Internal endpoint for now.
|
||||||
createBillingPortal: authenticatedProcedure
|
createBillingPortal: authenticatedProcedure
|
||||||
.input(ZCreateTeamBillingPortalMutationSchema)
|
.input(ZCreateTeamBillingPortalMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
@@ -101,7 +126,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
createTeam: authenticatedProcedure
|
createTeam: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team' } })
|
||||||
.input(ZCreateTeamMutationSchema)
|
.input(ZCreateTeamMutationSchema)
|
||||||
|
.output(ZCreateTeamResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await createTeam({
|
return await createTeam({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -110,7 +137,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
createTeamEmailVerification: authenticatedProcedure
|
createTeamEmailVerification: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team/{teamId}/email' } })
|
||||||
.input(ZCreateTeamEmailVerificationMutationSchema)
|
.input(ZCreateTeamEmailVerificationMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await createTeamEmailVerification({
|
return await createTeamEmailVerification({
|
||||||
teamId: input.teamId,
|
teamId: input.teamId,
|
||||||
@@ -123,7 +152,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
createTeamMemberInvites: authenticatedProcedure
|
createTeamMemberInvites: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team/{teamId}/member/invite' } })
|
||||||
.input(ZCreateTeamMemberInvitesMutationSchema)
|
.input(ZCreateTeamMemberInvitesMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await createTeamMemberInvites({
|
return await createTeamMemberInvites({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -132,6 +163,7 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Internal endpoint for now.
|
||||||
createTeamPendingCheckout: authenticatedProcedure
|
createTeamPendingCheckout: authenticatedProcedure
|
||||||
.input(ZCreateTeamPendingCheckoutMutationSchema)
|
.input(ZCreateTeamPendingCheckoutMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
@@ -142,6 +174,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeam: authenticatedProcedure
|
deleteTeam: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}' } })
|
||||||
.input(ZDeleteTeamMutationSchema)
|
.input(ZDeleteTeamMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeam({
|
return await deleteTeam({
|
||||||
@@ -151,6 +184,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamEmail: authenticatedProcedure
|
deleteTeamEmail: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}/email' } })
|
||||||
.input(ZDeleteTeamEmailMutationSchema)
|
.input(ZDeleteTeamEmailMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamEmail({
|
return await deleteTeamEmail({
|
||||||
@@ -161,6 +195,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamEmailVerification: authenticatedProcedure
|
deleteTeamEmailVerification: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}/email-verification' } })
|
||||||
.input(ZDeleteTeamEmailVerificationMutationSchema)
|
.input(ZDeleteTeamEmailVerificationMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamEmailVerification({
|
return await deleteTeamEmailVerification({
|
||||||
@@ -170,6 +205,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamMemberInvitations: authenticatedProcedure
|
deleteTeamMemberInvitations: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}/member/invite' } })
|
||||||
.input(ZDeleteTeamMemberInvitationsMutationSchema)
|
.input(ZDeleteTeamMemberInvitationsMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamMemberInvitations({
|
return await deleteTeamMemberInvitations({
|
||||||
@@ -179,6 +215,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamMembers: authenticatedProcedure
|
deleteTeamMembers: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}/member' } })
|
||||||
.input(ZDeleteTeamMembersMutationSchema)
|
.input(ZDeleteTeamMembersMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamMembers({
|
return await deleteTeamMembers({
|
||||||
@@ -188,6 +225,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamPending: authenticatedProcedure
|
deleteTeamPending: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team-pending/{pendingTeamId}' } })
|
||||||
.input(ZDeleteTeamPendingMutationSchema)
|
.input(ZDeleteTeamPendingMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamPending({
|
return await deleteTeamPending({
|
||||||
@@ -197,6 +235,7 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteTeamTransferRequest: authenticatedProcedure
|
deleteTeamTransferRequest: authenticatedProcedure
|
||||||
|
// .meta({ openapi: { method: 'DELETE', path: '/team/{teamId}/transfer' } })
|
||||||
.input(ZDeleteTeamTransferRequestMutationSchema)
|
.input(ZDeleteTeamTransferRequestMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await deleteTeamTransferRequest({
|
return await deleteTeamTransferRequest({
|
||||||
@@ -205,6 +244,7 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Internal endpoint for now.
|
||||||
findTeamInvoices: authenticatedProcedure
|
findTeamInvoices: authenticatedProcedure
|
||||||
.input(ZFindTeamInvoicesQuerySchema)
|
.input(ZFindTeamInvoicesQuerySchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
@@ -215,7 +255,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
findTeamMemberInvites: authenticatedProcedure
|
findTeamMemberInvites: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'GET', path: '/team/{teamId}/member/invite' } })
|
||||||
.input(ZFindTeamMemberInvitesQuerySchema)
|
.input(ZFindTeamMemberInvitesQuerySchema)
|
||||||
|
.output(ZFindTeamMemberInvitesResponseSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
return await findTeamMemberInvites({
|
return await findTeamMemberInvites({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -224,7 +266,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
findTeamMembers: authenticatedProcedure
|
findTeamMembers: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'GET', path: '/team/{teamId}/member' } })
|
||||||
.input(ZFindTeamMembersQuerySchema)
|
.input(ZFindTeamMembersQuerySchema)
|
||||||
|
.output(ZFindTeamMembersResponseSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
return await findTeamMembers({
|
return await findTeamMembers({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -232,6 +276,7 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Todo: Refactor, seems to be a redundant endpoint.
|
||||||
findTeams: authenticatedProcedure.input(ZFindTeamsQuerySchema).query(async ({ input, ctx }) => {
|
findTeams: authenticatedProcedure.input(ZFindTeamsQuerySchema).query(async ({ input, ctx }) => {
|
||||||
return await findTeams({
|
return await findTeams({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -240,7 +285,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
findTeamsPending: authenticatedProcedure
|
findTeamsPending: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'GET', path: '/team-pending' } })
|
||||||
.input(ZFindTeamsPendingQuerySchema)
|
.input(ZFindTeamsPendingQuerySchema)
|
||||||
|
.output(ZFindTeamsPendingResponseSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
return await findTeamsPending({
|
return await findTeamsPending({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -248,34 +295,52 @@ export const teamRouter = router({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getTeam: authenticatedProcedure.input(ZGetTeamQuerySchema).query(async ({ input, ctx }) => {
|
getTeam: authenticatedProcedure
|
||||||
return await getTeamById({ teamId: input.teamId, userId: ctx.user.id });
|
.meta({ openapi: { method: 'GET', path: '/team/{teamId}' } })
|
||||||
}),
|
.input(ZGetTeamQuerySchema)
|
||||||
|
.output(ZGetTeamByIdResponseSchema)
|
||||||
|
.query(async ({ input, ctx }) => {
|
||||||
|
return await getTeamById({ teamId: input.teamId, userId: ctx.user.id });
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Todo
|
||||||
getTeamEmailByEmail: authenticatedProcedure.query(async ({ ctx }) => {
|
getTeamEmailByEmail: authenticatedProcedure.query(async ({ ctx }) => {
|
||||||
return await getTeamEmailByEmail({ email: ctx.user.email });
|
return await getTeamEmailByEmail({ email: ctx.user.email });
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getTeamInvitations: authenticatedProcedure.query(async ({ ctx }) => {
|
getTeamInvitations: authenticatedProcedure
|
||||||
return await getTeamInvitations({ email: ctx.user.email });
|
.meta({ openapi: { method: 'GET', path: '/team/invite' } })
|
||||||
}),
|
.input(z.void())
|
||||||
|
.output(ZGetTeamInvitationsResponseSchema)
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
return await getTeamInvitations({ email: ctx.user.email });
|
||||||
|
}),
|
||||||
|
|
||||||
getTeamMembers: authenticatedProcedure
|
getTeamMembers: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'GET', path: '/team/member' } })
|
||||||
.input(ZGetTeamMembersQuerySchema)
|
.input(ZGetTeamMembersQuerySchema)
|
||||||
|
.output(ZGetTeamMembersResponseSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
return await getTeamMembers({ teamId: input.teamId, userId: ctx.user.id });
|
return await getTeamMembers({ teamId: input.teamId, userId: ctx.user.id });
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Internal endpoint for now.
|
||||||
getTeamPrices: authenticatedProcedure.query(async () => {
|
getTeamPrices: authenticatedProcedure.query(async () => {
|
||||||
return await getTeamPrices();
|
return await getTeamPrices();
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getTeams: authenticatedProcedure.query(async ({ ctx }) => {
|
getTeams: authenticatedProcedure
|
||||||
return await getTeams({ userId: ctx.user.id });
|
.meta({ openapi: { method: 'GET', path: '/team' } })
|
||||||
}),
|
.input(z.void())
|
||||||
|
.output(ZGetTeamsResponseSchema)
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
return await getTeams({ userId: ctx.user.id });
|
||||||
|
}),
|
||||||
|
|
||||||
leaveTeam: authenticatedProcedure
|
leaveTeam: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team/{teamId}/leave' } })
|
||||||
.input(ZLeaveTeamMutationSchema)
|
.input(ZLeaveTeamMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await leaveTeam({
|
return await leaveTeam({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -284,7 +349,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeam: authenticatedProcedure
|
updateTeam: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}' } })
|
||||||
.input(ZUpdateTeamMutationSchema)
|
.input(ZUpdateTeamMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await updateTeam({
|
return await updateTeam({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -293,7 +360,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeamEmail: authenticatedProcedure
|
updateTeamEmail: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}/email' } })
|
||||||
.input(ZUpdateTeamEmailMutationSchema)
|
.input(ZUpdateTeamEmailMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await updateTeamEmail({
|
return await updateTeamEmail({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -302,7 +371,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeamMember: authenticatedProcedure
|
updateTeamMember: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}/member' } })
|
||||||
.input(ZUpdateTeamMemberMutationSchema)
|
.input(ZUpdateTeamMemberMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await updateTeamMember({
|
return await updateTeamMember({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -311,12 +382,14 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeamPublicProfile: authenticatedProcedure
|
updateTeamPublicProfile: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}/profile' } })
|
||||||
.input(ZUpdateTeamPublicProfileMutationSchema)
|
.input(ZUpdateTeamPublicProfileMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const { teamId, bio, enabled } = input;
|
const { teamId, bio, enabled } = input;
|
||||||
|
|
||||||
const team = await updateTeamPublicProfile({
|
await updateTeamPublicProfile({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
data: {
|
data: {
|
||||||
@@ -324,8 +397,6 @@ export const teamRouter = router({
|
|||||||
enabled,
|
enabled,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, url: team.url };
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
@@ -344,7 +415,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
requestTeamOwnershipTransfer: authenticatedProcedure
|
requestTeamOwnershipTransfer: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team/{teamId}/transfer' } })
|
||||||
.input(ZRequestTeamOwnerhsipTransferMutationSchema)
|
.input(ZRequestTeamOwnerhsipTransferMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await requestTeamOwnershipTransfer({
|
return await requestTeamOwnershipTransfer({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -354,7 +427,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
resendTeamEmailVerification: authenticatedProcedure
|
resendTeamEmailVerification: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'POST', path: '/team/{teamId}/email/resend' } })
|
||||||
.input(ZResendTeamEmailVerificationMutationSchema)
|
.input(ZResendTeamEmailVerificationMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await resendTeamEmailVerification({
|
await resendTeamEmailVerification({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -363,7 +438,11 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
resendTeamMemberInvitation: authenticatedProcedure
|
resendTeamMemberInvitation: authenticatedProcedure
|
||||||
|
.meta({
|
||||||
|
openapi: { method: 'POST', path: '/team/{teamId}/member/invite/{invitationId}/resend' },
|
||||||
|
})
|
||||||
.input(ZResendTeamMemberInvitationMutationSchema)
|
.input(ZResendTeamMemberInvitationMutationSchema)
|
||||||
|
.output(z.void())
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await resendTeamMemberInvitation({
|
await resendTeamMemberInvitation({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
@@ -373,7 +452,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeamBrandingSettings: authenticatedProcedure
|
updateTeamBrandingSettings: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}/branding' } })
|
||||||
.input(ZUpdateTeamBrandingSettingsMutationSchema)
|
.input(ZUpdateTeamBrandingSettingsMutationSchema)
|
||||||
|
.output(ZUpdateTeamBrandingSettingsResponseSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { teamId, settings } = input;
|
const { teamId, settings } = input;
|
||||||
|
|
||||||
@@ -385,7 +466,9 @@ export const teamRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTeamDocumentSettings: authenticatedProcedure
|
updateTeamDocumentSettings: authenticatedProcedure
|
||||||
|
.meta({ openapi: { method: 'PATCH', path: '/team/{teamId}/settings' } })
|
||||||
.input(ZUpdateTeamDocumentSettingsMutationSchema)
|
.input(ZUpdateTeamDocumentSettingsMutationSchema)
|
||||||
|
.output(ZUpdateTeamDocumentSettingsResponseSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { teamId, settings } = input;
|
const { teamId, settings } = input;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"preserveWatchOutput": true,
|
"preserveWatchOutput": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
"target": "ES2018"
|
"target": "ES2018"
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts", "**/*.tsx", "**/.d.ts"],
|
"include": ["**/*.ts", "**/*.tsx", "**/.d.ts"],
|
||||||
|
|||||||
@@ -78,6 +78,6 @@
|
|||||||
"tailwind-merge": "^1.12.0",
|
"tailwind-merge": "^1.12.0",
|
||||||
"tailwindcss-animate": "^1.0.5",
|
"tailwindcss-animate": "^1.0.5",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.23.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user