-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ec493
commit 7633ca6
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ENVIRONMENT } from "../../config/environment"; | ||
import axios, { AxiosError } from "axios"; | ||
type UnshareFileRequest = { | ||
token: string; | ||
fileUUID: string; | ||
otherUsername: string; | ||
}; | ||
|
||
type UnshareFileResponse = { | ||
success: boolean; | ||
msg: string; | ||
}; | ||
|
||
export const unshareFileService = async ( | ||
req: UnshareFileRequest | ||
): Promise<UnshareFileResponse> => { | ||
const URL = `${ENVIRONMENT.PROXY_BASE_URL}/file/unshare`; | ||
|
||
try { | ||
const unshareFileResponse = await axios.post( | ||
URL, | ||
{ | ||
fileUUID: req.fileUUID, | ||
otherUsername: req.otherUsername | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${req.token}` | ||
} | ||
} | ||
); | ||
const { data } = unshareFileResponse; | ||
|
||
return { | ||
success: true, | ||
msg: data.msg | ||
}; | ||
} catch (error) { | ||
let errorMsg = "There was an error while trying to un-share the file"; | ||
|
||
if (error instanceof AxiosError) { | ||
errorMsg = error.response?.data.msg || errorMsg; | ||
} | ||
|
||
return { | ||
success: false, | ||
msg: errorMsg | ||
}; | ||
} | ||
}; |