From efb5768a6ebfa20d742496c49cfe0cc9d8aa7c9d Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 22 Feb 2021 21:49:59 -0800 Subject: [PATCH] Complete support for share collabs --- .../src/classes/client/rest-client/index.ts | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/webapp/src/classes/client/rest-client/index.ts b/packages/webapp/src/classes/client/rest-client/index.ts index 2677886f..2ff26089 100644 --- a/packages/webapp/src/classes/client/rest-client/index.ts +++ b/packages/webapp/src/classes/client/rest-client/index.ts @@ -10,9 +10,19 @@ export default class RestClient implements Client { this.baseUrl = baseUrl; this.sessionExpired = sessionExpired; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars + deleteMapPermission(id: number, email: string): Promise { - throw new Error('Method not implemented.'); + const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { + axios.delete(`${this.baseUrl}/c/restful/maps/${id}/collabs?email=${email}`, + { headers: { 'Content-Type': 'text/plain' } } + ).then(() => { + success(); + }).catch(error => { + const errorInfo = this.parseResponseOnError(error.response); + reject(errorInfo); + }); + } + return new Promise(handler); } // eslint-disable-next-line @typescript-eslint/no-unused-vars addMapPermissions(id: number, message: string, permissions: Permission[]): Promise { @@ -38,8 +48,7 @@ export default class RestClient implements Client { fetchMapPermissions(id: number): Promise { const handler = (success: (labels: Permission[]) => void, reject: (error: ErrorInfo) => void) => { - axios.get( - this.baseUrl + `/c/restful/maps/${id}/collabs`, + axios.get(`${this.baseUrl}/c/restful/maps/${id}/collabs`, { headers: { 'Content-Type': 'text/plain' } } @@ -65,7 +74,7 @@ export default class RestClient implements Client { deleteAccount(): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.delete(this.baseUrl + `/c/restful/account`, + axios.delete(`${this.baseUrl}/c/restful/account`, { headers: { 'Content-Type': 'text/plain' } } ).then(() => { success(); @@ -131,7 +140,7 @@ export default class RestClient implements Client { importMap(model: ImportMapInfo): Promise { const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, + axios.post(`${this.baseUrl}/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, model.content, { headers: { 'Content-Type': model.contentType } } ).then(response => { @@ -147,8 +156,7 @@ export default class RestClient implements Client { fetchAccountInfo(): Promise { const handler = (success: (account: AccountInfo) => void, reject: (error: ErrorInfo) => void) => { - axios.get( - this.baseUrl + '/c/restful/account', + axios.get(`${this.baseUrl}/c/restful/account`, { headers: { 'Content-Type': 'application/json' } } @@ -171,7 +179,7 @@ export default class RestClient implements Client { deleteMaps(ids: number[]): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.delete(this.baseUrl + `/c/restful/maps/batch?ids=${ids.join()}`, + axios.delete(`${this.baseUrl}/c/restful/maps/batch?ids=${ids.join()}`, { headers: { 'Content-Type': 'text/plain' } } ).then(() => { success(); @@ -202,7 +210,7 @@ export default class RestClient implements Client { revertHistory(id: number, hid: number): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + `/maps/${id}/history/${hid}`, + axios.post(`${this.baseUrl}/maps/${id}/history/${hid}`, null, { headers: { 'Content-Type': 'text/pain' } } ).then(() => { @@ -243,7 +251,7 @@ export default class RestClient implements Client { createMap(model: BasicMapInfo): Promise { const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, + axios.post(`${this.baseUrl}/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, null, { headers: { 'Content-Type': 'application/json' } } ).then(response => { @@ -259,8 +267,7 @@ export default class RestClient implements Client { fetchAllMaps(): Promise { const handler = (success: (mapsInfo: MapInfo[]) => void, reject: (error: ErrorInfo) => void) => { - axios.get( - this.baseUrl + '/c/restful/maps/', + axios.get(`${this.baseUrl}/c/restful/maps/`, { headers: { 'Content-Type': 'application/json' } } @@ -298,7 +305,7 @@ export default class RestClient implements Client { registerNewUser(user: NewUser): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + '/service/users/', + axios.post(`${this.baseUrl}/service/users/`, JSON.stringify(user), { headers: { 'Content-Type': 'application/json' } } ).then(() => { @@ -316,7 +323,7 @@ export default class RestClient implements Client { deleteMap(id: number): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.delete(this.baseUrl + `/c/restful/maps/${id}`, + axios.delete( `${this.baseUrl}/c/restful/maps/${id}`, { headers: { 'Content-Type': 'application/json' } } ).then(() => { success(); @@ -349,7 +356,7 @@ export default class RestClient implements Client { duplicateMap(id: number, basicInfo: BasicMapInfo): Promise { const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { - axios.post(this.baseUrl + `/c/restful/maps/${id}`, + axios.post(`${this.baseUrl}/c/restful/maps/${id}`, JSON.stringify(basicInfo), { headers: { 'Content-Type': 'application/json' } } ).then(response => { @@ -366,7 +373,7 @@ export default class RestClient implements Client { updateStarred(id: number, starred: boolean): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`, + axios.put(`${this.baseUrl}/c/restful/maps/${id}/starred`, starred, { headers: { 'Content-Type': 'text/plain' } } ).then(() => { @@ -382,8 +389,7 @@ export default class RestClient implements Client { fetchLabels(): Promise { const handler = (success: (labels: Label[]) => void, reject: (error: ErrorInfo) => void) => { - axios.get( - this.baseUrl + '/c/restful/labels/', + axios.get(`${this.baseUrl}/c/restful/labels/`, { headers: { 'Content-Type': 'application/json' } } @@ -409,7 +415,7 @@ export default class RestClient implements Client { deleteLabel(id: number): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { - axios.delete(this.baseUrl + `/c/restful/label/${id}`).then(() => { + axios.delete(`${this.baseUrl}/c/restful/label/${id}`).then(() => { success(); }).catch(error => { const errorInfo = this.parseResponseOnError(error.response);