Skip to content

Commit 74972c3

Browse files
authored
Merge pull request #78 from KasualBusiness/develop
v1.5.1
2 parents 566d126 + 281e4cb commit 74972c3

22 files changed

+1316
-944
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"prettier/prettier": [
2020
"error",
2121
{
22-
"singleQuote": true
22+
"singleQuote": true,
23+
"trailingComma": "none"
2324
}
2425
]
2526
}

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@ const listProducts = async () => {
258258

259259
Operator can be `'start'`, `'end'`, `'contains'` and `'strict'`.
260260

261-
## Tests
262-
263-
```bash
264-
npm run test
265-
```
261+
### References
266262

267263
#### addresses
268264

@@ -1017,3 +1013,9 @@ npm run test
10171013
| `create` | body, CustomParams | Create on custom endpoint |
10181014
| `update` | id, body, CustomParams | Update on custom endpoint by id |
10191015
| `delete` | id, body, CustomParams | Delete on custom endpoint by id |
1016+
1017+
## Tests
1018+
1019+
```bash
1020+
npm run test
1021+
```

package-lock.json

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

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kasual-business/prestashop-api",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Prestashop node API",
55
"keywords": [
66
"prestashop",
@@ -44,19 +44,19 @@
4444
"author": "Kasual Business",
4545
"license": "MIT",
4646
"devDependencies": {
47-
"@types/qs": "^6.9.7",
48-
"@typescript-eslint/eslint-plugin": "^5.59.8",
49-
"@typescript-eslint/parser": "^5.57.0",
50-
"eslint": "^8.43.0",
51-
"eslint-config-prettier": "^8.8.0",
52-
"eslint-plugin-prettier": "^4.2.1",
53-
"nock": "^13.3.1",
54-
"prettier": "2.8.7",
55-
"typescript": "^5.0.2",
56-
"vitest": "^0.29.8"
47+
"@types/qs": "^6.9.8",
48+
"@typescript-eslint/eslint-plugin": "^6.8.0",
49+
"@typescript-eslint/parser": "^6.8.0",
50+
"eslint": "^8.51.0",
51+
"eslint-config-prettier": "^9.0.0",
52+
"eslint-plugin-prettier": "^5.0.1",
53+
"nock": "^13.3.4",
54+
"prettier": "^3.0.3",
55+
"typescript": "^5.2.2",
56+
"vitest": "^0.34.6"
5757
},
5858
"dependencies": {
59-
"axios": "^1.4.0",
59+
"axios": "^1.5.1",
6060
"qs": "^6.11.2",
6161
"xmlbuilder2": "^3.1.1"
6262
}

src/classes/base.class.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
GetParams,
55
PostParams,
66
PutParams,
7-
DeleteParams,
7+
DeleteParams
88
} from '../types/global.type';
99
import {
1010
listCall,
@@ -13,15 +13,15 @@ import {
1313
putCall,
1414
deleteCall,
1515
getSchemaCall,
16-
findCall,
16+
findCall
1717
} from '../utils/calls';
1818
import {
1919
PrestashopAPIDeleteResponse,
20-
PrestashopAPIResponse,
20+
PrestashopAPIResponse
2121
} from '../types/calls.type';
2222
import {
2323
handleBodyCreateUpdateAssociations,
24-
handleCreateUpdateMultiLanguagesFields,
24+
handleCreateUpdateMultiLanguagesFields
2525
} from '../utils/handlers';
2626
import { KEYS_TO_DELETE_WHEN_UPDATING } from '../utils/consts';
2727

@@ -124,7 +124,7 @@ export class Base<T> {
124124
// Pre-merge key deletation, some keys block the update of an item
125125
const listOfKeysToExclude = [
126126
...keysToDelete,
127-
...KEYS_TO_DELETE_WHEN_UPDATING,
127+
...KEYS_TO_DELETE_WHEN_UPDATING
128128
];
129129

130130
listOfKeysToExclude.forEach(

src/classes/custom.class.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class Custom<Response> {
2020
const response = await customCall<Response>({
2121
method: 'GET',
2222
path: `/${this.endpoint}`,
23-
params,
23+
params
2424
});
2525

2626
return response;
@@ -40,7 +40,7 @@ export class Custom<Response> {
4040
const response = await customCall<Response>({
4141
method: 'GET',
4242
path: `/${this.endpoint}${id ? `/${id}` : ''}`,
43-
params,
43+
params
4444
});
4545

4646
return response;
@@ -61,7 +61,7 @@ export class Custom<Response> {
6161
method: 'POST',
6262
path: `/${this.endpoint}`,
6363
body,
64-
params,
64+
params
6565
});
6666

6767
return response;
@@ -83,7 +83,7 @@ export class Custom<Response> {
8383
method: 'PUT',
8484
path: `/${this.endpoint}${id ? `/${id}` : ''}`,
8585
body,
86-
params,
86+
params
8787
});
8888

8989
return response;
@@ -103,7 +103,7 @@ export class Custom<Response> {
103103
const response = await customCall<Response, Body>({
104104
method: 'DELETE',
105105
path: `/${this.endpoint}${id ? `/${id}` : ''}`,
106-
params,
106+
params
107107
});
108108

109109
return response;

src/classes/images.class.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Images {
3030
const response: AxiosResponse = await call({
3131
method: 'POST',
3232
path: `/images/${type}/${itemId}`,
33-
body: formData,
33+
body: formData
3434
}).catch((error) => {
3535
return error.response;
3636
});
@@ -46,7 +46,7 @@ export class Images {
4646
method: 'POST',
4747
path: `/images/${type}/${itemId}`,
4848
body: formData,
49-
headers: formData.getHeaders(),
49+
headers: formData.getHeaders()
5050
}).catch((error) => {
5151
return error.response;
5252
});
@@ -73,7 +73,7 @@ export class Images {
7373
const response = await customCall<ArrayBuffer>({
7474
method: 'GET',
7575
path: `/images/${type}/${itemId}/${imageId}`,
76-
responseType: 'arraybuffer',
76+
responseType: 'arraybuffer'
7777
});
7878

7979
return response;
@@ -96,7 +96,7 @@ export class Images {
9696
): Promise<PrestashopAPIDeleteResponse | undefined> => {
9797
const response = await customCall<PrestashopAPIDeleteResponse>({
9898
method: 'DELETE',
99-
path: `/images/${type}/${itemId}/${imageId}`,
99+
path: `/images/${type}/${itemId}/${imageId}`
100100
});
101101

102102
return response;

src/classes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './custom.class';
33
export * from './images.class';
44
export * from './stock-movements.class';
55
export * from './stocks.class';
6+
export * from './search.class';

src/classes/search.class.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
PrestashopAPIResponse,
3+
SearchParams,
4+
SearchResponse
5+
} from '../types/calls.type';
6+
import { customCall } from '../utils/calls';
7+
8+
export class Search {
9+
/**
10+
* Search function.
11+
*
12+
* @param params
13+
* @returns
14+
*/
15+
find = async (
16+
params: SearchParams | undefined = {
17+
value: '',
18+
languageId: -1
19+
}
20+
): Promise<PrestashopAPIResponse<SearchResponse>> => {
21+
const searchParams = new URLSearchParams();
22+
23+
searchParams.append('query', params.value);
24+
searchParams.append('language', params.languageId.toString());
25+
26+
const response = await customCall<Partial<SearchResponse>>({
27+
method: 'GET',
28+
path: '/search',
29+
params: {
30+
customSearchParams: searchParams
31+
}
32+
});
33+
34+
return {
35+
data: {
36+
products: response?.products || [],
37+
categories: response?.categories || []
38+
},
39+
errors: response?.errors
40+
};
41+
};
42+
}

src/classes/stock-movements.class.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
GetParams,
55
ListParams,
66
PostParams,
7-
PutParams,
7+
PutParams
88
} from '../types/global.type';
99
import {
1010
PrestashopAPIResponse,
11-
StockMovementsResponse,
11+
StockMovementsResponse
1212
} from '../types/calls.type';
1313
import { customCall } from '../utils/calls';
1414

@@ -25,12 +25,12 @@ export class StockMovements {
2525
const response = await customCall<Partial<StockMovementsResponse>>({
2626
method: 'GET',
2727
path: '/stock_mvt',
28-
params,
28+
params
2929
});
3030

3131
return {
3232
data: response?.stock_movements || [],
33-
errors: response?.errors,
33+
errors: response?.errors
3434
};
3535
};
3636

@@ -48,19 +48,19 @@ export class StockMovements {
4848
const response = await customCall<StockMovementsResponse>({
4949
method: 'GET',
5050
path: `/stock_mvt/${id}`,
51-
params,
51+
params
5252
});
5353

5454
if (response?.stock_movements && response?.stock_movements.length > 0) {
5555
return {
5656
data: response?.stock_movements[0] || [],
57-
errors: response?.errors,
57+
errors: response?.errors
5858
};
5959
}
6060

6161
return {
6262
data: undefined,
63-
errors: response?.errors,
63+
errors: response?.errors
6464
};
6565
};
6666

@@ -79,19 +79,19 @@ export class StockMovements {
7979
method: 'POST',
8080
path: '/stock_mvt',
8181
body: { stock_mvt: body },
82-
params,
82+
params
8383
});
8484

8585
if (response?.stock_movements && response?.stock_movements.length > 0) {
8686
return {
8787
data: response?.stock_movements[0] || [],
88-
errors: response?.errors,
88+
errors: response?.errors
8989
};
9090
}
9191

9292
return {
9393
data: undefined,
94-
errors: response?.errors,
94+
errors: response?.errors
9595
};
9696
};
9797

@@ -112,19 +112,19 @@ export class StockMovements {
112112
method: 'PUT',
113113
path: `/stock_mvt/${id}`,
114114
body: { stock_mvt: body },
115-
params,
115+
params
116116
});
117117

118118
if (response?.stock_movements && response?.stock_movements.length > 0) {
119119
return {
120120
data: response?.stock_movements[0] || [],
121-
errors: response?.errors,
121+
errors: response?.errors
122122
};
123123
}
124124

125125
return {
126126
data: undefined,
127-
errors: response?.errors,
127+
errors: response?.errors
128128
};
129129
};
130130

@@ -142,19 +142,19 @@ export class StockMovements {
142142
const response = await customCall<StockMovementsResponse>({
143143
method: 'DELETE',
144144
path: `/stock_mvt/${id}`,
145-
params,
145+
params
146146
});
147147

148148
if (response?.stock_movements && response?.stock_movements.length > 0) {
149149
return {
150150
data: response?.stock_movements[0] || [],
151-
errors: response?.errors,
151+
errors: response?.errors
152152
};
153153
}
154154

155155
return {
156156
data: undefined,
157-
errors: response?.errors,
157+
errors: response?.errors
158158
};
159159
};
160160
}

0 commit comments

Comments
 (0)