diff --git a/src/components/ui/spinner.tsx b/src/components/ui/spinner.tsx
new file mode 100644
index 0000000..dab07e1
--- /dev/null
+++ b/src/components/ui/spinner.tsx
@@ -0,0 +1,10 @@
+import { cn } from "@/lib/utils"
+import { SpinnerIcon } from "@phosphor-icons/react"
+
+function Spinner({ className, ...props }: React.ComponentProps<"svg">) {
+ return (
+
+ )
+}
+
+export { Spinner }
diff --git a/src/components/user/ban-user-confirm-dialog.tsx b/src/components/user/ban-user-confirm-dialog.tsx
index c802f2b..7c42265 100644
--- a/src/components/user/ban-user-confirm-dialog.tsx
+++ b/src/components/user/ban-user-confirm-dialog.tsx
@@ -1,4 +1,3 @@
-import { ReturnError } from '@/types/common';
import usePreventAutoFocus from '@hooks/use-prevent-auto-focus';
import { m } from '@paraglide/messages';
import { ShieldWarningIcon } from '@phosphor-icons/react';
@@ -17,6 +16,7 @@ import {
} from '@ui/dialog';
import { UserWithRole } from 'better-auth/plugins';
import { toast } from 'sonner';
+import { Spinner } from '../ui/spinner';
import {
Table,
TableBody,
@@ -36,7 +36,7 @@ const BanUserConfirm = ({ data }: BanConfirmProps) => {
const queryClient = useQueryClient();
const prevent = usePreventAutoFocus();
- const { mutate: banUserMutation } = useMutation({
+ const { mutate: banUserMutation, isPending } = useMutation({
mutationFn: banUser,
onSuccess: () => {
queryClient.refetchQueries({
@@ -130,7 +130,13 @@ const BanUserConfirm = ({ data }: BanConfirmProps) => {
{m.ui_cancel_btn()}
-
+
+ {isPending && }
{m.ui_confirm_btn()}
diff --git a/src/components/user/unban-user-dialog.tsx b/src/components/user/unban-user-dialog.tsx
index 0787d08..3a50b80 100644
--- a/src/components/user/unban-user-dialog.tsx
+++ b/src/components/user/unban-user-dialog.tsx
@@ -1,4 +1,3 @@
-import { ReturnError } from '@/types/common';
import useHasPermission from '@hooks/use-has-permission';
import usePreventAutoFocus from '@hooks/use-prevent-auto-focus';
import { m } from '@paraglide/messages';
@@ -23,7 +22,15 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@ui/tooltip';
import { UserWithRole } from 'better-auth/plugins';
import { useState } from 'react';
import { toast } from 'sonner';
-import DisplayBreakLineMessage from '../DisplayBreakLineMessage';
+import { Spinner } from '../ui/spinner';
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '../ui/table';
type UnbanUserProps = {
data: UserWithRole;
@@ -38,7 +45,7 @@ const UnbanUserAction = ({ data }: UnbanUserProps) => {
const [_open, _setOpen] = useState(false);
const prevent = usePreventAutoFocus();
- const { mutate: unbanMutation } = useMutation({
+ const { mutate: unbanMutation, isPending } = useMutation({
mutationFn: unbanUser,
onSuccess: () => {
queryClient.refetchQueries({
@@ -107,19 +114,47 @@ const UnbanUserAction = ({ data }: UnbanUserProps) => {
{m.users_page_ui_dialog_alert_title()}
-
- {m.users_page_ui_dialog_alert_description({
- name: data.name,
- email: data.email,
- })}
-
+
+
+
+
+
+ {m.users_page_ui_dialog_alert_description_title()}
+
+
+
+
+
+
+ {m.users_page_ui_table_header_name()}:
+
+ {data.name}
+
+
+
+ {m.users_page_ui_table_header_email()}:
+
+ {data.email}
+
+
+
+
{m.ui_cancel_btn()}
-
+
+ {isPending && }
{m.ui_confirm_btn()}
diff --git a/src/lib/auth.ts b/src/lib/auth.ts
index 8624f7e..e1b96d9 100644
--- a/src/lib/auth.ts
+++ b/src/lib/auth.ts
@@ -9,7 +9,7 @@ import {
owner,
} from '@lib/auth/organization-permissions';
import { ac, admin, user } from '@lib/auth/permissions';
-import { createAuditLog } from '@service/repository';
+import { createAuditLog, getInitialOrganization } from '@service/repository';
import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { admin as adminPlugin, organization } from 'better-auth/plugins';
@@ -117,6 +117,15 @@ export const auth = betterAuth({
},
session: {
create: {
+ before: async (session) => {
+ const organization = await getInitialOrganization(session.userId);
+ return {
+ data: {
+ ...session,
+ activeOrganizationId: organization?.id,
+ },
+ };
+ },
after: async (session, context) => {
if (context?.path.includes('/sign-in')) {
await createAuditLog({
diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts
index 3377b64..6afa5db 100644
--- a/src/routeTree.gen.ts
+++ b/src/routeTree.gen.ts
@@ -14,11 +14,14 @@ import { Route as appIndexRouteImport } from './routes/(app)/index'
import { Route as authSignInRouteImport } from './routes/(auth)/sign-in'
import { Route as appauthRouteRouteImport } from './routes/(app)/(auth)/route'
import { Route as ApiAuthSplatRouteImport } from './routes/api.auth.$'
-import { Route as appauthDashboardRouteImport } from './routes/(app)/(auth)/dashboard'
+import { Route as appauthManagementRouteRouteImport } from './routes/(app)/(auth)/management/route'
import { Route as appauthKanriRouteRouteImport } from './routes/(app)/(auth)/kanri/route'
import { Route as appauthAccountRouteRouteImport } from './routes/(app)/(auth)/account/route'
+import { Route as appauthManagementIndexRouteImport } from './routes/(app)/(auth)/management/index'
import { Route as appauthKanriIndexRouteImport } from './routes/(app)/(auth)/kanri/index'
import { Route as appauthAccountIndexRouteImport } from './routes/(app)/(auth)/account/index'
+import { Route as appauthManagementHousesRouteImport } from './routes/(app)/(auth)/management/houses'
+import { Route as appauthManagementDashboardRouteImport } from './routes/(app)/(auth)/management/dashboard'
import { Route as appauthKanriUsersRouteImport } from './routes/(app)/(auth)/kanri/users'
import { Route as appauthKanriSettingsRouteImport } from './routes/(app)/(auth)/kanri/settings'
import { Route as appauthKanriLogsRouteImport } from './routes/(app)/(auth)/kanri/logs'
@@ -50,9 +53,9 @@ const ApiAuthSplatRoute = ApiAuthSplatRouteImport.update({
path: '/api/auth/$',
getParentRoute: () => rootRouteImport,
} as any)
-const appauthDashboardRoute = appauthDashboardRouteImport.update({
- id: '/dashboard',
- path: '/dashboard',
+const appauthManagementRouteRoute = appauthManagementRouteRouteImport.update({
+ id: '/management',
+ path: '/management',
getParentRoute: () => appauthRouteRoute,
} as any)
const appauthKanriRouteRoute = appauthKanriRouteRouteImport.update({
@@ -65,6 +68,11 @@ const appauthAccountRouteRoute = appauthAccountRouteRouteImport.update({
path: '/account',
getParentRoute: () => appauthRouteRoute,
} as any)
+const appauthManagementIndexRoute = appauthManagementIndexRouteImport.update({
+ id: '/',
+ path: '/',
+ getParentRoute: () => appauthManagementRouteRoute,
+} as any)
const appauthKanriIndexRoute = appauthKanriIndexRouteImport.update({
id: '/',
path: '/',
@@ -75,6 +83,17 @@ const appauthAccountIndexRoute = appauthAccountIndexRouteImport.update({
path: '/',
getParentRoute: () => appauthAccountRouteRoute,
} as any)
+const appauthManagementHousesRoute = appauthManagementHousesRouteImport.update({
+ id: '/houses',
+ path: '/houses',
+ getParentRoute: () => appauthManagementRouteRoute,
+} as any)
+const appauthManagementDashboardRoute =
+ appauthManagementDashboardRouteImport.update({
+ id: '/dashboard',
+ path: '/dashboard',
+ getParentRoute: () => appauthManagementRouteRoute,
+ } as any)
const appauthKanriUsersRoute = appauthKanriUsersRouteImport.update({
id: '/users',
path: '/users',
@@ -117,7 +136,7 @@ export interface FileRoutesByFullPath {
'/': typeof appIndexRoute
'/account': typeof appauthAccountRouteRouteWithChildren
'/kanri': typeof appauthKanriRouteRouteWithChildren
- '/dashboard': typeof appauthDashboardRoute
+ '/management': typeof appauthManagementRouteRouteWithChildren
'/api/auth/$': typeof ApiAuthSplatRoute
'/account/change-password': typeof appauthAccountChangePasswordRoute
'/account/profile': typeof appauthAccountProfileRoute
@@ -126,13 +145,15 @@ export interface FileRoutesByFullPath {
'/kanri/logs': typeof appauthKanriLogsRoute
'/kanri/settings': typeof appauthKanriSettingsRoute
'/kanri/users': typeof appauthKanriUsersRoute
+ '/management/dashboard': typeof appauthManagementDashboardRoute
+ '/management/houses': typeof appauthManagementHousesRoute
'/account/': typeof appauthAccountIndexRoute
'/kanri/': typeof appauthKanriIndexRoute
+ '/management/': typeof appauthManagementIndexRoute
}
export interface FileRoutesByTo {
'/sign-in': typeof authSignInRoute
'/': typeof appIndexRoute
- '/dashboard': typeof appauthDashboardRoute
'/api/auth/$': typeof ApiAuthSplatRoute
'/account/change-password': typeof appauthAccountChangePasswordRoute
'/account/profile': typeof appauthAccountProfileRoute
@@ -141,8 +162,11 @@ export interface FileRoutesByTo {
'/kanri/logs': typeof appauthKanriLogsRoute
'/kanri/settings': typeof appauthKanriSettingsRoute
'/kanri/users': typeof appauthKanriUsersRoute
+ '/management/dashboard': typeof appauthManagementDashboardRoute
+ '/management/houses': typeof appauthManagementHousesRoute
'/account': typeof appauthAccountIndexRoute
'/kanri': typeof appauthKanriIndexRoute
+ '/management': typeof appauthManagementIndexRoute
}
export interface FileRoutesById {
__root__: typeof rootRouteImport
@@ -152,7 +176,7 @@ export interface FileRoutesById {
'/(app)/': typeof appIndexRoute
'/(app)/(auth)/account': typeof appauthAccountRouteRouteWithChildren
'/(app)/(auth)/kanri': typeof appauthKanriRouteRouteWithChildren
- '/(app)/(auth)/dashboard': typeof appauthDashboardRoute
+ '/(app)/(auth)/management': typeof appauthManagementRouteRouteWithChildren
'/api/auth/$': typeof ApiAuthSplatRoute
'/(app)/(auth)/account/change-password': typeof appauthAccountChangePasswordRoute
'/(app)/(auth)/account/profile': typeof appauthAccountProfileRoute
@@ -161,8 +185,11 @@ export interface FileRoutesById {
'/(app)/(auth)/kanri/logs': typeof appauthKanriLogsRoute
'/(app)/(auth)/kanri/settings': typeof appauthKanriSettingsRoute
'/(app)/(auth)/kanri/users': typeof appauthKanriUsersRoute
+ '/(app)/(auth)/management/dashboard': typeof appauthManagementDashboardRoute
+ '/(app)/(auth)/management/houses': typeof appauthManagementHousesRoute
'/(app)/(auth)/account/': typeof appauthAccountIndexRoute
'/(app)/(auth)/kanri/': typeof appauthKanriIndexRoute
+ '/(app)/(auth)/management/': typeof appauthManagementIndexRoute
}
export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
@@ -171,7 +198,7 @@ export interface FileRouteTypes {
| '/'
| '/account'
| '/kanri'
- | '/dashboard'
+ | '/management'
| '/api/auth/$'
| '/account/change-password'
| '/account/profile'
@@ -180,13 +207,15 @@ export interface FileRouteTypes {
| '/kanri/logs'
| '/kanri/settings'
| '/kanri/users'
+ | '/management/dashboard'
+ | '/management/houses'
| '/account/'
| '/kanri/'
+ | '/management/'
fileRoutesByTo: FileRoutesByTo
to:
| '/sign-in'
| '/'
- | '/dashboard'
| '/api/auth/$'
| '/account/change-password'
| '/account/profile'
@@ -195,8 +224,11 @@ export interface FileRouteTypes {
| '/kanri/logs'
| '/kanri/settings'
| '/kanri/users'
+ | '/management/dashboard'
+ | '/management/houses'
| '/account'
| '/kanri'
+ | '/management'
id:
| '__root__'
| '/(app)'
@@ -205,7 +237,7 @@ export interface FileRouteTypes {
| '/(app)/'
| '/(app)/(auth)/account'
| '/(app)/(auth)/kanri'
- | '/(app)/(auth)/dashboard'
+ | '/(app)/(auth)/management'
| '/api/auth/$'
| '/(app)/(auth)/account/change-password'
| '/(app)/(auth)/account/profile'
@@ -214,8 +246,11 @@ export interface FileRouteTypes {
| '/(app)/(auth)/kanri/logs'
| '/(app)/(auth)/kanri/settings'
| '/(app)/(auth)/kanri/users'
+ | '/(app)/(auth)/management/dashboard'
+ | '/(app)/(auth)/management/houses'
| '/(app)/(auth)/account/'
| '/(app)/(auth)/kanri/'
+ | '/(app)/(auth)/management/'
fileRoutesById: FileRoutesById
}
export interface RootRouteChildren {
@@ -261,11 +296,11 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ApiAuthSplatRouteImport
parentRoute: typeof rootRouteImport
}
- '/(app)/(auth)/dashboard': {
- id: '/(app)/(auth)/dashboard'
- path: '/dashboard'
- fullPath: '/dashboard'
- preLoaderRoute: typeof appauthDashboardRouteImport
+ '/(app)/(auth)/management': {
+ id: '/(app)/(auth)/management'
+ path: '/management'
+ fullPath: '/management'
+ preLoaderRoute: typeof appauthManagementRouteRouteImport
parentRoute: typeof appauthRouteRoute
}
'/(app)/(auth)/kanri': {
@@ -282,6 +317,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof appauthAccountRouteRouteImport
parentRoute: typeof appauthRouteRoute
}
+ '/(app)/(auth)/management/': {
+ id: '/(app)/(auth)/management/'
+ path: '/'
+ fullPath: '/management/'
+ preLoaderRoute: typeof appauthManagementIndexRouteImport
+ parentRoute: typeof appauthManagementRouteRoute
+ }
'/(app)/(auth)/kanri/': {
id: '/(app)/(auth)/kanri/'
path: '/'
@@ -296,6 +338,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof appauthAccountIndexRouteImport
parentRoute: typeof appauthAccountRouteRoute
}
+ '/(app)/(auth)/management/houses': {
+ id: '/(app)/(auth)/management/houses'
+ path: '/houses'
+ fullPath: '/management/houses'
+ preLoaderRoute: typeof appauthManagementHousesRouteImport
+ parentRoute: typeof appauthManagementRouteRoute
+ }
+ '/(app)/(auth)/management/dashboard': {
+ id: '/(app)/(auth)/management/dashboard'
+ path: '/dashboard'
+ fullPath: '/management/dashboard'
+ preLoaderRoute: typeof appauthManagementDashboardRouteImport
+ parentRoute: typeof appauthManagementRouteRoute
+ }
'/(app)/(auth)/kanri/users': {
id: '/(app)/(auth)/kanri/users'
path: '/users'
@@ -384,16 +440,34 @@ const appauthKanriRouteRouteChildren: appauthKanriRouteRouteChildren = {
const appauthKanriRouteRouteWithChildren =
appauthKanriRouteRoute._addFileChildren(appauthKanriRouteRouteChildren)
+interface appauthManagementRouteRouteChildren {
+ appauthManagementDashboardRoute: typeof appauthManagementDashboardRoute
+ appauthManagementHousesRoute: typeof appauthManagementHousesRoute
+ appauthManagementIndexRoute: typeof appauthManagementIndexRoute
+}
+
+const appauthManagementRouteRouteChildren: appauthManagementRouteRouteChildren =
+ {
+ appauthManagementDashboardRoute: appauthManagementDashboardRoute,
+ appauthManagementHousesRoute: appauthManagementHousesRoute,
+ appauthManagementIndexRoute: appauthManagementIndexRoute,
+ }
+
+const appauthManagementRouteRouteWithChildren =
+ appauthManagementRouteRoute._addFileChildren(
+ appauthManagementRouteRouteChildren,
+ )
+
interface appauthRouteRouteChildren {
appauthAccountRouteRoute: typeof appauthAccountRouteRouteWithChildren
appauthKanriRouteRoute: typeof appauthKanriRouteRouteWithChildren
- appauthDashboardRoute: typeof appauthDashboardRoute
+ appauthManagementRouteRoute: typeof appauthManagementRouteRouteWithChildren
}
const appauthRouteRouteChildren: appauthRouteRouteChildren = {
appauthAccountRouteRoute: appauthAccountRouteRouteWithChildren,
appauthKanriRouteRoute: appauthKanriRouteRouteWithChildren,
- appauthDashboardRoute: appauthDashboardRoute,
+ appauthManagementRouteRoute: appauthManagementRouteRouteWithChildren,
}
const appauthRouteRouteWithChildren = appauthRouteRoute._addFileChildren(
diff --git a/src/routes/(app)/(auth)/kanri/houses.tsx b/src/routes/(app)/(auth)/kanri/houses.tsx
index 19b1498..995637e 100644
--- a/src/routes/(app)/(auth)/kanri/houses.tsx
+++ b/src/routes/(app)/(auth)/kanri/houses.tsx
@@ -14,6 +14,7 @@ import { useState } from 'react';
export const Route = createFileRoute('/(app)/(auth)/kanri/houses')({
component: RouteComponent,
+ staticData: { breadcrumb: () => m.nav_houses() },
});
function RouteComponent() {
@@ -54,7 +55,7 @@ function RouteComponent() {
-
+
m.nav_dashboard() },
});
diff --git a/src/routes/(app)/(auth)/management/houses.tsx b/src/routes/(app)/(auth)/management/houses.tsx
new file mode 100644
index 0000000..6392485
--- /dev/null
+++ b/src/routes/(app)/(auth)/management/houses.tsx
@@ -0,0 +1,30 @@
+import CurrentUserActionGroup from '@/components/house/current-user-action-group';
+import CurrentUserHouseList from '@/components/house/current-user-house-list';
+import CurrentUserMemberList from '@/components/house/current-user-member-list';
+import { m } from '@/paraglide/messages';
+import { housesQueries } from '@/service/queries';
+import { authClient } from '@lib/auth-client';
+import { useQuery } from '@tanstack/react-query';
+import { createFileRoute } from '@tanstack/react-router';
+
+export const Route = createFileRoute('/(app)/(auth)/management/houses')({
+ component: RouteComponent,
+ staticData: { breadcrumb: () => m.nav_houses() },
+});
+
+function RouteComponent() {
+ const { data: houses } = useQuery(housesQueries.currentUser());
+ const { data: activeHouse } = authClient.useActiveOrganization();
+
+ if (!activeHouse || !houses) return null;
+
+ return (
+
+ );
+}
diff --git a/src/routes/(app)/(auth)/management/index.tsx b/src/routes/(app)/(auth)/management/index.tsx
new file mode 100644
index 0000000..e131b56
--- /dev/null
+++ b/src/routes/(app)/(auth)/management/index.tsx
@@ -0,0 +1,9 @@
+import { createFileRoute } from '@tanstack/react-router'
+
+export const Route = createFileRoute('/(app)/(auth)/management/')({
+ component: RouteComponent,
+})
+
+function RouteComponent() {
+ return Hello "/(app)/(auth)/management/"!
+}
diff --git a/src/routes/(app)/(auth)/management/route.tsx b/src/routes/(app)/(auth)/management/route.tsx
new file mode 100644
index 0000000..be8cca7
--- /dev/null
+++ b/src/routes/(app)/(auth)/management/route.tsx
@@ -0,0 +1,6 @@
+import { m } from '@/paraglide/messages';
+import { createFileRoute } from '@tanstack/react-router';
+
+export const Route = createFileRoute('/(app)/(auth)/management')({
+ staticData: { breadcrumb: () => m.nav_label_management() },
+});
diff --git a/src/routes/(app)/route.tsx b/src/routes/(app)/route.tsx
index 0adaf27..f8fcaf7 100644
--- a/src/routes/(app)/route.tsx
+++ b/src/routes/(app)/route.tsx
@@ -23,7 +23,7 @@ function RouteComponent() {
}, [language]);
return (
-
+
diff --git a/src/service/house.api.ts b/src/service/house.api.ts
index 0cb1c6a..026c573 100644
--- a/src/service/house.api.ts
+++ b/src/service/house.api.ts
@@ -4,6 +4,7 @@ import { DB_TABLE, LOG_ACTION } from '@/types/enum';
import { auth } from '@lib/auth';
import { authMiddleware } from '@lib/middleware';
import { createServerFn } from '@tanstack/react-start';
+import { getRequestHeaders } from '@tanstack/react-start/server';
import { parseError } from '@utils/helper';
import {
baseHouse,
@@ -43,6 +44,7 @@ export const getAllHouse = createServerFn({ method: 'GET' })
role: true,
user: {
select: {
+ id: true,
name: true,
email: true,
image: true,
@@ -74,6 +76,43 @@ export const getAllHouse = createServerFn({ method: 'GET' })
}
});
+export const getCurrentUserHouses = createServerFn({ method: 'GET' })
+ .middleware([authMiddleware])
+ .handler(async ({ context: { user } }) => {
+ try {
+ const houses = await prisma.organization.findMany({
+ where: { members: { some: { userId: user.id } } },
+ orderBy: { createdAt: 'asc' },
+ include: {
+ _count: {
+ select: {
+ members: true,
+ },
+ },
+ members: {
+ select: {
+ role: true,
+ user: {
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ return houses;
+ } catch (error) {
+ console.error(error);
+ const { message, code } = parseError(error);
+ throw { message, code };
+ }
+ });
+
export const createHouse = createServerFn({ method: 'POST' })
.middleware([authMiddleware])
.inputValidator(houseCreateBESchema)
@@ -177,3 +216,40 @@ export const deleteHouse = createServerFn({ method: 'POST' })
throw { message, code };
}
});
+
+export const deleteUserHouse = createServerFn({ method: 'POST' })
+ .middleware([authMiddleware])
+ .inputValidator(baseHouse)
+ .handler(async ({ data, context: { user } }) => {
+ try {
+ const currentHouse = await prisma.organization.findUnique({
+ where: { id: data.id },
+ });
+ if (!currentHouse) throw Error('House not found');
+
+ const headers = getRequestHeaders();
+ const result = await auth.api.deleteOrganization({
+ body: {
+ organizationId: data.id, // required
+ },
+ headers,
+ });
+
+ if (result) {
+ await createAuditLog({
+ action: LOG_ACTION.DELETE,
+ tableName: DB_TABLE.ORGANIZATION,
+ recordId: result?.id,
+ oldValue: JSON.stringify(currentHouse),
+ newValue: '',
+ userId: user.id,
+ });
+ }
+
+ return result;
+ } catch (error) {
+ console.error(error);
+ const { message, code } = parseError(error);
+ throw { message, code };
+ }
+ });
diff --git a/src/service/house.schema.ts b/src/service/house.schema.ts
index 5451fc0..f5379ae 100644
--- a/src/service/house.schema.ts
+++ b/src/service/house.schema.ts
@@ -27,6 +27,10 @@ export const houseCreateBESchema = houseCreateSchema.extend({
slug: z.string().nonempty(m.common_is_required({ field: 'Slug' })),
});
+export const houseCreateByUserBESchema = houseCreateBESchema.omit({
+ userId: true,
+});
+
export const houseEditSchema = baseHouse.extend({
name: z
.string()
diff --git a/src/service/queries.ts b/src/service/queries.ts
index 087d288..718ca55 100644
--- a/src/service/queries.ts
+++ b/src/service/queries.ts
@@ -1,7 +1,7 @@
import { getSession } from '@lib/auth/session';
import { queryOptions } from '@tanstack/react-query';
import { getAllAudit } from './audit.api';
-import { getAllHouse } from './house.api';
+import { getAllHouse, getCurrentUserHouses } from './house.api';
import {
getAdminSettings,
getCurrentUserLanguage,
@@ -69,4 +69,9 @@ export const housesQueries = {
queryKey: [...housesQueries.all, 'list', params],
queryFn: () => getAllHouse({ data: params }),
}),
+ currentUser: () =>
+ queryOptions({
+ queryKey: [...housesQueries.all, 'currentUser'],
+ queryFn: () => getCurrentUserHouses(),
+ }),
};
diff --git a/src/service/repository.ts b/src/service/repository.ts
index 67d065d..65decbe 100644
--- a/src/service/repository.ts
+++ b/src/service/repository.ts
@@ -54,3 +54,16 @@ export const createAuditLog = async (data: Omit) => {
throw { message, code };
}
};
+
+export const getInitialOrganization = async (userId: string) => {
+ const organization = await prisma.organization.findFirst({
+ where: {
+ members: {
+ some: {
+ userId,
+ },
+ },
+ },
+ });
+ return organization;
+};
diff --git a/src/types/common.d.ts b/src/types/common.d.ts
index 894c5e1..e69de29 100644
--- a/src/types/common.d.ts
+++ b/src/types/common.d.ts
@@ -1,4 +0,0 @@
-export interface ReturnError extends Error {
- message: string;
- code: string;
-}
diff --git a/src/types/db.d.ts b/src/types/db.d.ts
index 7f2ade1..eccffb8 100644
--- a/src/types/db.d.ts
+++ b/src/types/db.d.ts
@@ -19,6 +19,7 @@ declare global {
role: true;
user: {
select: {
+ id: true;
name: true;
email: true;
image: true;
@@ -28,4 +29,9 @@ declare global {
};
};
}>;
+
+ type ReturnError = Error & {
+ message: string;
+ code: string;
+ };
}