@amityco/ts-sdk-react-native
Version:
Amity Social Cloud Typescript SDK
53 lines (45 loc) • 1.36 kB
text/typescript
import { fireEvent } from '~/core/events';
import { getActiveClient } from '~/client/api/activeClient';
import { ingestInCache } from '~/cache/api/ingestInCache';
import { prepareInvitationPayload } from '../utils';
/* begin_public_function
id: invitation.createInvitations
*/
/**
* ```js
* import { createInvitations } from '@amityco/ts-sdk'
* const created = await createInvitations({
* type: string,
* targetType: string,
* targetId: string,
* userIds: string[]
* }))
* ```
*
* Creates an {@link Amity.Invitation}
*
* @param bundle The data necessary to create a new {@link Amity.Invitation}
* @returns The newly created {@link Amity.Invitation}
*
* @category Invitation API
* @async
*/
export const createInvitations = async (
bundle: Amity.CreateInvitations,
): Promise<Amity.Cached<Amity.InternalInvitation[]>> => {
const client = getActiveClient();
client.log('invitation/createInvitations', bundle);
const { data: payload } = await client.http.post<Amity.InvitationPayload>(
'/api/v1/invitations',
bundle,
);
const data = prepareInvitationPayload(payload);
const cachedAt = client.cache && Date.now();
if (client.cache) ingestInCache(data, { cachedAt });
fireEvent('local.invitation.created', data.invitations);
return {
data: data.invitations,
cachedAt,
};
};
/* end_public_function */