add health benefit form

fix super admin
This commit is contained in:
Danel Kungla
2025-07-23 16:33:24 +03:00
parent 2db67b7f20
commit 86b86c6752
43 changed files with 1329 additions and 561 deletions

View File

@@ -2,6 +2,8 @@ import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@kit/supabase/database';
import { UpdateHealthBenefitData } from './types';
/**
* Class representing an API for interacting with team accounts.
* @constructor
@@ -254,6 +256,45 @@ export class TeamAccountsApi {
return invitation;
}
/**
* @name updateHealthBenefit
* @description Update health benefits for the team account
*/
async updateHealthBenefit(data: UpdateHealthBenefitData) {
const { error } = await this.client
.schema('medreport')
.from('company_params')
.update({
benefit_occurance: data.occurance,
benefit_amount: data.amount,
updated_at: new Date().toISOString(),
})
.eq('account_id', data.accountId);
if (error) {
throw error;
}
}
/**
* @name getTeamAccountParams
* @description Get health benefits for the team account
*/
async getTeamAccountParams(accountId: string) {
const { data, error } = await this.client
.schema('medreport')
.from('company_params')
.select('*')
.eq('account_id', accountId)
.single();
if (error) {
throw error;
}
return data;
}
}
export function createTeamAccountsApi(client: SupabaseClient<Database>) {

View File

@@ -0,0 +1,5 @@
export interface UpdateHealthBenefitData {
accountId: string;
occurance: string;
amount: number;
}

View File

@@ -7,11 +7,16 @@ import { Database } from '@kit/supabase/database';
* @description Check if the current user is a super admin.
* @param client
*/
export async function isCompanyAdmin(client: SupabaseClient<Database>, accountSlug: string) {
export async function isCompanyAdmin(
client: SupabaseClient<Database>,
accountSlug: string,
) {
try {
const { data, error } = await client.rpc('is_company_admin', {
account_slug: accountSlug,
});
const { data, error } = await client
.schema('medreport')
.rpc('is_company_admin', {
account_slug: accountSlug,
});
if (error) {
throw error;