Skip to content

Commit

Permalink
improve FileInfo class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 29, 2024
1 parent eca2476 commit b981d5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
24 changes: 14 additions & 10 deletions src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,38 @@ 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
},
'PUT'
);
}

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');
}
}

Expand Down
18 changes: 2 additions & 16 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default class ApiHandler {
} else {
console.error('Other error:', error);
}

return undefined;
});
}

Expand All @@ -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');
};
Expand All @@ -104,9 +95,4 @@ export default class ApiHandler {
'POST'
);
};

// Get all users in a document
getMembers = (documentId: string) => {
return this.callApi('/documents/' + documentId + '/users');
};
}

0 comments on commit b981d5f

Please sign in to comment.