revbits-cip-integration
Version:
This package will integrate CIP with any product
111 lines (110 loc) • 5.39 kB
JavaScript
"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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const form_data_1 = __importDefault(require("form-data"));
const jwt_client_1 = require("../services/jwt.client");
const api_config_1 = require("./api.config");
const base_api_1 = require("./base.api");
class UsersApi extends base_api_1.BaseApi {
constructor(baseUrl, platform, privKey, options, actor = null) {
super(baseUrl, options, platform, () => {
const jwtClient = new jwt_client_1.JWTClient(platform, privKey, actor);
return jwtClient.getJWT();
});
this.baseUrl = baseUrl;
this.platform = platform;
this.privKey = privKey;
this.options = options;
}
getAll(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.GET_ALL, data, 'Unable to get Users.');
});
}
getOne(id, username = null) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.GET_ONE, { id, username }, id ? `Unable to get User against id ${id}.` : `Unable to get User against username ${username}.`);
});
}
create(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.CREATE, data, 'Unable to create User.');
});
}
createBulk(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.CREATE_BULK, data, 'Unable to create bulk Users.');
});
}
update(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.UPDATE, data, `Unable to update User against id ${data.id}.`);
});
}
bulkUpdate(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.BULK_UPDATE, data, `Unable to update bulk Users.`);
});
}
uploadAvatar(filePath) {
return __awaiter(this, void 0, void 0, function* () {
const file = (0, fs_1.createReadStream)(filePath);
const formData = new form_data_1.default();
formData.append('file', file);
return this.sendFormDataApiRequest(api_config_1.API_ENDPOINTS.USER.UPLOAD_AVATAR, formData, `User Avatar could not be uploaded.`);
});
}
delete(id) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.DELETE, { id }, `Unable to delete User against id ${id}.`);
});
}
restore(id) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.RESTORE, { id }, `Unable to restore User against id ${id}.`);
});
}
checkUsersExistenceByUsernames(usernames) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.CHECK_USERS_EXISTENCE_BY_USERNAMES, { usernames }, `Unable to check existence of users against given usernames list.`);
});
}
checkUsersExistenceByIds(ids) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.CHECK_USERS_EXISTENCE_BY_IDS, { ids }, `Unable to check existence of users against given ids list.`);
});
}
getCipUrlsConfig() {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.USER.GET_CIP_URLS_CONFIG, {}, `Unable to get cip urls config.`);
});
}
createInventory(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.INVENTORY.CREATE_INVENTORY, data, `Unable to Create inventory.`);
});
}
logout() {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.SESSION.LOGOUT, {}, `Unable to logout.`);
});
}
updateDashboard() {
return __awaiter(this, void 0, void 0, function* () {
return this.sendApiRequest(api_config_1.API_ENDPOINTS.DASHBOARD.UPDATE, {}, `Unable to update dashboard.`);
});
}
}
exports.default = UsersApi;