fix: add jsdoc comments to models

This commit is contained in:
StevanFreeborn
2023-02-21 13:48:32 -06:00
committed by Stevan Freeborn
parent e97ee15387
commit 07ec44a0ad
17 changed files with 170 additions and 1 deletions
+26
View File
@@ -238,6 +238,10 @@ export class ApiResponse<T> {
); );
} }
/**
* @method asFileInfoType - Converts the ApiResponse to an ApiResponse<FileInfo>.
* @returns {ApiResponse<FileInfo>} - An ApiResponse<FileInfo>.
*/
public asFileInfoType(): ApiResponse<FileInfo> { public asFileInfoType(): ApiResponse<FileInfo> {
const apiResponse = this as ApiResponse<any>; const apiResponse = this as ApiResponse<any>;
@@ -259,6 +263,10 @@ export class ApiResponse<T> {
); );
} }
/**
* @method asFileType - Converts the ApiResponse to an ApiResponse<File>.
* @returns {ApiResponse<File>} - An ApiResponse<File>.
*/
public asFileType(response: AxiosResponse): ApiResponse<File> { public asFileType(response: AxiosResponse): ApiResponse<File> {
const apiResponse = this as ApiResponse<any>; const apiResponse = this as ApiResponse<any>;
@@ -411,6 +419,10 @@ export class ApiResponse<T> {
); );
} }
/**
* @method asRecordCollectionType - Converts the ApiResponse to an ApiResponse<CollectionResponse<Record>>.
* @returns {ApiResponse<CollectionResponse<Record>>} - An ApiResponse<CollectionResponse<Record>>.
*/
public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> { public asRecordCollectionType(): ApiResponse<CollectionResponse<Record>> {
const apiResponse = this as ApiResponse<any>; const apiResponse = this as ApiResponse<any>;
@@ -434,6 +446,10 @@ export class ApiResponse<T> {
); );
} }
/**
* @method asSaveRecordResponseType - Converts the ApiResponse to an ApiResponse<SaveRecordResponse>.
* @returns {ApiResponse<SaveRecordResponse>} - An ApiResponse<SaveRecordResponse>.
*/
public asSaveRecordResponseType(): ApiResponse<SaveRecordResponse> { public asSaveRecordResponseType(): ApiResponse<SaveRecordResponse> {
const apiResponse = this as ApiResponse<any>; const apiResponse = this as ApiResponse<any>;
const response = new SaveRecordResponse( const response = new SaveRecordResponse(
@@ -447,6 +463,11 @@ export class ApiResponse<T> {
); );
} }
/**
* @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> { private static getRecordValueByType(recordValueItem: any): RecordValue<any> {
const type = RecordValueType[recordValueItem.type]; const type = RecordValueType[recordValueItem.type];
@@ -629,6 +650,11 @@ export class ApiResponse<T> {
} }
} }
/**
* @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 { private static convertToDelegate(delegateItem: any): Delegate {
const delegateType = DelegateType[delegateItem.delegateType]; 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( private static async getStreamDataAsString(
stream: Readable 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> { export class CreatedWithIdResponse<T> {
/** /**
* @property {T} id - The id of the created object. * @property {T} id - The id of the created object.
+9
View File
@@ -1,7 +1,16 @@
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValueType } from '../enums/RecordValueType.js';
/**
* @class DecimalRecordValue - Represents a decimal record value
*/
export class DecimalRecordValue extends RecordValue<number> { 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) { constructor(fieldId: number, value: number) {
super(RecordValueType.Decimal, fieldId, value); super(RecordValueType.Decimal, fieldId, value);
} }
+9
View File
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
import { type Delegate } from './Delegate.js'; import { type Delegate } from './Delegate.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class DelegateListRecordValue - Represents a delegate list record value.
*/
export class DelegateListRecordValue extends RecordValue<Delegate[]> { 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[]) { constructor(fieldId: number, value: Delegate[]) {
super(RecordValueType.DelegateList, fieldId, value); super(RecordValueType.DelegateList, fieldId, value);
} }
+9
View File
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
import { type File } from './File.js'; import { type File } from './File.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class FileListRecordValue - Represents a file list record value.
*/
export class FileListRecordValue extends RecordValue<File[]> { 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[]) { constructor(fieldId: number, value: File[]) {
super(RecordValueType.FileList, fieldId, value); super(RecordValueType.FileList, fieldId, value);
} }
+3
View File
@@ -1,6 +1,9 @@
import { DataFormat } from '../enums/DataFormat.js'; import { DataFormat } from '../enums/DataFormat.js';
import { PagingRequest } from './PagingRequest.js'; import { PagingRequest } from './PagingRequest.js';
/**
* @class GetRecordsByAppIdRequest - Represents a request to get records by app id.
*/
export class GetRecordsByAppIdRequest { export class GetRecordsByAppIdRequest {
/** /**
* @property {number} appId - The id of the app that the records belong to. * @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.js'; import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class GuidListRecordValue - Represents a guid list record value.
*/
export class GuidListRecordValue extends RecordValue<string[]> { 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[]) { constructor(fieldId: number, value: string[]) {
super(RecordValueType.GuidList, fieldId, value); super(RecordValueType.GuidList, fieldId, value);
} }
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class GuidRecordValue - Represents a guid record value.
*/
export class GuidRecordValue extends RecordValue<string> { 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) { constructor(fieldId: number, value: string) {
super(RecordValueType.Guid, fieldId, value); super(RecordValueType.Guid, fieldId, value);
} }
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class IntegerListRecordValue - Represents an integer list record value.
*/
export class IntegerListRecordValue extends RecordValue<number[]> { 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[]) { constructor(fieldId: number, value: number[]) {
super(RecordValueType.IntegerList, fieldId, value); super(RecordValueType.IntegerList, fieldId, value);
} }
+12
View File
@@ -282,6 +282,13 @@ export class OnspringClient {
return apiResponse.asCreatedWithIdResponseType<number>(); 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( public async deleteFileById(
recordId: number, recordId: number,
fieldId: number, fieldId: number,
@@ -416,6 +423,11 @@ export class OnspringClient {
return apiResponse.asGetPagedRecordsResponseType(); 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( public async saveRecord(
request: Record | SaveRecordRequest request: Record | SaveRecordRequest
): Promise<ApiResponse<SaveRecordResponse>> { ): Promise<ApiResponse<SaveRecordResponse>> {
+26
View File
@@ -1,10 +1,32 @@
import { FilterOperators } from '../enums/FilterOperators.js'; import { FilterOperators } from '../enums/FilterOperators.js';
/**
* @class QueryFilter - Represents a query filter.
*/
export class QueryFilter { export class QueryFilter {
/**
* @property {number} fieldId - The id of the field to filter on.
*/
public fieldId: number; public fieldId: number;
/**
* @property {FilterOperators} operator - The operator for the filter.
*/
public operator: FilterOperators; public operator: FilterOperators;
/**
* @property {string | number | Date | null} value - The value for the filter.
*/
public value: string | number | Date | null; 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( constructor(
fieldId: number, fieldId: number,
operator: FilterOperators, operator: FilterOperators,
@@ -23,6 +45,10 @@ export class QueryFilter {
this.value = value; this.value = value;
} }
/**
* @method toString - Converts the filter to a string.
* @returns {string} - The filter as a string.
*/
public toString(): string { public toString(): string {
if (this.value == null) { if (this.value == null) {
return `${this.fieldId} ${this.operator}`; return `${this.fieldId} ${this.operator}`;
+4
View File
@@ -55,6 +55,10 @@ export class Record {
this.fieldData = this.fieldData.concat(fieldData); this.fieldData = this.fieldData.concat(fieldData);
} }
/**
* @method convertToSaveRecordRequest - Converts the record to a SaveRecordRequest.
* @returns {SaveRecordRequest} - A SaveRecordRequest.
*/
public convertToSaveRecordRequest(): SaveRecordRequest { public convertToSaveRecordRequest(): SaveRecordRequest {
const fields = this.fieldData.reduce((acc, cur) => { const fields = this.fieldData.reduce((acc, cur) => {
acc.set(cur.fieldId, cur.value); acc.set(cur.fieldId, cur.value);
+12
View File
@@ -1,8 +1,20 @@
import { CreatedWithIdResponse } from './CreatedWithIdResponse.js'; import { CreatedWithIdResponse } from './CreatedWithIdResponse.js';
/**
* @class SaveRecordResponse - Response from saving a record
*/
export class SaveRecordResponse extends CreatedWithIdResponse<number> { export class SaveRecordResponse extends CreatedWithIdResponse<number> {
/**
* @property {string[]} warnings - The warnings from saving the record.
*/
public warnings: string[]; 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[] = []) { constructor(id: number, warnings: string[] = []) {
super(id); super(id);
this.warnings = warnings; this.warnings = warnings;
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
import { type ScoringGroup } from './ScoringGroup.js'; import { type ScoringGroup } from './ScoringGroup.js';
/**
* @class ScoringGroupListRecordValue - Represents a scoring group list record value.
*/
export class ScoringGroupListRecordValue extends RecordValue<ScoringGroup[]> { 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[]) { constructor(fieldId: number, value: ScoringGroup[]) {
super(RecordValueType.ScoringGroupList, fieldId, value); super(RecordValueType.ScoringGroupList, fieldId, value);
} }
+9
View File
@@ -1,7 +1,16 @@
import { RecordValueType } from '../enums/RecordValueType.js'; import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
/**
* @class StringListRecordValue - Represents a string list record value.
*/
export class StringListRecordValue extends RecordValue<string[]> { 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[]) { constructor(fieldId: number, value: string[]) {
super(RecordValueType.StringList, fieldId, value); super(RecordValueType.StringList, fieldId, value);
} }
+9
View File
@@ -2,7 +2,16 @@ import { RecordValueType } from '../enums/RecordValueType.js';
import { RecordValue } from './RecordValue.js'; import { RecordValue } from './RecordValue.js';
import { type TimeSpanData } from './TimeSpanData.js'; import { type TimeSpanData } from './TimeSpanData.js';
/**
* @class TimeSpanRecordValue - Represents a time span record value.
*/
export class TimeSpanRecordValue extends RecordValue<TimeSpanData> { 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) { constructor(fieldId: number, value: TimeSpanData) {
super(RecordValueType.TimeSpan, fieldId, value); super(RecordValueType.TimeSpan, fieldId, value);
} }