UNPKG

osu-api-extended

Version:

Advanced osu! api wrapper cover all V2 and V1 endpoints, and provide useful tools

51 lines (50 loc) 2.47 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.notifications_actions = void 0; const request_1 = require("../../utility/request"); const handleErrors_1 = require("../../utility/handleErrors"); const notifications_actions = (params, addons) => __awaiter(void 0, void 0, void 0, function* () { const object = {}; let url = 'https://osu.ppy.sh/api/v2'; let method = 'GET'; switch (params === null || params === void 0 ? void 0 : params.type) { case 'mark_as_read': url += '/notifications/mark-read'; method = 'POST'; if (!Array.isArray(params.notifications) && !Array.isArray(params.identities)) { return (0, handleErrors_1.handleErrors)(new Error(`Missing on of parameters`)); } ; // params.ids.forEach((r, index) => object[`identities[${index}][id]`] = r); if (Array.isArray(params === null || params === void 0 ? void 0 : params.notifications)) { object['notifications'] = params.notifications; } ; if (Array.isArray(params === null || params === void 0 ? void 0 : params.identities)) { object['identities'] = params.identities; } ; break; default: return (0, handleErrors_1.handleErrors)(new Error(`Unsupported type: ${params.type}`)); } ; const data = yield (0, request_1.request)(url, { method: method, data: JSON.stringify(object), addons, }); if (data.error) return (0, handleErrors_1.handleErrors)(new Error(data.error)); return data; }); exports.notifications_actions = notifications_actions;