fix: add jsdoc comments to models

This commit is contained in:
StevanFreeborn
2023-02-20 21:08:22 -06:00
parent f3c69d3a34
commit 396660e801
17 changed files with 185 additions and 12 deletions
+36 -10
View File
@@ -92,17 +92,17 @@ export class ApiResponse<T> {
public asGetPagedAppsResponseType(): ApiResponse<GetPagedAppsResponse> {
const apiResponse = this as ApiResponse<any>;
const apps = apiResponse.data.items.map((item: any) => {
return new App(item.href, item.id, item.name);
});
const apps = apiResponse.data.items.map((item: any) => {
return new App(item.href, item.id, item.name);
});
const getAppsPagedResponse = new GetPagedAppsResponse(
apps,
apiResponse.data.pageNumber,
apiResponse.data.pageSize,
apiResponse.data.totalPages,
apiResponse.data.totalRecords
);
const getAppsPagedResponse = new GetPagedAppsResponse(
apps,
apiResponse.data.pageNumber,
apiResponse.data.pageSize,
apiResponse.data.totalPages,
apiResponse.data.totalRecords
);
return new ApiResponse<GetPagedAppsResponse>(
apiResponse.statusCode,
@@ -238,6 +238,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
);
}
/**
* @method asFileInfoType - Converts the ApiResponse to an ApiResponse<FileInfo>.
* @returns {ApiResponse<FileInfo>} - An ApiResponse<FileInfo>.
*/
public asFileInfoType(): ApiResponse<FileInfo> {
const apiResponse = this as ApiResponse<any>;
@@ -259,6 +263,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
);
}
/**
* @method asFileType - Converts the ApiResponse to an ApiResponse<File>.
* @returns {ApiResponse<File>} - An ApiResponse<File>.
*/
public asFileType(response: AxiosResponse): ApiResponse<File> {
const apiResponse = this as ApiResponse<any>;
@@ -411,6 +419,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
);
}
/**
* @method asRecordCollectionType - Converts the ApiResponse to an ApiResponse<CollectionResponse<Record>>.
* @returns {ApiResponse<CollectionResponse<Record>>} - An ApiResponse<CollectionResponse<Record>>.
*/
public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> {
const apiResponse = this as ApiResponse<any>;
@@ -434,6 +446,10 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
);
}
/**
* @method asSaveRecordResponseType - Converts the ApiResponse to an ApiResponse<SaveRecordResponse>.
* @returns {ApiResponse<SaveRecordResponse>} - An ApiResponse<SaveRecordResponse>.
*/
public asSaveRecordResponseType(): ApiResponse<SaveRecordResponse> {
const apiResponse = this as ApiResponse<any>;
const response = new SaveRecordResponse(
@@ -447,6 +463,11 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
);
}
/**
* @method getRecordValueByType - Gets the RecordValue by by type.
* @param {RecordValue} recordValueItem - The record value item.
* @returns {RecordValue} - The RecordValue.
*/
private static getRecordValueByType(recordValueItem: any): RecordValue<any> {
const type = RecordValueType[recordValueItem.type];
@@ -629,6 +650,11 @@ const getAppsPagedResponse = new GetPagedAppsResponse(
}
}
/**
* @method convertToDelegate - Converts the delegate item to a Delegate object.
* @param {any} delegateItem - The delegate item to convert.
* @returns {Delegate} - The converted Delegate object.
*/
private static convertToDelegate(delegateItem: any): Delegate {
const delegateType = DelegateType[delegateItem.delegateType];
+3 -1
View File
@@ -60,7 +60,9 @@ export class ApiResponseFactory {
}
/**
*
* @method getStreamDataAsString - Gets the data from a stream as a string
* @param {Readable} stream - The stream that will be used to get the data
* @returns {Promise<string>} - A promise that resolves to the data from the stream as a string
*/
private static async getStreamDataAsString(
stream: Readable
+3
View File
@@ -1,3 +1,6 @@
/**
* @class CreatedWithIdResponse<T> - Represents a response to a request to create a resource.
*/
export class CreatedWithIdResponse<T> {
/**
* @property {T} id - The id of the created object.
+9
View File
@@ -1,7 +1,16 @@
import { RecordValue } from './RecordValue';
import { RecordValueType } from '../enums/RecordValueType';
/**
* @class DecimalRecordValue - Represents a decimal record value
*/
export class DecimalRecordValue extends RecordValue<number> {
/**
* @constructor - Creates a new instance of DecimalRecordValue
* @param {number} fieldId - The id of the field
* @param {number} value - The value of the field
* @returns {DecimalRecordValue} - A new instance of DecimalRecordValue
*/
constructor(fieldId: number, value: number) {
super(RecordValueType.Decimal, fieldId, value);
}
+9
View File
@@ -2,7 +2,16 @@ import { RecordValue } from './RecordValue';
import { RecordValueType } from '../enums/RecordValueType';
import { type Delegate } from './Delegate';
/**
* @class DelegateListRecordValue - Represents a delegate list record value.
*/
export class DelegateListRecordValue extends RecordValue<Delegate[]> {
/**
* @constructor - Creates a new instance of DelegateListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {Delegate[]} value - The value of the field.
* @returns {DelegateListRecordValue} - A new instance of DelegateListRecordValue.
*/
constructor(fieldId: number, value: Delegate[]) {
super(RecordValueType.DelegateList, fieldId, value);
}
+9
View File
@@ -2,7 +2,16 @@ import { RecordValue } from './RecordValue';
import { RecordValueType } from '../enums/RecordValueType';
import { type File } from './File';
/**
* @class FileListRecordValue - Represents a file list record value.
*/
export class FileListRecordValue extends RecordValue<File[]> {
/**
* @constructor - Creates a new instance of FileListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {File[]} value - The value of the field.
* @returns {FileListRecordValue} - A new instance of FileListRecordValue.
*/
constructor(fieldId: number, value: File[]) {
super(RecordValueType.FileList, fieldId, value);
}
+3
View File
@@ -1,6 +1,9 @@
import { DataFormat } from '../enums/DataFormat';
import { PagingRequest } from './PagingRequest';
/**
* @class GetRecordsByAppIdRequest - Represents a request to get records by app id.
*/
export class GetRecordsByAppIdRequest {
/**
* @property {number} appId - The id of the app that the records belong to.
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
/**
* @class GuidListRecordValue - Represents a guid list record value.
*/
export class GuidListRecordValue extends RecordValue<string[]> {
/**
* @constructor - Creates a new instance of GuidListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {string[]} value - The value of the field.
* @returns {GuidListRecordValue} - A new instance of GuidListRecordValue.
*/
constructor(fieldId: number, value: string[]) {
super(RecordValueType.GuidList, fieldId, value);
}
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
/**
* @class GuidRecordValue - Represents a guid record value.
*/
export class GuidRecordValue extends RecordValue<string> {
/**
* @constructor - Creates a new instance of GuidRecordValue.
* @param {number} fieldId - The id of the field.
* @param {string} value - The value of the field.
* @returns {GuidRecordValue} - A new instance of GuidRecordValue.
*/
constructor(fieldId: number, value: string) {
super(RecordValueType.Guid, fieldId, value);
}
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
/**
* @class IntegerListRecordValue - Represents an integer list record value.
*/
export class IntegerListRecordValue extends RecordValue<number[]> {
/**
* @constructor - Creates a new instance of IntegerListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {number[]} value - The value of the field.
* @returns {IntegerListRecordValue} - A new instance of IntegerListRecordValue.
*/
constructor(fieldId: number, value: number[]) {
super(RecordValueType.IntegerList, fieldId, value);
}
+17 -1
View File
@@ -49,7 +49,11 @@ export class OnspringClient {
* @throws {Error} - Thrown when the apiKey is null/undefined/empty/whitespace.
* @returns {OnspringClient} - A new instance of the OnspringClient class.
*/
constructor(baseUrl: string | undefined | null, apiKey: string | undefined | null, config: CreateAxiosDefaults = {}) {
constructor(
baseUrl: string | undefined | null,
apiKey: string | undefined | null,
config: CreateAxiosDefaults = {}
) {
if (ArgumentValidator.isValidUrl(baseUrl) === false || baseUrl === null) {
throw new Error('baseUrl must be an absolute and well-formed URI.');
}
@@ -278,6 +282,13 @@ export class OnspringClient {
return apiResponse.asCreatedWithIdResponseType<number>();
}
/**
* @method deleteFileById - Deletes a file by its id.
* @param {number} recordId - The id of the record that the file is held on.
* @param {number} fieldId - The id of the field that the file is held in.
* @param {number} fileId - The id of the file to delete.
* @returns {Promise<ApiResponse<any>>} - A promise that resolves to an ApiResponse of type any.
*/
public async deleteFileById(
recordId: number,
fieldId: number,
@@ -412,6 +423,11 @@ export class OnspringClient {
return apiResponse.asGetPagedRecordsResponseType();
}
/**
* @method saveRecord - Saves a record.
* @param {Record | SaveRecordRequest} request - The record or request that will be used to save the record.
* @returns {Promise<ApiResponse<SaveRecordResponse>>} - A promise that resolves to an ApiResponse of type SaveRecordResponse.
*/
public async saveRecord(
request: Record | SaveRecordRequest
): Promise<ApiResponse<SaveRecordResponse>> {
+26
View File
@@ -1,10 +1,32 @@
import { FilterOperators } from '../enums/FilterOperators';
/**
* @class QueryFilter - Represents a query filter.
*/
export class QueryFilter {
/**
* @property {number} fieldId - The id of the field to filter on.
*/
public fieldId: number;
/**
* @property {FilterOperators} operator - The operator for the filter.
*/
public operator: FilterOperators;
/**
* @property {string | number | Date | null} value - The value for the filter.
*/
public value: string | number | Date | null;
/**
* @constructor - Creates a new instance of the QueryFilter class.
* @param {number} fieldId - The id of the field to filter on.
* @param {FilterOperators} operator - The operator for the filter.
* @param {string | number | Date | null} value - The value for the filter.
* @returns {QueryFilter} - A new instance of the QueryFilter class.
* @throws {Error} - If the value is null and the operator is not IsNull or NotNull.
*/
constructor(
fieldId: number,
operator: FilterOperators,
@@ -23,6 +45,10 @@ export class QueryFilter {
this.value = value;
}
/**
* @method toString - Converts the filter to a string.
* @returns {string} - The filter as a string.
*/
public toString(): string {
if (this.value == null) {
return `${this.fieldId} ${this.operator}`;
+4
View File
@@ -55,6 +55,10 @@ export class Record {
this.fieldData = this.fieldData.concat(fieldData);
}
/**
* @method convertToSaveRecordRequest - Converts the record to a SaveRecordRequest.
* @returns {SaveRecordRequest} - A SaveRecordRequest.
*/
public convertToSaveRecordRequest(): SaveRecordRequest {
const fields = this.fieldData.reduce((acc, cur) => {
acc.set(cur.fieldId, cur.value);
+12
View File
@@ -1,8 +1,20 @@
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
/**
* @class SaveRecordResponse - Response from saving a record
*/
export class SaveRecordResponse extends CreatedWithIdResponse<number> {
/**
* @property {string[]} warnings - The warnings from saving the record.
*/
public warnings: string[];
/**
* @constructor - Creates a new instance of SaveRecordResponse.
* @param {number} id - The id of the record.
* @param {string[]} warnings - The warnings from saving the record.
* @returns {SaveRecordResponse} - A new instance of SaveRecordResponse.s
*/
constructor(id: number, warnings: string[] = []) {
super(id);
this.warnings = warnings;
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
import { type ScoringGroup } from './ScoringGroup';
/**
* @class ScoringGroupListRecordValue - Represents a scoring group list record value.
*/
export class ScoringGroupListRecordValue extends RecordValue<ScoringGroup[]> {
/**
* @constructor - Creates a new instance of ScoringGroupListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {ScoringGroup[]} value - The value of the field.
* @returns {ScoringGroupListRecordValue} - A new instance of ScoringGroupListRecordValue.
*/
constructor(fieldId: number, value: ScoringGroup[]) {
super(RecordValueType.ScoringGroupList, fieldId, value);
}
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
/**
* @class StringListRecordValue - Represents a string list record value.
*/
export class StringListRecordValue extends RecordValue<string[]> {
/**
* @constructor - Creates a new instance of StringListRecordValue.
* @param {number} fieldId - The id of the field.
* @param {string[]} value - The value of the field.
* @returns {StringListRecordValue} - A new instance of StringListRecordValue.
*/
constructor(fieldId: number, value: string[]) {
super(RecordValueType.StringList, fieldId, value);
}
+9
View File
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType';
import { RecordValue } from './RecordValue';
import { type TimeSpanData } from './TimeSpanData';
/**
* @class TimeSpanRecordValue - Represents a time span record value.
*/
export class TimeSpanRecordValue extends RecordValue<TimeSpanData> {
/**
* @constructor - Creates a new instance of TimeSpanRecordValue.
* @param {number} fieldId - The id of the field.
* @param {TimeSpanData} value - The value of the field.
* @returns {TimeSpanRecordValue} - A new instance of TimeSpanRecordValue.
*/
constructor(fieldId: number, value: TimeSpanData) {
super(RecordValueType.TimeSpan, fieldId, value);
}