All files / src/services/api/routers InviteRouter.tsx

100% Statements 7/7
100% Branches 3/3
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                            2209x     2209x 3x 3x     2209x 3x 3x      
import { InviteAccepted, InvitePreview } from "@/objects/Organisation";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { APIRouter } from "../ApiRouter";
 
/** Opening an invite link. The token goes in the body, never the URL, so it
 *  stays out of access logs; the link itself keeps it in the fragment. */
export class InviteRouter extends APIRouter {
  constructor(
    host: string,
    token: string | null = null,
    default_config: AxiosRequestConfig | null = null,
    headers: Dictionary<string> = {},
  ) {
    super("invites", host, token, default_config, headers);
  }
 
  preview = async (token: string): Promise<InvitePreview> => {
    const res = await this.api.post(this.endpoint("preview"), { token });
    return res.data as InvitePreview;
  };
 
  accept = async (token: string): Promise<InviteAccepted> => {
    const res = await this.api.post(this.endpoint("accept"), { token });
    return res.data as InviteAccepted;
  };
}