@selfcommunity/api-services
Version:
Client api for SelfCommunity.
164 lines (156 loc) • 6.2 kB
JavaScript
import { __awaiter } from "tslib";
import Endpoints from '../../constants/Endpoints';
import { apiRequest } from '../../utils/apiRequest';
import { urlParams } from '../../utils/url';
/**
* Contains all the endpoints needed to manage legal pages.
*/
export class LegalPageApiClient {
/**
* This endpoint retrieves all legal pages.
* @param params
* @param config
*/
static getLegalPages(params, config) {
const p = urlParams(params);
return apiRequest(Object.assign(Object.assign({}, config), { url: `${Endpoints.GetLegalPages.url({})}?${p.toString()}`, method: Endpoints.GetLegalPages.method }));
}
/**
* This endpoint retrieves a specific legal page.
* @param id
* @param config
*/
static getSpecificLegalPage(id, config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.LegalPage.url({ id }), method: Endpoints.LegalPage.method }));
}
/**
* This endpoint retrieves all revisions of a legal page.
* @param policy
* @param config
*/
static getAllRevisionsOfLegalPage(policy, config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.LegalPageRevisions.url({ policy }), method: Endpoints.LegalPageRevisions.method }));
}
/**
* This endpoint retrieves all last revisions of legal pages.
*/
static getAllLastRevisionsOfLegalPages(config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.LegalPagesLastRevision.url({}), method: Endpoints.LegalPagesLastRevision.method }));
}
/**
* This endpoint retrieves last revision of a legal page.
* @param policy
* @param config
*/
static getLastRevisionOfLegalPage(policy, config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.LegalPageLastRevision.url({ policy }), method: Endpoints.LegalPageLastRevision.method }));
}
/**
* This endpoint performs search of a Legal Page.
* @param params
* @param config
*/
static searchLegalPages(params, config) {
const p = urlParams(params);
return apiRequest(Object.assign(Object.assign({}, config), { url: `${Endpoints.SearchLegalPages.url({})}?${p.toString()}`, method: Endpoints.SearchLegalPages.method }));
}
/**
*
* @param id
* @param accept Accept or not accept a legal page, valid values are: ('true', 'on', '1').
* @param config
*/
static ackLegalPage(id, accept, config) {
var _a;
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.AckLegalPage.url({ id }), method: Endpoints.AckLegalPage.method, data: (_a = { accept: accept }) !== null && _a !== void 0 ? _a : null }));
}
/**
* This endpoint retrieves a specific user ack.
* @param id
* @param config
*/
static getSpecificUserAck(id, config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.SpecificUserAck.url({ id }), method: Endpoints.SpecificUserAck.method }));
}
/**
* This endpoint retrieves all user acks.
*/
static userAckList(config) {
return apiRequest(Object.assign(Object.assign({}, config), { url: Endpoints.UserAckList.url({}), method: Endpoints.UserAckList.method }));
}
}
/**
*
:::tip LegalPage service can be used in the following way:
```jsx
1. Import the service from our library:
import {LegalPageService} from "@selfcommunity/api-services";
```
```jsx
2. Create a function and put the service inside it!
The async function `getLegalPages` will return the paginated list of legal pages.
async getLegalPages() {
return await LegalPageService.getLegalPages();
}
```
```jsx
In case of required `params`, just add them inside the brackets.
async getSpecificLegalPage(legalPageId) {
return await LegalPageService.getSpecificLegalPage(legalPageId);
}
```
```jsx
If you need to customize the request, you can add optional config params (`AxiosRequestConfig` type).
1. Declare it(or declare them, it is possible to add multiple params)
const headers = headers: {Authorization: `Bearer ${yourToken}`}
2. Add it inside the brackets and pass it to the function, as shown in the previous example!
```
:::
*/
export default class LegalPageService {
static getLegalPages(params, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getLegalPages(params, config);
});
}
static getSpecificLegalPage(id, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getSpecificLegalPage(id, config);
});
}
static getAllRevisionsOfLegalPage(policy, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getAllRevisionsOfLegalPage(policy, config);
});
}
static getAllLastRevisionsOfLegalPages(config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getAllLastRevisionsOfLegalPages(config);
});
}
static getLastRevisionOfLegalPage(policy, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getLastRevisionOfLegalPage(policy, config);
});
}
static searchLegalPages(params, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.searchLegalPages(params, config);
});
}
static ackLegalPage(id, accept, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.ackLegalPage(id, accept, config);
});
}
static getSpecificUserAck(id, config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.getSpecificUserAck(id, config);
});
}
static userAckList(config) {
return __awaiter(this, void 0, void 0, function* () {
return LegalPageApiClient.userAckList(config);
});
}
}