Skip to content

Commit 2fb42cc

Browse files
authored
Merge pull request #72 from StatelessStudio/v0.5.1
V0.5.1
2 parents dd8e301 + 7aee528 commit 2fb42cc

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# PointyApi Changelog
22

3+
## [0.5.1] Dec-31-2018
4+
5+
### Fixes
6+
- [Issue #71] Object alias (mnemonic) must be prepended if join tables exist, but this field isn't from a join
7+
38
## [0.5.0] Dec-31-2018
49

510
Created `CanSearchRelation()` decorator and fixed relation search bugs

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pointyapi",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"author": "stateless-studio",
55
"license": "MIT",
66
"scripts": {

src/middleware/get-query.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export async function getQuery(
303303
.select(readableFields);
304304

305305
// Loop through join tables
306+
const hasJoinMembers = request.joinMembers.length > 0;
306307
for (const table of request.joinMembers) {
307308
selection = await selection.leftJoinAndSelect(
308309
`${objMnemonic}.${table}`,
@@ -321,7 +322,15 @@ export async function getQuery(
321322

322323
// Add order by keys
323324
for (let i = 0; i < orderByKeys.length; i++) {
324-
query.addOrderBy(orderByKeys[i], orderByOrders[i]);
325+
let key = orderByKeys[i];
326+
327+
// Object alias must be prepended if join tables exist,
328+
// but this field isn't from a join
329+
if (hasJoinMembers && !key.includes('.')) {
330+
key = 'obj.' + key;
331+
}
332+
333+
query.addOrderBy(key, orderByOrders[i]);
325334
}
326335

327336
// Add limit

test/spec/chat/chat/chat-get.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,28 @@ describe('[Chat] Chat API Get', async () => {
431431
})
432432
.catch((error) => fail(JSON.stringify(error)));
433433
});
434+
435+
it('can sort by member when a join column is included', async () => {
436+
await http
437+
.get(
438+
'/api/v1/chat',
439+
{
440+
__search: '',
441+
__orderBy: {
442+
id: 'ASC'
443+
}
444+
},
445+
[ 200 ],
446+
this.token.body.token
447+
)
448+
.then((result) => {
449+
if (result.body instanceof Array) {
450+
expect(result.body.length).toBeGreaterThanOrEqual(2);
451+
}
452+
else {
453+
fail('Result is not an array');
454+
}
455+
})
456+
.catch((error) => JSON.stringify(error));
457+
});
434458
});

0 commit comments

Comments
 (0)