feat: implement saveFile method

This commit is contained in:
StevanFreeborn
2023-02-03 16:01:20 -06:00
parent 1b046b4cfc
commit 3dee5b690c
7 changed files with 147 additions and 2 deletions
+23
View File
@@ -10,6 +10,8 @@ import { type App } from './App';
import { type CollectionResponse } from './CollectionResponse';
import { type Field } from './Field';
import { type GetPagedFieldsResponse } from './GetPagedFieldsResponse';
import { type SaveFileRequest } from './SaveFileRequest';
import { type CreatedWithIdResponse } from './CreatedWithIdResponse';
/**
* @class OnspringClient - A client that can communicate with the Onspring API.
@@ -169,6 +171,27 @@ export class OnspringClient {
return apiResponse.AsGetPagedFieldsResponseType();
}
/**
* @method saveFile - Saves a file to a record in Onspring.
* @param {SaveFileRequest} request - The request that will be used to save the file.
* @returns {Promise<ApiResponse<CreatedWithIdResponse>>} - A promise that resolves to an ApiResponse of type CreatedWithIdResponse.
*/
public async saveFile(
request: SaveFileRequest
): Promise<ApiResponse<CreatedWithIdResponse>> {
const endpoint = EndpointFactory.getSaveFileEndpoint();
const formData = request.AsFormData();
const apiResponse = await this.post<any>(endpoint, formData, {
headers: formData.getHeaders(),
});
if (apiResponse.isSuccessful === false) {
return apiResponse;
}
return apiResponse.AsCreatedWithIdResponseType();
}
/**
* @method get - Makes a GET request to the specified endpoint.
* @param {string} endpoint - The endpoint that will be used to make the request.