Skip to content

Commit

Permalink
BC-5639 - try to fix calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Nov 14, 2023
1 parent 11f85a1 commit 7ff1c15
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 60 deletions.
8 changes: 1 addition & 7 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"$schema": "./default.schema.json",
"host": "localhost",
"port": 3030,
"public": "../public/",
"services": {
"calendar": "http://localhost:3000",
"content": "https://content.schul-cloud.org",
"hydra": "http://localhost:9001",
"web": "http://localhost:3100"
},
"public": "./public/",
"I18N": {
"AVAILABLE_LANGUAGES": "de,en,es,uk",
"DEFAULT_LANGUAGE": "de",
Expand Down
8 changes: 1 addition & 7 deletions config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
"host": "localhost",
"port": "PORT",
"mongodb": "MONGO_URI",
"public": "../public/",
"services": {
"calendar": "CALENDAR_URI",
"content": "CONTENT_URI",
"hydra": "HYDRA_URI",
"web": "HOST"
}
"public": "./public/"
}
6 changes: 1 addition & 5 deletions config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"SC_DOMAIN": "localhost",
"PUBLIC_BACKEND_URL": "http://localhost:3030/api",
"DB_URL": "mongodb://127.0.0.1:27017/schulcloud-test",
"public": "../public/",
"services": {
"calendar": "https://schul.tech:3000",
"content": "https://content.schul-cloud.org"
},
"public": "./public/",
"FORCE_SEND_EMAIL": true,
"LDAP_PASSWORD_ENCRYPTION_KEY": "1234567890123456",
"AES_KEY": "6543210987654321",
Expand Down
5 changes: 2 additions & 3 deletions src/services/calendar/courseCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ const request = require('request-promise-native');
const { Configuration } = require('@hpi-schul-cloud/commons');
const hooks = require('./hooks');

const calendarUri = Configuration.get('CALENDAR_URI');
class CourseCalendarService {
constructor(app) {
this.app = app;
}

remove(id, params) {
const serviceUrls = this.app.get('services') || {};

const userId = (params.query || {}).userId || (params.account || {}).userId || params.payload.userId;
const options = {
uri: `${serviceUrls.calendar}/scopes/${id}`,
uri: `${calendarUri}/scopes/${id}`,
headers: {
Authorization: userId,
},
Expand Down
73 changes: 35 additions & 38 deletions src/services/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const courseCalendarSetup = require('./courseCalendar');

const hooks = require('./hooks');

const calendarUri = Configuration.get('CALENDAR_URI');

/**
* converts a jsonApi-event to a plain event
* @param event {object}
Expand All @@ -34,34 +36,36 @@ const convertJsonApiToEvent = (event) => {
* @param body
* @returns {object} - valid json-api body for calendar-service
*/
const convertEventToJsonApi = (body) => ({
data: [
{
type: 'event',
attributes: {
summary: body.summary,
location: body.location,
description: body.description,
dtstart: body.startDate,
dtend: body.endDate || new Date(new Date(body.startDate).getTime() + body.duration).toISOString(),
dtstamp: new Date(),
transp: 'OPAQUE',
sequence: 0,
repeat_freq: body.frequency,
repeat_wkst: body.weekday,
repeat_until: body.repeat_until,
'x-sc-courseId': body.courseId,
'x-sc-teamId': body.teamId,
'x-sc-featureVideoConference': body.featureVideoConference === 'on',
'x-sc-courseTimeId': body.courseTimeId,
},
relationships: {
'scope-ids': [body.scopeId],
'separate-users': false,
const convertEventToJsonApi = (body) => {
return {
data: [
{
type: 'event',
attributes: {
summary: body.summary,
location: body.location,
description: body.description,
dtstart: body.startDate,
dtend: body.endDate || new Date(new Date(body.startDate).getTime() + body.duration).toISOString(),
dtstamp: new Date(),
transp: 'OPAQUE',
sequence: 0,
repeat_freq: body.frequency,
repeat_wkst: body.weekday,
repeat_until: body.repeat_until,
'x-sc-courseId': body.courseId,
'x-sc-teamId': body.teamId,
'x-sc-featureVideoConference': body.featureVideoConference === 'on',
'x-sc-courseTimeId': body.courseTimeId,
},
relationships: {
'scope-ids': [body.scopeId],
'separate-users': false,
},
},
},
],
});
],
};
};

class Service {
constructor(options) {
Expand Down Expand Up @@ -172,11 +176,9 @@ class Service {
}

create(data, params) {
const serviceUrls = this.app.get('services') || {};

const userId = (params.query || {}).userId || (params.account || {}).userId || params.payload.userId;
const options = {
uri: `${serviceUrls.calendar}/events/`,
uri: `${calendarUri}/events/`,
method: 'POST',
headers: {
Authorization: userId,
Expand All @@ -201,10 +203,9 @@ class Service {
}

find(params) {
const serviceUrls = this.app.get('services') || {};
const userId = (params.query || {}).userId || (params.account || {}).userId || params.payload.userId;
const options = {
uri: `${serviceUrls.calendar}/events?${queryString.stringify(params.query)}`,
uri: `${calendarUri}/events?${queryString.stringify(params.query)}`,
headers: {
Authorization: userId,
},
Expand All @@ -229,11 +230,9 @@ class Service {
}

remove(id, params) {
const serviceUrls = this.app.get('services') || {};

const userId = (params.query || {}).userId || (params.account || {}).userId || params.payload.userId;
const options = {
uri: `${serviceUrls.calendar}/events/${id}`,
uri: `${calendarUri}/events/${id}`,
headers: {
Authorization: userId,
},
Expand All @@ -251,11 +250,9 @@ class Service {
}

update(id, data, params) {
const serviceUrls = this.app.get('services') || {};

const userId = (params.query || {}).userId || (params.account || {}).userId || params.payload.userId;
const options = {
uri: `${serviceUrls.calendar}/events/${id}`,
uri: `${calendarUri}/events/${id}`,
method: 'PUT',
headers: {
Authorization: userId,
Expand Down

0 comments on commit 7ff1c15

Please sign in to comment.