add medreport schema
This commit is contained in:
@@ -3,6 +3,11 @@ import { BadgeX, Ban, ShieldPlus, VenetianMask } from 'lucide-react';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import {
|
||||
AccountInvitationsTable,
|
||||
AccountMembersTable,
|
||||
InviteMembersDialogContainer,
|
||||
} from '@kit/team-accounts/components';
|
||||
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
|
||||
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
@@ -28,14 +33,8 @@ import { AdminMembersTable } from './admin-members-table';
|
||||
import { AdminMembershipsTable } from './admin-memberships-table';
|
||||
import { AdminReactivateUserDialog } from './admin-reactivate-user-dialog';
|
||||
|
||||
import {
|
||||
AccountInvitationsTable,
|
||||
AccountMembersTable,
|
||||
InviteMembersDialogContainer,
|
||||
} from '@kit/team-accounts/components';
|
||||
|
||||
type Account = Tables<'accounts'>;
|
||||
type Membership = Tables<'accounts_memberships'>;
|
||||
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
|
||||
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
|
||||
|
||||
export function AdminAccountPage(props: {
|
||||
account: Account & { memberships: Membership[] };
|
||||
@@ -231,6 +230,7 @@ async function SubscriptionsTable(props: { accountId: string }) {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const { data: subscription, error } = await client
|
||||
.schema('medreport')
|
||||
.from('subscriptions')
|
||||
.select('*, subscription_items !inner (*)')
|
||||
.eq('account_id', props.accountId)
|
||||
@@ -372,6 +372,7 @@ async function getMemberships(userId: string) {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const memberships = await client
|
||||
.schema('medreport')
|
||||
.from('accounts_memberships')
|
||||
.select<
|
||||
string,
|
||||
@@ -394,7 +395,7 @@ async function getMemberships(userId: string) {
|
||||
async function getMembers(accountSlug: string) {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const members = await client.rpc('get_account_members', {
|
||||
const members = await client.schema('medreport').rpc('get_account_members', {
|
||||
account_slug: accountSlug,
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import { AdminDeleteUserDialog } from './admin-delete-user-dialog';
|
||||
import { AdminImpersonateUserDialog } from './admin-impersonate-user-dialog';
|
||||
import { AdminResetPasswordDialog } from './admin-reset-password-dialog';
|
||||
|
||||
type Account = Database['public']['Tables']['accounts']['Row'];
|
||||
type Account = Database['medreport']['Tables']['accounts']['Row'];
|
||||
|
||||
const FiltersSchema = z.object({
|
||||
type: z.enum(['all', 'team', 'personal']),
|
||||
|
||||
@@ -9,7 +9,7 @@ import { DataTable } from '@kit/ui/enhanced-data-table';
|
||||
import { ProfileAvatar } from '@kit/ui/profile-avatar';
|
||||
|
||||
type Memberships =
|
||||
Database['public']['Functions']['get_account_members']['Returns'][number];
|
||||
Database['medreport']['Functions']['get_account_members']['Returns'][number];
|
||||
|
||||
export function AdminMembersTable(props: { members: Memberships[] }) {
|
||||
return <DataTable data={props.members} columns={getColumns()} />;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Tables } from '@kit/supabase/database';
|
||||
import { DataTable } from '@kit/ui/enhanced-data-table';
|
||||
|
||||
type Membership = Tables<'accounts_memberships'> & {
|
||||
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'> & {
|
||||
account: {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
@@ -15,13 +15,13 @@ import {
|
||||
ImpersonateUserSchema,
|
||||
ReactivateUserSchema,
|
||||
} from './schema/admin-actions.schema';
|
||||
import { CreateCompanySchema } from './schema/create-company.schema';
|
||||
import { CreateUserSchema } from './schema/create-user.schema';
|
||||
import { ResetPasswordSchema } from './schema/reset-password.schema';
|
||||
import { createAdminAccountsService } from './services/admin-accounts.service';
|
||||
import { createAdminAuthUserService } from './services/admin-auth-user.service';
|
||||
import { adminAction } from './utils/admin-action';
|
||||
import { CreateCompanySchema } from './schema/create-company.schema';
|
||||
import { createCreateCompanyAccountService } from './services/admin-create-company-account.service';
|
||||
import { adminAction } from './utils/admin-action';
|
||||
|
||||
/**
|
||||
* @name banUserAction
|
||||
@@ -183,12 +183,16 @@ export const createUserAction = adminAction(
|
||||
);
|
||||
|
||||
const { error: accountError } = await adminClient
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.update({ personal_code: personalCode })
|
||||
.eq('id', data.user.id);
|
||||
|
||||
if (accountError) {
|
||||
logger.error({ accountError }, 'Error inserting personal code to accounts');
|
||||
logger.error(
|
||||
{ accountError },
|
||||
'Error inserting personal code to accounts',
|
||||
);
|
||||
throw new Error(`Error saving personal code: ${accountError.message}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ class AdminAccountsService {
|
||||
|
||||
async deleteAccount(accountId: string) {
|
||||
const { error } = await this.adminClient
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.delete()
|
||||
.eq('id', accountId);
|
||||
|
||||
@@ -30,6 +30,7 @@ export class AdminDashboardService {
|
||||
};
|
||||
|
||||
const subscriptionsPromise = this.client
|
||||
.schema('medreport')
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'active')
|
||||
@@ -47,6 +48,7 @@ export class AdminDashboardService {
|
||||
});
|
||||
|
||||
const trialsPromise = this.client
|
||||
.schema('medreport')
|
||||
.from('subscriptions')
|
||||
.select('*', selectParams)
|
||||
.eq('status', 'trialing')
|
||||
@@ -64,6 +66,7 @@ export class AdminDashboardService {
|
||||
});
|
||||
|
||||
const accountsPromise = this.client
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', true)
|
||||
@@ -81,6 +84,7 @@ export class AdminDashboardService {
|
||||
});
|
||||
|
||||
const teamAccountsPromise = this.client
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('*', selectParams)
|
||||
.eq('is_personal_account', false)
|
||||
|
||||
Reference in New Issue
Block a user