feat(MED-131): use existing supabase server admin client conf
This commit is contained in:
@@ -1,27 +1,19 @@
|
|||||||
import { createClient as createCustomClient } from '@supabase/supabase-js';
|
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import type { IConnectedOnlineResponse_Search_Load } from './types';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
|
|
||||||
|
import type { ISearchLoadResponse } from '~/lib/types/connected-online';
|
||||||
|
|
||||||
export default async function syncConnectedOnline() {
|
export default async function syncConnectedOnline() {
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
const baseUrl = process.env.CONNECTED_ONLINE_URL;
|
const baseUrl = process.env.CONNECTED_ONLINE_URL;
|
||||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
|
||||||
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
||||||
|
|
||||||
if (!baseUrl || !supabaseUrl || !supabaseServiceRoleKey) {
|
if (!baseUrl) {
|
||||||
throw new Error('Could not access all necessary environment variables');
|
throw new Error('Could not access all necessary environment variables');
|
||||||
}
|
}
|
||||||
|
|
||||||
const supabase = createCustomClient(supabaseUrl, supabaseServiceRoleKey, {
|
const supabase = getSupabaseServerAdminClient();
|
||||||
auth: {
|
|
||||||
persistSession: false,
|
|
||||||
autoRefreshToken: false,
|
|
||||||
detectSessionInUrl: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post<{ d: string }>(`${baseUrl}/Search_Load`, {
|
const response = await axios.post<{ d: string }>(`${baseUrl}/Search_Load`, {
|
||||||
@@ -31,7 +23,7 @@ export default async function syncConnectedOnline() {
|
|||||||
param: "{'Value':'|et|-1'}", // get all available services in Estonian
|
param: "{'Value':'|et|-1'}", // get all available services in Estonian
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseData: IConnectedOnlineResponse_Search_Load = JSON.parse(response.data.d);
|
const responseData: ISearchLoadResponse = JSON.parse(response.data.d);
|
||||||
|
|
||||||
if (responseData?.ErrorCode !== 0) {
|
if (responseData?.ErrorCode !== 0) {
|
||||||
throw new Error('Failed to get Connected Online data');
|
throw new Error('Failed to get Connected Online data');
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
export interface IMedipostResponse_GetPublicMessageList {
|
|
||||||
code: number;
|
|
||||||
messages: {
|
|
||||||
messageId: string;
|
|
||||||
}[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IConnectedOnlineResponse_Search_Load {
|
|
||||||
Value: string;
|
|
||||||
Data: {
|
|
||||||
T_Lic: {
|
|
||||||
ID: number;
|
|
||||||
Name: string;
|
|
||||||
OnlineCanSelectWorker: boolean;
|
|
||||||
Email: string | null;
|
|
||||||
PersonalCodeRequired: boolean;
|
|
||||||
Phone: string | null;
|
|
||||||
}[];
|
|
||||||
T_Service: {
|
|
||||||
ID: number;
|
|
||||||
ClinicID: number;
|
|
||||||
Code: string;
|
|
||||||
Description: string | null;
|
|
||||||
Display: string;
|
|
||||||
Duration: number;
|
|
||||||
HasFreeCodes: boolean;
|
|
||||||
Name: string;
|
|
||||||
NetoDuration: number;
|
|
||||||
OnlineHideDuration: number;
|
|
||||||
OnlineHidePrice: number;
|
|
||||||
Price: number;
|
|
||||||
PricePeriods: string | null;
|
|
||||||
RequiresPayment: boolean;
|
|
||||||
SyncID: string;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
ErrorCode: number;
|
|
||||||
ErrorMessage: string;
|
|
||||||
}
|
|
||||||
8
lib/services/codes.service.ts
Normal file
8
lib/services/codes.service.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { getSupabaseServerAdminClient } from "@kit/supabase/server-admin-client";
|
||||||
|
import type { ICode } from "~/lib/types/code";
|
||||||
|
|
||||||
|
export const createCodes = async (codes: ICode[]) => {
|
||||||
|
await getSupabaseServerAdminClient()
|
||||||
|
.schema('medreport').from('codes')
|
||||||
|
.upsert(codes);
|
||||||
|
}
|
||||||
9
lib/types/code.ts
Normal file
9
lib/types/code.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export interface ICode {
|
||||||
|
hk_code: string;
|
||||||
|
hk_code_multiplier: number;
|
||||||
|
coefficient: number;
|
||||||
|
price: number;
|
||||||
|
analysis_group_id: number | null;
|
||||||
|
analysis_element_id: number | null;
|
||||||
|
analysis_id: number | null;
|
||||||
|
}
|
||||||
@@ -224,3 +224,36 @@ export const ConfirmedLoadResponseSchema = z.object({
|
|||||||
ErrorMessage: z.union([z.string(), z.null()]),
|
ErrorMessage: z.union([z.string(), z.null()]),
|
||||||
});
|
});
|
||||||
export type ConfirmedLoadResponse = z.infer<typeof ConfirmedLoadResponseSchema>;
|
export type ConfirmedLoadResponse = z.infer<typeof ConfirmedLoadResponseSchema>;
|
||||||
|
|
||||||
|
export interface ISearchLoadResponse {
|
||||||
|
Value: string;
|
||||||
|
Data: {
|
||||||
|
T_Lic: {
|
||||||
|
ID: number;
|
||||||
|
Name: string;
|
||||||
|
OnlineCanSelectWorker: boolean;
|
||||||
|
Email: string | null;
|
||||||
|
PersonalCodeRequired: boolean;
|
||||||
|
Phone: string | null;
|
||||||
|
}[];
|
||||||
|
T_Service: {
|
||||||
|
ID: number;
|
||||||
|
ClinicID: number;
|
||||||
|
Code: string;
|
||||||
|
Description: string | null;
|
||||||
|
Display: string;
|
||||||
|
Duration: number;
|
||||||
|
HasFreeCodes: boolean;
|
||||||
|
Name: string;
|
||||||
|
NetoDuration: number;
|
||||||
|
OnlineHideDuration: number;
|
||||||
|
OnlineHidePrice: number;
|
||||||
|
Price: number;
|
||||||
|
PricePeriods: string | null;
|
||||||
|
RequiresPayment: boolean;
|
||||||
|
SyncID: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
ErrorCode: number;
|
||||||
|
ErrorMessage: string;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user