Skip to content

Commit bd77925

Browse files
authored
Merge pull request #212 from StatelessStudio/v3.3.5
[3.3.5] May-02-2021
2 parents 1564779 + 88140bc commit bd77925

8 files changed

Lines changed: 554 additions & 296 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.3.5] May-02-2021
4+
5+
### Fixes
6+
- npm update
7+
- Fix typescript build errors
8+
39
## [3.3.4] Mar-15-2021
410

511
### Fixes

package-lock.json

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

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pointyapi",
3-
"version": "3.3.4",
3+
"version": "3.3.5",
44
"author": "stateless-studio",
55
"license": "MIT",
66
"scripts": {
@@ -24,38 +24,38 @@
2424
"dependencies": {
2525
"@types/atob": "^2.1.2",
2626
"@types/btoa": "^1.2.3",
27-
"@types/express": "^4.17.3",
28-
"@types/jsonwebtoken": "^8.3.8",
29-
"@types/node": "^12.12.32",
30-
"@types/request": "^2.48.4",
27+
"@types/express": "^4.17.11",
28+
"@types/jsonwebtoken": "^8.5.1",
29+
"@types/node": "^12.20.11",
30+
"@types/request": "^2.48.5",
3131
"atob": "^2.1.2",
3232
"bcryptjs": "^2.4.3",
3333
"btoa": "^1.2.1",
3434
"class-validator": "^0.11.1",
3535
"express": "^4.17.1",
3636
"jsonwebtoken": "^8.5.1",
37-
"mock-req-res": "^1.1.4",
37+
"mock-req-res": "^1.2.0",
3838
"pg": "^7.18.2",
39-
"pg-connection-string": "^2.2.0",
39+
"pg-connection-string": "^2.5.0",
4040
"reflect-metadata": "^0.1.13",
4141
"request": "^2.88.2",
4242
"sinon": "^7.5.0",
43-
"typeorm": "^0.2.24",
43+
"typeorm": "^0.2.32",
4444
"validator": "^12.2.0"
4545
},
4646
"main": "./index.js",
4747
"types": "./index.d.ts",
4848
"devDependencies": {
4949
"@istanbuljs/nyc-config-typescript": "^0.1.3",
50-
"@types/jasmine": "^3.5.10",
51-
"coveralls": "^3.0.11",
52-
"jasmine": "^3.5.0",
50+
"@types/jasmine": "^3.6.10",
51+
"coveralls": "^3.1.0",
52+
"jasmine": "^3.7.0",
5353
"nyc": "^14.1.1",
54-
"source-map-support": "^0.5.16",
55-
"ts-node": "^8.8.1",
54+
"source-map-support": "^0.5.19",
55+
"ts-node": "^8.10.2",
5656
"tslint": "^5.20.1",
5757
"tslint-eslint-rules": "^5.4.0",
58-
"typescript": "^3.8.3"
58+
"typescript": "^3.9.9"
5959
},
6060
"description": "*\"Stop writing endpoints\"*",
6161
"directories": {

src/database/base-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ export class BaseDb {
3737

3838
// Create database connection
3939
public async connect(options: string | Object): Promise<any> {
40-
return new Promise((accept) => accept());
40+
return new Promise((accept) => accept(null));
4141
}
4242
}

src/middleware/basic-cors.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export function basicCors(
2626
let host = request.headers.origin;
2727
const clientUrls = process.env.ALLOW_ORIGIN.split(', ');
2828

29-
if (host instanceof Array) {
30-
host = host[0];
31-
}
32-
3329
if (clientUrls.includes(host)) {
3430
origin = host;
3531
}

src/query-tools/get-query.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Request, Response } from 'express';
22
import { getReadableFields, getBodyguardKeys } from '../bodyguard';
33

44
import { createSearchQuery } from '../utils';
5+
import { Query } from './query';
56

67
/**
78
* Get the objects represented by the request query
@@ -13,14 +14,16 @@ export async function getQuery(
1314
request: Request,
1415
response: Response
1516
): Promise<any> {
16-
if ('query' in request && 'id' in request.query && request.query.id) {
17+
const requestQueryParams: Query = request.query;
18+
19+
if ('id' in requestQueryParams && requestQueryParams.id) {
1720
// Read one
18-
return request.repository.findOne(request.query.id);
21+
return request.repository.findOne(requestQueryParams.id);
1922
}
20-
else if ('query' in request && Object.keys(request.query).length) {
23+
else if (Object.keys(requestQueryParams).length) {
2124
// Read query
2225

23-
const shouldCount = 'count' in request.query && request.query.count;
26+
const shouldCount = 'count' in requestQueryParams && requestQueryParams.count;
2427

2528
// Readable keys
2629
let readableFields = getReadableFields(
@@ -31,8 +34,8 @@ export async function getQuery(
3134

3235
// Extract select query keys
3336
const selectKeys = [];
34-
if ('select' in request.query) {
35-
for (let key of request.query.select) {
37+
if ('select' in requestQueryParams) {
38+
for (let key of requestQueryParams.select) {
3639
key = `obj.${key}`;
3740
selectKeys.push(key);
3841
}
@@ -41,8 +44,8 @@ export async function getQuery(
4144
}
4245

4346
// Extract Join join query keys
44-
if ('join' in request.query) {
45-
request.query.join.forEach((key) => {
47+
if ('join' in requestQueryParams) {
48+
requestQueryParams.join.forEach((key) => {
4649
if (!request.joinMembers.includes(key)) {
4750
request.joinMembers.push(key);
4851
}
@@ -51,15 +54,15 @@ export async function getQuery(
5154

5255
// Extract Group By query keys
5356
const groupByKeys = [];
54-
if ('groupBy' in request.query) {
55-
request.query.groupBy.forEach((key) => {
57+
if ('groupBy' in requestQueryParams) {
58+
requestQueryParams.groupBy.forEach((key) => {
5659
groupByKeys.push(key);
5760
});
5861

5962
// Add 'id' to array if not already
6063
if (
6164
readableFields.includes('obj.id') &&
62-
!('id' in request.query.groupBy)
65+
!('id' in requestQueryParams.groupBy)
6366
) {
6467
groupByKeys.push('id');
6568
}
@@ -68,11 +71,11 @@ export async function getQuery(
6871
// Extract order By query keys
6972
const orderByKeys = [];
7073
const orderByOrders = [];
71-
if ('orderBy' in request.query) {
72-
for (const key in request.query.orderBy) {
74+
if ('orderBy' in requestQueryParams) {
75+
for (const key in requestQueryParams.orderBy) {
7376
orderByKeys.push(key);
7477
orderByOrders.push(
75-
request.query.orderBy[key] === 'DESC' ? 'DESC' : 'ASC'
78+
requestQueryParams.orderBy[key] === 'DESC' ? 'DESC' : 'ASC'
7679
);
7780
}
7881
}
@@ -81,7 +84,7 @@ export async function getQuery(
8184
// tslint:disable-next-line:prefer-const
8285
let { queryString, queryParams } = createSearchQuery(
8386
request.payloadType,
84-
request.query
87+
requestQueryParams
8588
);
8689

8790
// Join bodyguard keys, unless this is the User
@@ -161,17 +164,17 @@ export async function getQuery(
161164
}
162165

163166
// Add limit
164-
if ('limit' in request.query && request.query.limit) {
165-
query.take(request.query.limit);
167+
if ('limit' in requestQueryParams && requestQueryParams.limit) {
168+
query.take(requestQueryParams.limit);
166169
}
167170

168171
// Add offset
169-
if ('offset' in request.query && request.query.offset) {
170-
query.skip(request.query.offset);
172+
if ('offset' in requestQueryParams && requestQueryParams.offset) {
173+
query.skip(requestQueryParams.offset);
171174
}
172175
}
173176

174-
if ('raw' in request.query && request.query.raw) {
177+
if ('raw' in requestQueryParams && requestQueryParams.raw) {
175178
return query.getRawMany();
176179
}
177180
else if (groupByKeys.length) {

src/query-tools/query-validator.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { queryTypes, queryTypeKeys } from './query-types';
44
import { getReadableFields, getReadableRelations } from '../bodyguard';
55
import { validateSync } from 'class-validator';
66
import { getValidationConstraints } from './get-validation-constraints';
7+
import { Query } from './query';
78

89
/**
910
* Validate a GET query type
@@ -27,13 +28,15 @@ function queryFieldValidator(
2728
request.user
2829
);
2930

30-
if (type in request.query) {
31-
if (request.query[type] instanceof Array) {
32-
for (let i = 0; i < request.query[type].length; i++) {
33-
const key = request.query[type][i];
31+
const requestQueryParams: Query = request.query;
32+
33+
if (type in requestQueryParams) {
34+
if (requestQueryParams[type] instanceof Array) {
35+
for (let i = 0; i < requestQueryParams[type].length; i++) {
36+
const key = requestQueryParams[type][i];
3437

3538
if (key === undefined) {
36-
request.query[type].splice(i, 1);
39+
requestQueryParams[type].splice(i, 1);
3740

3841
continue;
3942
}
@@ -60,14 +63,14 @@ function queryFieldValidator(
6063
}
6164
}
6265
}
63-
else if (request.query[type] instanceof Object) {
66+
else if (requestQueryParams[type] instanceof Object) {
6467
const validators = getValidationConstraints(request.payloadType);
6568

66-
for (const key in request.query[type]) {
67-
const value = request.query[type][key];
69+
for (const key in requestQueryParams[type]) {
70+
const value = requestQueryParams[type][key];
6871

6972
if (value === undefined) {
70-
delete request.query[type][key];
73+
delete requestQueryParams[type][key];
7174

7275
continue;
7376
}
@@ -112,7 +115,7 @@ function queryFieldValidator(
112115
const asInt = parseInt(value, 10);
113116

114117
if (!isNaN(asInt)) {
115-
request.query[type][key] = asInt;
118+
requestQueryParams[type][key] = asInt;
116119
}
117120
}
118121
}
@@ -129,7 +132,7 @@ function queryFieldValidator(
129132
) {
130133
const testObject = Object.assign(
131134
new request.payloadType(),
132-
request.query[type]
135+
requestQueryParams[type]
133136
);
134137

135138
const validationErrors = validateSync(testObject, {
@@ -149,15 +152,15 @@ function queryFieldValidator(
149152
);
150153

151154
if (validator && 'isInt' in validator && validator.isInt === true) {
152-
const asInt = parseInt(request.query.id, 10);
155+
const asInt = parseInt(`${requestQueryParams.id}`, 10);
153156

154157
if (!isNaN(asInt)) {
155-
request.query.id = asInt;
158+
requestQueryParams.id = asInt;
156159
}
157160
}
158161

159162
const testObject = Object.assign(new request.payloadType(), {
160-
id: request.query[type]
163+
id: requestQueryParams[type]
161164
});
162165

163166
const validationErrors = validateSync(testObject, {
@@ -182,10 +185,12 @@ function queryFieldValidator(
182185
* @return Returns if the get query is valid
183186
*/
184187
export function queryValidator(request: Request, response: Response): boolean {
185-
for (const type in request.query) {
188+
const requestQueryParams: Query = request.query;
189+
190+
for (const type in requestQueryParams) {
186191
// Is this defined?
187-
if (request.query[type] === undefined) {
188-
delete request.query[type];
192+
if (requestQueryParams[type] === undefined) {
193+
delete requestQueryParams[type];
189194

190195
continue;
191196
}
@@ -202,11 +207,11 @@ export function queryValidator(request: Request, response: Response): boolean {
202207
}
203208

204209
// Is query type proper (array, object, etc)?
205-
let queryTypeConstructor: string = typeof request.query[type];
210+
let queryTypeConstructor: string = typeof requestQueryParams[type];
206211

207212
if (
208213
queryTypeConstructor === 'object' &&
209-
'length' in request.query[type]
214+
'length' in requestQueryParams[type]
210215
) {
211216
queryTypeConstructor = 'array';
212217
}
@@ -221,7 +226,7 @@ export function queryValidator(request: Request, response: Response): boolean {
221226
']. It is: ' +
222227
queryTypeConstructor +
223228
'. Value: ' +
224-
request.query[type]
229+
requestQueryParams[type]
225230
);
226231
}
227232

src/query-tools/query.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface Query
2+
{
3+
id?: number|string,
4+
count?: boolean,
5+
raw?: boolean,
6+
select?: string[],
7+
join?: string[],
8+
search?: string,
9+
groupBy?: string[],
10+
orderBy?: object,
11+
limit?: number,
12+
offset?: number
13+
}

0 commit comments

Comments
 (0)