add health benefit form
fix super admin
This commit is contained in:
@@ -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>) {
|
||||
|
||||
5
packages/features/team-accounts/src/server/types.ts
Normal file
5
packages/features/team-accounts/src/server/types.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface UpdateHealthBenefitData {
|
||||
accountId: string;
|
||||
occurance: string;
|
||||
amount: number;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user