haifa-reminder/dist/Ics.js

69 lines
2.7 KiB
JavaScript

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const ics = __importStar(require("ics"));
const uuid = require('uuid').v4();
class Ics {
constructor() {
this.generateIcsOutputFromGames = (games) => {
let output = [];
games.forEach((game) => {
output.push(this.generateIcsOutputFromGame(game));
});
console.log(output);
const { error, value } = ics.createEvents(output);
if (error) {
console.log(error);
return '';
}
console.log(value);
return value;
};
this.generateIcsOutputFromGame = (game) => {
const { summary, location, description, start, end } = game;
const icsEvent = {
title: description,
description,
location,
start: [start.dateTime[0], start.dateTime[1], start.dateTime[2], start.dateTime[3], start.dateTime[4]],
end: [end.dateTime[0], end.dateTime[1], end.dateTime[2], end.dateTime[3], end.dateTime[4]],
status: 'CONFIRMED',
busyStatus: "BUSY",
productId: '-//kfir.dayanhub.com',
recurrenceRule: '',
attendees: [],
alarms: [],
categories: [],
organizer: { name: 'Maccabi Haifa F.C.', email: '' },
};
return icsEvent;
};
this.convertIcsToIcal = (icsEvents) => {
const icalEvents = icsEvents.replace(/BEGIN:VEVENT/g, 'BEGIN:VEVENT\r\nUID:' + uuid);
return icalEvents;
};
}
}
exports.default = Ics;