-
Notifications
You must be signed in to change notification settings - Fork 53
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
Showing
2 changed files
with
76 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,44 @@ | ||
import axios from 'axios'; | ||
import { getAPIBaseUrls } from '../helpers'; | ||
import Constants, {ENV} from '../constants'; | ||
import { | ||
GroupDTO | ||
} from '../types'; | ||
|
||
import Constants, { ENV } from '../constants'; | ||
import { GroupDTO } from '../types'; | ||
|
||
/** | ||
* GET /v1/chat/groups/:chatId | ||
*/ | ||
|
||
export interface GetGroupType { | ||
chatId: string, | ||
env?: ENV | ||
chatId: string; | ||
env?: ENV; | ||
page?: number; | ||
limit?: number; | ||
} | ||
|
||
export const getGroup = async ( | ||
options: GetGroupType | ||
): Promise<GroupDTO> => { | ||
const { chatId, env = Constants.ENV.PROD } = options || {}; | ||
try { | ||
if (chatId == null || chatId.length == 0) { | ||
throw new Error(`chatId cannot be null or empty`); | ||
} | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}`; | ||
return axios | ||
.get(requestUrl) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((err) => { | ||
if (err?.response?.data) | ||
throw new Error(err?.response?.data); | ||
throw new Error(err); | ||
}); | ||
} catch (err) { | ||
console.error(`[Push SDK] - API - Error - API ${getGroup.name} -: `, err); | ||
throw Error(`[Push SDK] - API - Error - API ${getGroup.name} -: ${err}`); | ||
export const getGroup = async (options: GetGroupType): Promise<GroupDTO> => { | ||
const { | ||
chatId, | ||
env = Constants.ENV.PROD, | ||
page = 1, | ||
limit = 30, | ||
} = options || {}; | ||
try { | ||
if (chatId == null || chatId.length == 0) { | ||
throw new Error(`chatId cannot be null or empty`); | ||
} | ||
}; | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}?page=${page}&limit=${limit}`; | ||
return axios | ||
.get(requestUrl) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((err) => { | ||
if (err?.response?.data) throw new Error(err?.response?.data); | ||
throw new Error(err); | ||
}); | ||
} catch (err) { | ||
console.error(`[Push SDK] - API - Error - API ${getGroup.name} -: `, err); | ||
throw Error(`[Push SDK] - API - Error - API ${getGroup.name} -: ${err}`); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,46 +1,56 @@ | ||
import axios from 'axios'; | ||
import { getAPIBaseUrls } from '../helpers'; | ||
import Constants, {ENV} from '../constants'; | ||
import { | ||
GroupDTO | ||
} from '../types'; | ||
|
||
import Constants, { ENV } from '../constants'; | ||
import { GroupDTO } from '../types'; | ||
|
||
/** | ||
* GET /v1/chat/groups/:chatId | ||
*/ | ||
|
||
export interface GetGroupByNameType { | ||
groupName: string, | ||
env?: ENV, | ||
groupName: string; | ||
env?: ENV; | ||
page?: number; | ||
limit?: number; | ||
} | ||
|
||
export const getGroupByName = async ( | ||
options: GetGroupByNameType | ||
options: GetGroupByNameType | ||
): Promise<GroupDTO> => { | ||
const { groupName, env = Constants.ENV.PROD } = options || {}; | ||
try { | ||
console.log("============================================="); | ||
console.log("NOTICE: The method 'getGroupByName' will be deprecated on January 1st, 2024. Please update your code to remove this."); | ||
console.log("============================================="); | ||
if (groupName == null || groupName.length == 0) { | ||
throw new Error(`Group Name cannot be null or empty`); | ||
} | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups?groupName=${groupName}`; | ||
return axios | ||
.get(requestUrl) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((err) => { | ||
if (err?.response?.data) | ||
throw new Error(err?.response?.data); | ||
throw new Error(err); | ||
}); | ||
} catch (err) { | ||
console.error(`[Push SDK] - API - Error - API ${getGroupByName.name} -: `, err); | ||
throw Error(`[Push SDK] - API - Error - API ${getGroupByName.name} -: ${err}`); | ||
const { | ||
groupName, | ||
env = Constants.ENV.PROD, | ||
page = 1, | ||
limit = 30, | ||
} = options || {}; | ||
try { | ||
console.log('============================================='); | ||
console.log( | ||
"NOTICE: The method 'getGroupByName' will be deprecated on January 1st, 2024. Please update your code to remove this." | ||
); | ||
console.log('============================================='); | ||
if (groupName == null || groupName.length == 0) { | ||
throw new Error(`Group Name cannot be null or empty`); | ||
} | ||
}; | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups?groupName=${groupName}&page=${page}&limit=${limit}`; | ||
return axios | ||
.get(requestUrl) | ||
.then((response) => { | ||
return response.data; | ||
}) | ||
.catch((err) => { | ||
if (err?.response?.data) console.log(err); | ||
throw new Error(err?.response?.data); | ||
}); | ||
} catch (err) { | ||
console.error( | ||
`[Push SDK] - API - Error - API ${getGroupByName.name} -: `, | ||
err | ||
); | ||
throw Error( | ||
`[Push SDK] - API - Error - API ${getGroupByName.name} -: ${err}` | ||
); | ||
} | ||
}; |