Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v2.4.0 #231

Merged
merged 9 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ config.webapp = {
}

config.deck = {
url: process.env.CANNON_EVENTDECK_URL || 'https://deck.sinfo.org'
url: process.env.CANNON_EVENTDECK_URL || 'https://deck.sinfo.org/api'
}

config.upload = {
Expand Down
5 changes: 4 additions & 1 deletion server/db/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
8 changes: 5 additions & 3 deletions server/resources/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server.method('deck.getSession', getSession, {})
server.method('deck.getSpeakers', getSpeakers, {})
server.method('deck.getSpeaker', getSpeaker, {})

const DECK_API_URL = `${config.deck.url}/api`
const DECK_API_URL = `${config.deck.url}`

async function getLatestEdition() {
const event = await axios.get(`${DECK_API_URL}/public/events?current=true`, { json: true })
Expand Down Expand Up @@ -91,12 +91,13 @@ async function getSpeaker(speakerId) {
// Translate Deck's event object to old format
function transformEvent(event, options) {
return {
id: event.id,
id: String(event.id),
name: event.name,
kind: options?.kind || "Main Event",
public: options?.public || true,
date: event.begin,
duration: new Date(new Date(event.end) - new Date(event.begin)),
calendarUrl: event.calendarUrl
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -147,7 +149,7 @@ function transformSession(session, options) {
name: session.title,
description: session.description,
kind: sessionKinds[session.kind] || session.kind,
event: options?.event || (session.company?.participation?.length > 0 && session.company.participation[0].event),
event: String(options?.event || (session.company?.participation?.length > 0 && session.company.participation[0].event)),
date: session.begin,
duration: new Date(new Date(session.end) - new Date(session.begin)),
place: session.place,
Expand Down
7 changes: 6 additions & 1 deletion server/resources/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
16 changes: 16 additions & 0 deletions server/routes/deck/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
7 changes: 7 additions & 0 deletions server/routes/deck/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
1 change: 1 addition & 0 deletions server/views/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function renderObject (model) {
return {
id: model.id,
name: model.name,
site: model.site,
advertisementLvl: model.advertisementLvl,
img: model.img
}
Expand Down
3 changes: 2 additions & 1 deletion server/views/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

2 changes: 1 addition & 1 deletion server/views/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading