From f36ead9b7a0a880f336e3bfcab6cc5101b6a305b Mon Sep 17 00:00:00 2001 From: Pedro Maximino <53193337+PMax5@users.noreply.github.com> Date: Wed, 10 Apr 2024 21:50:24 +0100 Subject: [PATCH] Update 2.3.1 (#226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add support to Deck2 (#219) * fix: add company description (#220) * feat: add sponsors site (#223) Co-authored-by: André Romão <75808145+andreromao@users.noreply.github.com> * adds calendar to event in cannon (#224) * improves promo codes (#225) --------- Co-authored-by: Nuno Alves Co-authored-by: André Romão <75808145+andreromao@users.noreply.github.com> --- server/db/promo-code.js | 5 ++++- server/resources/deck.js | 2 ++ server/resources/promo-code.js | 7 ++++++- server/routes/deck/handlers.js | 16 ++++++++++++++++ server/routes/deck/index.js | 7 +++++++ server/views/company.js | 1 + server/views/event.js | 3 ++- server/views/promo-code.js | 2 +- 8 files changed, 39 insertions(+), 4 deletions(-) diff --git a/server/db/promo-code.js b/server/db/promo-code.js index dd9e70d..666eb25 100644 --- a/server/db/promo-code.js +++ b/server/db/promo-code.js @@ -3,7 +3,10 @@ const mongoose = require('mongoose') const schema = new mongoose.Schema({ company: String, edition: String, - expire: Date, + validity: { + from: Date, + to: Date + }, description: String, code: String }) diff --git a/server/resources/deck.js b/server/resources/deck.js index 74b358c..5423a0e 100644 --- a/server/resources/deck.js +++ b/server/resources/deck.js @@ -97,6 +97,7 @@ function transformEvent(event, options) { public: options?.public || true, date: event.begin, duration: new Date(new Date(event.end) - new Date(event.begin)), + calendarUrl: event.calendarUrl } } @@ -117,6 +118,7 @@ function transformCompany(company, options) { id: company.id, name: company.name, img: company.img, + site: company.site, description: company.description, advertisementLvl: options?.compact ? advertisementLvl : { advertisementLvl, diff --git a/server/resources/promo-code.js b/server/resources/promo-code.js index ddedb04..ddae8b7 100644 --- a/server/resources/promo-code.js +++ b/server/resources/promo-code.js @@ -8,8 +8,13 @@ server.method('promoCode.get', get, {}) async function get () { let now = new Date() + filter = { + 'validity.from': { $lte: now }, + 'validity.to': { $gte: now } + } + try { - let codes = await PromoCode.find({ expire: { '$gt': now.toISOString() } }, {}, {}) + let codes = await PromoCode.find(filter) if (!codes) { log.warn({ err: err }, 'could not find promo code') return cb(Boom.notFound()) diff --git a/server/routes/deck/handlers.js b/server/routes/deck/handlers.js index 2008a34..e350cf9 100644 --- a/server/routes/deck/handlers.js +++ b/server/routes/deck/handlers.js @@ -190,3 +190,19 @@ exports.getSpeaker = { } } } + +exports.getCalendarUrl = { + options: { + tags: ['api', 'calendar'], + description: 'Get the calendar url for the current edition' + }, + handler: async (request, h) => { + try { + const edition = await request.server.methods.deck.getLatestEdition() + return h.response(edition.calendarUrl) + } catch(err) { + log.error({ error: err }) + throw Boom.boomify(err) + } + } +} diff --git a/server/routes/deck/index.js b/server/routes/deck/index.js index ffa69d4..c5e9726 100644 --- a/server/routes/deck/index.js +++ b/server/routes/deck/index.js @@ -62,4 +62,11 @@ server.route({ path: '/speaker/{speakerId}', options: handlers.getSpeaker.options, handler: handlers.getSpeaker.handler +}) + +server.route({ + method: 'GET', + path: '/calendar', + options: handlers.getCalendarUrl.options, + handler: handlers.getCalendarUrl.handler }) \ No newline at end of file diff --git a/server/views/company.js b/server/views/company.js index cd2e976..094e1e5 100644 --- a/server/views/company.js +++ b/server/views/company.js @@ -10,6 +10,7 @@ function renderObject (model) { return { id: model.id, name: model.name, + site: model.site, advertisementLvl: model.advertisementLvl, img: model.img } diff --git a/server/views/event.js b/server/views/event.js index 85ff5d0..05df36a 100644 --- a/server/views/event.js +++ b/server/views/event.js @@ -16,7 +16,8 @@ module.exports = function render (content) { duration: model.duration, begin: model.begin, end: model.end, - isOcurring: model.isOcurring + isOcurring: model.isOcurring, + calendarUrl: model.calendarUrl, } } \ No newline at end of file diff --git a/server/views/promo-code.js b/server/views/promo-code.js index 685f022..ad47744 100644 --- a/server/views/promo-code.js +++ b/server/views/promo-code.js @@ -10,7 +10,7 @@ function renderObject (model) { return { company: model.company, edition: model.edition, - expire: model.expire, + expire: model.validity.to, description: model.description, code: model.code }