ministry-platform-provider
Version:
TypeScript client library for Ministry Platform API integration
57 lines (56 loc) • 2.05 kB
JavaScript
export class ProcedureService {
client;
constructor(client) {
this.client = client;
}
/**
* Returns the list of procedures available to the current user with basic metadata.
*/
async getProcedures(search) {
try {
await this.client.ensureValidToken();
const params = search ? { $search: search } : undefined;
return await this.client.getHttpClient().get('/procs', params);
}
catch (error) {
console.error('Error getting procedures:', error);
throw error;
}
}
/**
* Executes the requested stored procedure retrieving parameters from the query string.
*/
async executeProcedure(procedure, params) {
try {
await this.client.ensureValidToken();
console.log('Executing procedure:', procedure);
console.log('Query Params:', params);
const endpoint = `/procs/${encodeURIComponent(procedure)}`;
const data = await this.client.getHttpClient().get(endpoint, params);
console.log('Procedure results:', data);
return data;
}
catch (error) {
console.error(`Error executing procedure ${procedure}:`, error);
throw error;
}
}
/**
* Executes the requested stored procedure with provided parameters in the request body.
*/
async executeProcedureWithBody(procedure, parameters) {
try {
await this.client.ensureValidToken();
console.log('Executing procedure with body:', procedure);
console.log('Parameters:', parameters);
const endpoint = `/procs/${encodeURIComponent(procedure)}`;
const data = await this.client.getHttpClient().post(endpoint, parameters);
console.log('Procedure results:', data);
return data;
}
catch (error) {
console.error(`Error executing procedure ${procedure}:`, error);
throw error;
}
}
}