trello-for-wolves
Version:
Node.js wrapper for Trello API...for wolves.
82 lines (81 loc) • 3.36 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomFieldOption = void 0;
var TrelloForWolvesError_1 = require("../TrelloForWolvesError");
var BaseResource_1 = require("./BaseResource");
var CustomFieldOption = /** @class */ (function (_super) {
__extends(CustomFieldOption, _super);
function CustomFieldOption() {
return _super !== null && _super.apply(this, arguments) || this;
}
CustomFieldOption.prototype.getOption = function () {
return this.apiGet("/");
};
CustomFieldOption.prototype.getOptions = function () {
return this.apiGet("/");
};
/**
* This is the same as `getOptions()`, I added it to make more sense in the
* context of a card resource.
*/
CustomFieldOption.prototype.getCustomFieldItems = function () {
return this.apiGet("/");
};
CustomFieldOption.prototype.addOption = function (option) {
var body = this.stringifyOptionValue(option);
if (this.isChildOf("card")) {
return this.apiPut("/", {}, body);
}
return this.apiPost("/", {}, body);
};
CustomFieldOption.prototype.updateOption = function (option) {
if (!this.isChildOf("card")) {
throw new TrelloForWolvesError_1.TrelloForWolvesError("You can only call updateOption() from a parent card");
}
var body = this.stringifyOptionValue(option);
return this.apiPut("/", {}, body);
};
CustomFieldOption.prototype.deleteOption = function () {
if (this.isChildOf("card")) {
if (this.pathElements.length > 5) {
this.pathElements.pop();
}
return this.apiPut("/", {}, { value: "", key: "", token: "" });
}
return this.apiDelete("/");
};
CustomFieldOption.prototype.stringifyOptionValue = function (option) {
var validOption = __assign({}, option);
var _a = Object.entries(validOption.value)[0], key = _a[0], value = _a[1];
validOption.value[key] = value.toString();
return validOption;
};
return CustomFieldOption;
}(BaseResource_1.BaseResource));
exports.CustomFieldOption = CustomFieldOption;