Skip to content

Commit

Permalink
Merge pull request #8 from koopjs/p/fix-single-values
Browse files Browse the repository at this point in the history
fix: handle single number of string values for object ids
  • Loading branch information
rgwozdz authored Nov 15, 2023
2 parents d8f77e9 + 2551493 commit ec0c9c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @koopjs/geoservice-utils

## Unreleased
### Fixed
- handle single number of string values for object ids

## 2.2.0
### Added
- parse incoming geometry strings as JSON if possible in order to support GET requests
Expand Down
15 changes: 15 additions & 0 deletions src/combine-objectids-and-where/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ describe('combine-object-ids-and-where', () => {
expect(clause).toBe('(OBJECTID IN (\'a\',\'b\'))');
});

it('should return clause with string objectIds as single string', () => {
const clause = combineObjectIdsAndWhere({ objectIds: 'foo' })
expect(clause).toBe('(OBJECTID IN (\'foo\'))');
});

it('should return clause with stringifed number objectIds as single number', () => {
const clause = combineObjectIdsAndWhere({ objectIds: '123' })
expect(clause).toBe('(OBJECTID IN (123))');
});

it('should return clause with objectIds as single number', () => {
const clause = combineObjectIdsAndWhere({ objectIds: 123 })
expect(clause).toBe('(OBJECTID IN (123))');
});

it('should return clause with objectIds string and default idField', () => {
const clause = combineObjectIdsAndWhere({ objectIds: '1,2,3', idField: '_id' })
expect(clause).toBe('(_id IN (1,2,3))');
Expand Down
8 changes: 6 additions & 2 deletions src/combine-objectids-and-where/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function combineObjectIdsAndWhere(
}

function normalizeObjectIds(
objectIds: string | string[] | number[],
objectIds: string | string[] | number | number[],
): string[] | number[] {
return Array.isArray(objectIds) ? objectIds : objectIds.split(',');
if (Array.isArray(objectIds)) {
return objectIds
}

return (typeof objectIds === 'string') ? objectIds.split(',') : [objectIds];
}

0 comments on commit ec0c9c8

Please sign in to comment.