UNPKG

@amityco/ts-sdk

Version:

Amity Social Cloud Typescript SDK

50 lines (43 loc) 1.39 kB
import { fireEvent } from '~/core/events'; import { pullFromCache, upsertInCache } from '~/cache/api'; import { getActiveClient } from '~/client/api/activeClient'; import { JoinRequestStatusEnum } from '~/@types'; /* begin_public_function id: joinRequest.cancel */ /** * ```js * import { joinRequest } from '@amityco/ts-sdk' * const isCanceled = await joinRequest.cancel() * ``` * * Cancels a {@link Amity.JoinRequest} object * * @param joinRequest the {@link Amity.JoinRequest} to cancel * @returns A success boolean if the {@link Amity.JoinRequest} was canceled * * @category Join Request API * @async */ export const cancelJoinRequest = async ( joinRequest: Amity.InternalJoinRequest, ): Promise<boolean> => { const client = getActiveClient(); client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId); const { data } = await client.http.delete<{ success: boolean }>( `/api/v4/communities/${joinRequest.targetId}/join`, ); const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([ 'joinRequest', 'get', joinRequest.joinRequestId, ])?.data; if (joinRequestCache) { upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], { status: JoinRequestStatusEnum.Cancelled, }); fireEvent('local.joinRequest.deleted', [joinRequestCache]); } return data.success; }; /* end_public_function */