feat: add filter operator enum, add models for getting records by ids and querying records
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
export enum FilterOperators {
|
||||||
|
Equal = 'eq',
|
||||||
|
NotEqual = 'ne',
|
||||||
|
Contains = 'contains',
|
||||||
|
IsNull = 'isnull',
|
||||||
|
NotNull = 'notnull',
|
||||||
|
GreaterThan = 'gt',
|
||||||
|
LessThan = 'lt',
|
||||||
|
And = 'and',
|
||||||
|
Or = 'or',
|
||||||
|
Not = 'not',
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { DataFormat } from '../enums/DataFormat';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class GetRecordsRequest - Request to get records by their ids
|
||||||
|
*/
|
||||||
|
export class GetRecordsRequest {
|
||||||
|
/**
|
||||||
|
* @property {number} appId - The id of the app the records belong to.
|
||||||
|
*/
|
||||||
|
appId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number[]} recordIds - The ids of the records to get.
|
||||||
|
*/
|
||||||
|
recordIds: number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number[]} fieldIds - The ids of the fields to include in the response.
|
||||||
|
*/
|
||||||
|
fieldIds: number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {DataFormat} dataFormat - The format of the data in the response.
|
||||||
|
*/
|
||||||
|
dataFormat: DataFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of GetRecordsRequest
|
||||||
|
* @param {number} appId - The id of the app the records belong to.
|
||||||
|
* @param {number[]} recordIds - The ids of the records to get.
|
||||||
|
* @param {number[]} fieldIds - The ids of the fields to include in the response.
|
||||||
|
* @param {DataFormat} dataFormat - The format of the data in the response.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
appId: number,
|
||||||
|
recordIds: number[],
|
||||||
|
fieldIds: number[] = [],
|
||||||
|
dataFormat: DataFormat = DataFormat.Raw
|
||||||
|
) {
|
||||||
|
this.appId = appId;
|
||||||
|
this.recordIds = recordIds;
|
||||||
|
this.fieldIds = fieldIds;
|
||||||
|
this.dataFormat = dataFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import { type Record } from './Record';
|
|||||||
import { type GetRecordRequest } from './GetRecordRequest';
|
import { type GetRecordRequest } from './GetRecordRequest';
|
||||||
import { type GetRecordsByAppIdRequest } from './GetRecordsByAppIdRequest';
|
import { type GetRecordsByAppIdRequest } from './GetRecordsByAppIdRequest';
|
||||||
import { type GetPagedRecordsResponse } from './GetPagedRecordsResponse';
|
import { type GetPagedRecordsResponse } from './GetPagedRecordsResponse';
|
||||||
|
import { type GetRecordsRequest } from './GetRecordsRequest';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class OnspringClient - A client that can communicate with the Onspring API.
|
* @class OnspringClient - A client that can communicate with the Onspring API.
|
||||||
@@ -356,6 +357,12 @@ export class OnspringClient {
|
|||||||
return apiResponse.asRecordType();
|
return apiResponse.asRecordType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getRecordsByIds(
|
||||||
|
request: GetRecordsRequest
|
||||||
|
): Promise<ApiResponse<CollectionResponse<Record>>> {
|
||||||
|
throw new Error('Not implemented');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getReportsByAppId - Gets a paged list of reports by the app id.
|
* @method getReportsByAppId - Gets a paged list of reports by the app id.
|
||||||
* @param {number} appId - The id of the app to get the reports for.
|
* @param {number} appId - The id of the app to get the reports for.
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { DataFormat } from '../enums/DataFormat';
|
||||||
|
import { PagingRequest } from './PagingRequest';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class QueryRecordsRequest - Request to query for records.
|
||||||
|
*/
|
||||||
|
export class QueryRecordsRequest {
|
||||||
|
/**
|
||||||
|
* @property {number} appId - The id of the app the records belong to.
|
||||||
|
*/
|
||||||
|
appId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} filter - The filter to use to query for records.
|
||||||
|
*/
|
||||||
|
filter: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number[]} fieldIds - The ids of the fields to include in the response.
|
||||||
|
*/
|
||||||
|
fieldIds: number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {DataFormat} dataFormat - The format of the data in the response.
|
||||||
|
*/
|
||||||
|
dataFormat: DataFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {PagingRequest} pagingRequest - The paging request to use to query for records.
|
||||||
|
*/
|
||||||
|
pagingRequest: PagingRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of QueryRecordsRequest
|
||||||
|
* @param {number} appId - The id of the app the records belong to.
|
||||||
|
* @param {string} filter - The filter to use to query for records.
|
||||||
|
* @param {number[]} fieldIds - The ids of the fields to include in the response.
|
||||||
|
* @param {DataFormat} dataFormat - The format of the data in the response.
|
||||||
|
* @param {PagingRequest} pagingRequest - The paging request to use to query for records.
|
||||||
|
* @returns {QueryRecordsRequest} - A new instance of QueryRecordsRequest
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
appId: number,
|
||||||
|
filter: string,
|
||||||
|
fieldIds: number[] = [],
|
||||||
|
dataFormat: DataFormat = DataFormat.Raw,
|
||||||
|
pagingRequest: PagingRequest = new PagingRequest(1, 50)
|
||||||
|
) {
|
||||||
|
this.appId = appId;
|
||||||
|
this.filter = filter;
|
||||||
|
this.fieldIds = fieldIds;
|
||||||
|
this.dataFormat = dataFormat;
|
||||||
|
this.pagingRequest = pagingRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { FilterOperators } from '../src/enums/FilterOperators';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('FilterOperators', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(FilterOperators).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a Equal property with value "eq"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('Equal', 'eq');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a NotEqual property with value "ne"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('NotEqual', 'ne');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a Contains property with value "contains"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('Contains', 'contains');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a IsNull property with value "isnull"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('IsNull', 'isnull');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a NotNull property with value "notnull"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('NotNull', 'notnull');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a GreaterThan property with value "gt"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('GreaterThan', 'gt');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a LessThan property with value "lt"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('LessThan', 'lt');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a And property with value "and"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('And', 'and');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a Or property with value "or"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('Or', 'or');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a Not property with value "not"', function () {
|
||||||
|
expect(FilterOperators).to.have.property('Not', 'not');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { GetRecordsRequest } from '../src/models/GetRecordsRequest';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { DataFormat } from '../src/enums/DataFormat';
|
||||||
|
|
||||||
|
describe('GetRecordsRequest', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(GetRecordsRequest).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(GetRecordsRequest).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor with 2 parameters', function () {
|
||||||
|
expect(GetRecordsRequest).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have an appId property', function () {
|
||||||
|
expect(new GetRecordsRequest(1, [1, 2])).to.have.property('appId');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a recordIds property', function () {
|
||||||
|
expect(new GetRecordsRequest(1, [1, 2])).to.have.property('recordIds');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a fieldIds property', function () {
|
||||||
|
expect(new GetRecordsRequest(1, [1, 2])).to.have.property('fieldIds');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a dataFormat property', function () {
|
||||||
|
expect(new GetRecordsRequest(1, [1, 2])).to.have.property('dataFormat');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const appId = 1;
|
||||||
|
const recordIds = [1, 2];
|
||||||
|
const fieldIds = [1, 2];
|
||||||
|
const dataFormat = DataFormat.Raw;
|
||||||
|
|
||||||
|
const request = new GetRecordsRequest(
|
||||||
|
appId,
|
||||||
|
recordIds,
|
||||||
|
fieldIds,
|
||||||
|
dataFormat
|
||||||
|
);
|
||||||
|
expect(request).to.have.property('appId', appId);
|
||||||
|
expect(request).to.have.property('recordIds', recordIds);
|
||||||
|
expect(request).to.have.property('fieldIds', fieldIds);
|
||||||
|
expect(request).to.have.property('dataFormat', dataFormat);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { QueryRecordsRequest } from '../src/models/QueryRecordsRequest';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { DataFormat } from '../src/enums/DataFormat';
|
||||||
|
import { PagingRequest } from '../src/models/PagingRequest';
|
||||||
|
|
||||||
|
describe('QueryRecordsRequest', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(QueryRecordsRequest).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(QueryRecordsRequest).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that takes 2 parameters', function () {
|
||||||
|
expect(QueryRecordsRequest).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have an appId property', function () {
|
||||||
|
expect(new QueryRecordsRequest(1, 'filter')).to.have.property('appId');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a filter property', function () {
|
||||||
|
expect(new QueryRecordsRequest(1, 'filter')).to.have.property('filter');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a fieldIds property', function () {
|
||||||
|
expect(new QueryRecordsRequest(1, 'filter')).to.have.property('fieldIds');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a dataFormat property', function () {
|
||||||
|
expect(new QueryRecordsRequest(1, 'filter')).to.have.property('dataFormat');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a pagingRequest property', function () {
|
||||||
|
expect(new QueryRecordsRequest(1, 'filter')).to.have.property(
|
||||||
|
'pagingRequest'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const appId = 1;
|
||||||
|
const filter = 'filter';
|
||||||
|
const fieldIds = [1, 2, 3];
|
||||||
|
const dataFormat = DataFormat.Raw;
|
||||||
|
const pagingRequest = new PagingRequest(1, 50);
|
||||||
|
|
||||||
|
const request = new QueryRecordsRequest(
|
||||||
|
appId,
|
||||||
|
filter,
|
||||||
|
fieldIds,
|
||||||
|
dataFormat,
|
||||||
|
pagingRequest
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(request).to.have.property('appId', appId);
|
||||||
|
expect(request).to.have.property('filter', filter);
|
||||||
|
expect(request).to.have.property('fieldIds', fieldIds);
|
||||||
|
expect(request).to.have.property('dataFormat', dataFormat);
|
||||||
|
expect(request).to.have.property('pagingRequest', pagingRequest);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user