UNPKG

orgdo

Version:

Command-line tool to manage the Todo lists

64 lines (63 loc) 2.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const cron_1 = require("cron"); class Cron { constructor(client) { this.client = client; } add(options) { return __awaiter(this, void 0, void 0, function* () { verifyCron(options.cron); const id = yield this.client.incId("taskId"); options.task = options.task || `Task ${id}`; const model = { id, cron: options.cron, task: options.task }; yield this.client.addCron(model); return model; }); } update(options) { return __awaiter(this, void 0, void 0, function* () { const model = yield this.client.getCron(options.id); if (options.cron) { verifyCron(options.cron); model.cron = options.cron; } if (options.task) { model.task = options.task; } yield this.client.updateCron(model); return model; }); } remove(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.removeCron(id); }); } list() { return __awaiter(this, void 0, void 0, function* () { return this.client.listCrons(); }); } } exports.default = Cron; function verifyCron(cron) { try { const _ = new cron_1.CronTime(cron); } catch (err) { throw new Error(`Invalid cron pattern ${cron}, ${err.message}`); } }