From b981d5f4e372f7e6c88758c62f9151e291dd1091 Mon Sep 17 00:00:00 2001 From: Ell1ott <85990359+Ell1ott@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:35:07 +0100 Subject: [PATCH] improve FileInfo class --- src/lib/api/apiStore.ts | 24 ++++++++++++++---------- src/lib/api/index.ts | 18 ++---------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/lib/api/apiStore.ts b/src/lib/api/apiStore.ts index 5790622d..4e6dfe0a 100644 --- a/src/lib/api/apiStore.ts +++ b/src/lib/api/apiStore.ts @@ -12,21 +12,29 @@ export class FileInfo { apiPath: string = '/documents/'; - getPath() { + constructor(info) { + this.id = info.id; + this.name = info.name; + this.data = info.data; + this.created_at = info.created_at; + this.updated_at = info.updated_at; + } + + get path() { return this.apiPath + this.id; } rename(newName: string, api: ApiHandler) { - return api.callApi(this.getPath(), { name: newName }, 'PUT'); + return api.callApi(this.path, { name: newName }, 'PUT'); } delete(api: ApiHandler) { - return api.callApi(this.getPath(), {}, 'DELETE'); + return api.callApi(this.path, {}, 'DELETE'); } addUser(user_email: string, api: ApiHandler) { return api.callApi( - this.getPath() + '/users', + this.path + '/users', { user_email }, @@ -34,12 +42,8 @@ export class FileInfo { ); } - constructor(info) { - this.id = info.id; - this.name = info.name; - this.data = info.data; - this.created_at = info.created_at; - this.updated_at = info.updated_at; + getMembers(api: ApiHandler) { + return api.callApi(this.path + '/users'); } } diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index c105ab9c..cc21fc96 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -53,6 +53,8 @@ export default class ApiHandler { } else { console.error('Other error:', error); } + + return undefined; }); } @@ -78,17 +80,6 @@ export default class ApiHandler { 'POST' ); }; - - addUserToDocument = (documentId: string, user_email: string) => { - return this.callApi( - '/documents/' + documentId + '/users', - { - user_email - }, - 'PUT' - ); - }; - getAssignments = () => { return this.callApi('/assignments'); }; @@ -104,9 +95,4 @@ export default class ApiHandler { 'POST' ); }; - - // Get all users in a document - getMembers = (documentId: string) => { - return this.callApi('/documents/' + documentId + '/users'); - }; }