Skip to content

Commit b8ed711

Browse files
authored
Merge pull request #186 from StatelessStudio/v3.0.3
[3.0.3] Jul-23-2019
2 parents 6a6f182 + 72e5ed8 commit b8ed711

6 files changed

Lines changed: 22 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# PointyApi Changelog
22

3+
## [3.0.3] Jul-23-2019
4+
5+
### Fixes
6+
- runHook should return result set
7+
- Duplicate Key Value should output column name
8+
39
## [3.0.2] Jul-14-2019
410

511
### Fixes

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pointyapi",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"author": "stateless-studio",
55
"license": "MIT",
66
"scripts": {
@@ -26,7 +26,7 @@
2626
"@types/btoa": "^1.2.3",
2727
"@types/express": "^4.17.0",
2828
"@types/jsonwebtoken": "^7.2.8",
29-
"@types/node": "^10.14.12",
29+
"@types/node": "^10.14.13",
3030
"@types/request": "^2.48.2",
3131
"atob": "^2.1.2",
3232
"bcryptjs": "^2.4.3",

src/handlers/error-handler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function errorHandler(error: any, code: number = 500): void {
1717
{
1818
property: error.column,
1919
constraints: {
20-
"isNotNull": error.message
20+
isNotNull: error.message
2121
}
2222
}
2323
]);
@@ -30,7 +30,9 @@ export function errorHandler(error: any, code: number = 500): void {
3030
}
3131
else if (error.code === 23505) {
3232
// Duplicate key value
33-
this.response.conflictResponder('Duplicate Key Value');
33+
this.response.conflictResponder(
34+
'Duplicate Key Value: ' + error.detail
35+
);
3436
return;
3537
}
3638
}

src/utils/run-hook.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function runHook(
1717
): Promise<boolean> {
1818
// Run model hook
1919
let hookResult = false;
20+
let resultset;
2021
const promises = [];
2122

2223
if (obj instanceof Array) {
@@ -33,6 +34,7 @@ export async function runHook(
3334
await Promise.all(promises)
3435
.then((results) => {
3536
hookResult = true;
37+
resultset = results;
3638

3739
for (let i = 0; i < results.length; i++) {
3840
if (!results[i]) {
@@ -57,5 +59,5 @@ export async function runHook(
5759
console.warn('Could not complete hook "' + name + '" on object: ', obj);
5860
}
5961

60-
return hookResult;
62+
return hookResult ? resultset : false;
6163
}

test/spec/api/utils/run-hook.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('[Utils] runHook()', () => {
5858
response
5959
);
6060

61-
expect(result).toBe(true);
61+
expect(result).toBeTruthy();
6262
});
6363

6464
it('calls response.error if the hook does not return true', async () => {
@@ -143,7 +143,7 @@ describe('[Utils] runHook()', () => {
143143
response
144144
);
145145

146-
expect(result).toBe(true);
146+
expect(result).toBeTruthy();
147147
expect(tester.password).toEqual('bob');
148148
});
149149

@@ -158,7 +158,7 @@ describe('[Utils] runHook()', () => {
158158
response
159159
);
160160

161-
expect(result).toBe(true);
161+
expect(result).toBeTruthy();
162162
expect(testers[0].password).toEqual('bob');
163163
expect(testers[1].password).toEqual('bob');
164164
});

0 commit comments

Comments
 (0)