digi-tech-sdk
Version:
SDK oficial para integrar con la API de Digi
80 lines (79 loc) • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordService = void 0;
class RecordService {
constructor(client, authManager) {
this.client = client;
this.authManager = authManager;
}
/**
* Gets the API version path prefix
* @returns The API version path (e.g. "/1.0")
*/
getApiVersionPath() {
const version = this.authManager.getApiVersion() || '1.0';
return `/${version}`;
}
/**
* Creates a new record
* @param data The data for the new record
* @param strategy Creation strategy (IGNORE, COMPLETE, OVERRIDE)
* @returns The created record
*/
async create(data, strategy) {
const headers = {};
if (strategy) {
headers['strategy'] = strategy;
}
const response = await this.client.post(`${this.getApiVersionPath()}/legajo`, data, {
headers
});
return response.data;
}
/**
* Gets a record by ID
* @param recordId The ID of the record
* @returns The record
*/
async get(recordId) {
const response = await this.client.get(`${this.getApiVersionPath()}/legajo/${recordId}`);
return response.data;
}
/**
* Updates a record
* @param recordId The ID of the record to update
* @param data The data to update
* @returns The updated record
*/
async update(recordId, data) {
const response = await this.client.put(`${this.getApiVersionPath()}/legajo/${recordId}`, data);
return response.data;
}
/**
* Gets the recovery link from a record
* @param record Either a record ID or a record object
* @returns The recovery link or null if not found
*/
async getLinkRecover(record) {
// If a string is provided, fetch the record first
if (typeof record === 'string') {
record = await this.get(record);
}
// Return the linkRecover property if it exists
return record.linkRecover || null;
}
/**
* Gets the applicant link from a record
* @param record Either a record ID or a record object
* @returns The applicant link or null if not found
*/
async getLinkApplicant(record) {
// If a string is provided, fetch the record first
if (typeof record === 'string') {
record = await this.get(record);
}
// Return the linkApplicant property if it exists
return record.linkApplicant || null;
}
}
exports.RecordService = RecordService;