@ritas-inc/sapb1commandapi-client
Version:
A stateless TypeScript client for SAP B1 Service Layer Command API with comprehensive error handling, type safety, and batch operations
23 lines (22 loc) • 1.06 kB
JavaScript
import { CreatePlanRequestSchema, UpdatePlanStatusRequestSchema, UpdatePlanProductsRequestSchema, } from '../schemas/plans.schema.js';
export class PlansService {
httpClient;
constructor(httpClient) {
this.httpClient = httpClient;
}
async create(userId, user, products) {
const validatedRequest = CreatePlanRequestSchema.parse({ user, products });
return this.httpClient.post('/api/v1/plans', validatedRequest, userId);
}
async updateStatus(userId, planId, status) {
const validatedRequest = UpdatePlanStatusRequestSchema.parse({ status });
return this.httpClient.patch(`/api/v1/plans/${planId}/status`, validatedRequest, userId);
}
async updateProducts(userId, planId, products) {
const validatedRequest = UpdatePlanProductsRequestSchema.parse({ products });
return this.httpClient.patch(`/api/v1/plans/${planId}/products`, validatedRequest, userId);
}
async cancel(userId, planId) {
return this.httpClient.delete(`/api/v1/plans/${planId}`, userId);
}
}