init: lab project bootstrapped from isletmem-kovakcrm
- CRM domain modules removed (customers, services, software, calendar, tasks, invoices, leads, finance, etc.)
- DLS branding: package name=lab, logo wordmark, sidebar nav, header CTA
- Tenant layer extended with kind dimension (lab|clinic) + requireTenantKind helper
- Schema rewritten for DLS domain: jobs, job_files, job_status_history, prosthetics, connections, finance_entries, notifications
- Onboarding form: clinic/lab account-type selection + auto-generated memberNumber
- Placeholder routes for jobs/{inbound,outbound,new}, products, finance, connections
- PDF spec + spec.md under belgeler/
- db: lab database + 13 collections + indexes + storage bucket (job-files) provisioned via Appwrite MCP
Ref: belgeler/dls-ui-tasarim.pdf
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import "server-only";
|
||||
|
||||
import { Query } from "node-appwrite";
|
||||
|
||||
import { createAdminClient, getCurrentUser } from "./server";
|
||||
import { DATABASE_ID, TABLES, type TenantSettings } from "./schema";
|
||||
import { getActiveTenantId, getUserTeams } from "./tenant";
|
||||
|
||||
export type ActiveContext = {
|
||||
user: { id: string; name: string; email: string };
|
||||
tenantId: string;
|
||||
settings: TenantSettings | null;
|
||||
};
|
||||
|
||||
export async function getActiveContext(): Promise<ActiveContext | null> {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return null;
|
||||
|
||||
let tenantId = await getActiveTenantId();
|
||||
if (!tenantId) {
|
||||
const teams = await getUserTeams();
|
||||
tenantId = teams?.teams[0]?.$id ?? null;
|
||||
}
|
||||
if (!tenantId) return null;
|
||||
|
||||
let settings: TenantSettings | null = null;
|
||||
try {
|
||||
const { tablesDB } = createAdminClient();
|
||||
const result = await tablesDB.listRows({
|
||||
databaseId: DATABASE_ID,
|
||||
tableId: TABLES.tenantSettings,
|
||||
queries: [Query.equal("tenantId", tenantId), Query.limit(1)],
|
||||
});
|
||||
settings = (result.rows[0] as unknown as TenantSettings) ?? null;
|
||||
} catch {
|
||||
settings = null;
|
||||
}
|
||||
|
||||
return {
|
||||
user: { id: user.$id, name: user.name, email: user.email },
|
||||
tenantId,
|
||||
settings,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user