import req from './../../fetch'; import { AllAPIResponses, CarbonError, UserSubscriptionType, } from './../../index'; import { undocumentedResponse, paramsToString } from './../../utils'; type Params = { notificationSchemaId: number; userId: number; }; type Payload = { // 01234|02:04-03:04,04:04-05:04; 12|12:00-13:00; schedule: string; }; const put = async ( params: Params, payload: Payload, headers?: Headers ): Promise> => { try { const resp = await req.put( `/api/usersubscriptions${paramsToString(params)}`, JSON.stringify(payload), headers ); const clone = resp.clone(); switch (resp.status) { case 200: return { data: (await resp.json()) as UserSubscriptionType, response: clone, }; case 400: case 401: case 403: case 404: case 500: return { error: (await resp.json()) as CarbonError, response: clone, }; default: return { error: new Error(undocumentedResponse(resp)), response: clone, }; } } catch (e) { return { error: e, response: undefined }; } }; export default put;