Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-llamas-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@musica-sacra/api": major
---

Fix type of getList method. Add helpers for stringifying params for axios requests.
5 changes: 5 additions & 0 deletions .changeset/tangy-brooms-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@musica-sacra/api": major
---

Create new plugin musica-sacra/api
9 changes: 8 additions & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# @musica-sacra/api
# @musica-sacra/api

ReactQuery and Axios based complex system that provides classes and hooks for handling API requests.
With typescript support.

## Installation

`npm install @musica-sacra/api`
7 changes: 7 additions & 0 deletions packages/api/src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function stringifyArrayParam(
paramValues?: (string | number | boolean)[]
) {
if (!paramValues) return '';

return paramValues.map(String).join(',');
}
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useGetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import { useQuery } from '@tanstack/react-query';
import { BaseService } from '../service/BaseService';

export function useGetList<T = any>(

Check warning on line 9 in packages/api/src/hooks/useGetList.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 9 in packages/api/src/hooks/useGetList.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
url: string,
key: string,
params?: Record<string, any>
params?: Record<string, string>
) {
const { addNotification } = useContext(NotificationsContext);

Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { useGetById } from './hooks/useGetById';

export { AbstractService } from './service/AbstractService';
export { BaseService } from './service/BaseService';

export { stringifyArrayParam } from './helpers/helpers';
2 changes: 1 addition & 1 deletion packages/api/src/service/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AbstractService } from './AbstractService';
import axios from 'axios';

type WithItems<T, R = Record<string, any>> = { items: T[] } & R;

Check warning on line 4 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 4 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

export class BaseService<
T = any,

Check warning on line 7 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 7 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
R = Record<string, any>,

Check warning on line 8 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 8 in packages/api/src/service/BaseService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
> extends AbstractService {
async getList(url: string, params?: Record<string, any>) {
async getList(url: string, params?: Record<string, string>) {
return await axios.get<WithItems<T, R>>(url, {
params,
...this.getHeaders(),
Expand Down