diff --git a/packages/client/src/api.tsx b/packages/client/src/api.tsx index 150e72a1f..364af95d7 100644 --- a/packages/client/src/api.tsx +++ b/packages/client/src/api.tsx @@ -21,7 +21,10 @@ import { IUser, Relation, RequestPermissionUpdate, + IRequestStats, + IAudit, } from "@shared/types"; +import { ISetting, ISettingGroup } from "@shared/types/settings"; import * as errors from "@shared/types/errors"; import { NetworkError } from "@shared/types/errors"; import { IRequestSearch } from "@shared/types/request-search"; @@ -674,7 +677,8 @@ class Api { entityIds: string[], options?: IApiOptions ): Promise<(EntitiesDeleteSuccessResponse | EntitiesDeleteErrorResponse)[]> { - const out: (EntitiesDeleteSuccessResponse | EntitiesDeleteErrorResponse)[] = []; + const out: (EntitiesDeleteSuccessResponse | EntitiesDeleteErrorResponse)[] = + []; try { const response = await this.connection.delete(`/entities/`, { data: { @@ -682,13 +686,21 @@ class Api { }, ...options, }); - const data = (response.data as IResponseGeneric>).data; + const data = ( + response.data as IResponseGeneric< + Record + > + ).data; if (data) { for (const errorEntityId of Object.keys(data)) { if (data[errorEntityId] === true) { out.push({ entityId: errorEntityId, details: data[errorEntityId] }); } else { - out.push({ entityId: errorEntityId, error: true, details: data[errorEntityId] }); + out.push({ + entityId: errorEntityId, + error: true, + details: data[errorEntityId], + }); } } } @@ -851,6 +863,21 @@ class Api { } } + /** + * Stats + */ + async statsGet( + data: IRequestStats, + options?: IApiOptions + ): Promise> { + try { + const response = await this.connection.post(`/stats`, data, options); + return response; + } catch (err) { + throw this.handleError(err); + } + } + /** * Audit */ @@ -869,6 +896,20 @@ class Api { } } + async auditGetFirst( + options?: IApiOptions + ): Promise>> { + try { + const response = await this.connection.get( + `/audits?skip=0&take=1&from=1970`, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + /** * Statement * Editor container @@ -1218,6 +1259,40 @@ class Api { } } + async documentRemoveAnchors( + documentId: string, + entityId: string, + options?: IApiOptions + ): Promise> { + try { + const response = await this.connection.patch( + `/documents/${documentId}/removeAnchors?entityId=${entityId}`, + document, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + + async documentRemoveAnchor( + documentId: string, + entityId: string, + anchorText: string, + anchorIndex: number, + options?: IApiOptions + ): Promise> { + try { + // todo add api endpoint + + // @ts-ignore + return null; + } catch (err) { + throw this.handleError(err); + } + } + /** * Document update */ @@ -1237,6 +1312,113 @@ class Api { throw this.handleError(err); } } + + /** + * Setting get + * @param settingId + * @param options + * @returns + */ + async settingGet( + settingId: string, + options?: IApiOptions + ): Promise>> { + try { + const response = await this.connection.get( + `/settings/${settingId}`, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + + /** + * Setting group get + * @param settingId + * @param options + * @returns + */ + async settingGroupGet( + settingGroupId: string, + options?: IApiOptions + ): Promise>> { + try { + const response = await this.connection.get( + `/settings/group/${settingGroupId}`, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + + /** + * Setting group get + * @param settingId + * @param data + * @param options + * @returns + */ + async settingGroupUpdate( + settingGroupId: string, + data: { id: string; value: unknown }[], + options?: IApiOptions + ): Promise>> { + try { + const response = await this.connection.put( + `/settings/group/${settingGroupId}`, + data, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + + /** + * Setting update + * @param settingId + * @param data + * @param options + * @returns + */ + async settingUpdate( + settingId: string, + data: { value: unknown }, + options?: IApiOptions + ): Promise> { + try { + const response = await this.connection.put( + `/settings/${settingId}`, + data, + options + ); + return response; + } catch (err) { + throw this.handleError(err); + } + } + + /** + * Get owner's info + * @param settingId + * @param options + * @returns + */ + async usersGetOwner( + options?: IApiOptions + ): Promise>> { + try { + const response = await this.connection.get(`/users/owner`, options); + return response; + } catch (err) { + throw this.handleError(err); + } + } } const apiSingleton = new Api(); diff --git a/packages/client/src/components/advanced/Annotator/Annotator.tsx b/packages/client/src/components/advanced/Annotator/Annotator.tsx index ade26754a..15706a007 100644 --- a/packages/client/src/components/advanced/Annotator/Annotator.tsx +++ b/packages/client/src/components/advanced/Annotator/Annotator.tsx @@ -539,7 +539,7 @@ export const TextAnnotator = ({ {annotator && ( - +