import { AuthedFetchType } from "../../api/fake-fetch"; import { Cards } from "../models"; import { errorMessage } from "../../utils"; import { MISSING_ACCOUNT_ID_ERROR_MESSAGE, MISSING_CARD_ID_ERROR_MESSAGE, } from "../../constants"; export default function cards(authedFetch: AuthedFetchType): Cards { return { list: ({ accountID }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/cards`, { method: "GET" }); }, get: ({ accountID, cardID }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } if (!cardID) { return errorMessage(MISSING_CARD_ID_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/cards/${cardID}`, { method: "GET" }); }, disable: ({ accountID, cardID }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } if (!cardID) { return errorMessage(MISSING_CARD_ID_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/cards/${cardID}`, { method: "DELETE" }); } } }