km-web-plugin
Version:
ICE Web Plugin Initializer
50 lines (44 loc) • 1.37 kB
text/typescript
// @ts-ignore - JS module
import { log, getUser } from '@/utils/em.sdk';
// @ts-ignore - JS module
import { getCdo, saveCdo } from '@/utils/em.api';
export abstract class BaseApiService {
protected async getCdo(name: string): Promise<any> {
try {
const response = await getCdo(name);
log(`CDO ${name} retrieved successfully`);
return response;
} catch (error) {
log(`Error retrieving CDO ${name}:`, error);
throw error;
}
}
protected async saveCdo(name: string, data: any): Promise<void> {
try {
await saveCdo(name, data);
log(`CDO ${name} saved successfully`);
} catch (error) {
log(`Error saving CDO ${name}:`, error);
throw error;
}
}
protected async getCurrentUser() {
return await getUser();
}
protected log(...args: any[]): void {
log(...args);
}
protected async handleApiCall<T>(
operation: () => Promise<T>,
operationName: string,
): Promise<T> {
try {
const result = await operation();
this.log(`${operationName} completed successfully`);
return result;
} catch (error) {
this.log(`${operationName} failed:`, error);
throw error;
}
}
}