'use server'; import { z } from "zod"; import { AppcondaException } from "../../client"; import { getSDKForCurrentUser } from "../../getSDKForCurrentUser"; import { getSDKForService } from "../../getSDKForService"; import { CreateTenantSchema, CreateTenantUserSchema, GetTenantByIdSchema, ListTenantUsersSchema, ListUserTenantsSchema } from "./schema"; import { TTenant, TTenantUser } from "./types"; /* const getTenantActionSchema = z.object({ tenantId: z.string() }); */ /* export const getTenantAction = async (parsedInput: z.infer) => { try { const { tenantId } = parsedInput; const { tenants } = await getSDKForCurrentUser(); return await tenants.get(tenantId); } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } }; const listUserTenantsScheema = z.object({ userId: z.string() }); export const listUserTenantsAction = async (parsedInput: z.infer) => { try { const { userId } = parsedInput; const { tenants } = await getSDKForService(); //@ts-ignore return await tenants.listUserTenants(userId); } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } }; const createTenantScheema = z.object({ id: z.string(), name: z.string(), slug: z.string() }); export const createTenantAction = async (parsedInput: z.infer)=> { try { const { id, name, slug } = parsedInput; const { tenants } = await getSDKForCurrentUser(); return await tenants.create({ $id: id, name: name, slug: slug, users: [] }); } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } }; */ export const AdminGetAllTenantsIdsAndNames = async () => { try { const { tenants } = await getSDKForService(); return await tenants.AdminGetAllTenantsIdsAndNames(); } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } }; export async function CreateTenant(parsedInput: z.infer): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.CreateTenant(parsedInput); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } } export async function CreateTenantUser(parsedInput: z.infer): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.CreateTenantUser(parsedInput); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } } export async function GetTenantById(parsedInput: z.infer): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.GetTenantById(parsedInput); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } } export async function ListTenants(): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.ListTenants(); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } } export async function ListTenantUsers(parsedInput: z.infer): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.ListTenantUsers(parsedInput); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } } export async function ListUserTenants(parsedInput: z.infer): Promise { try { const { tenants } = await getSDKForService(); //@ts-ignore const app = await tenants.ListUserTenants(parsedInput); return app; } catch (error) { if (error instanceof AppcondaException) { throw new Error(error.message); } throw error; } }