Skip to content

Commit b75b53f

Browse files
committed
feat: add url to download cv
1 parent 7af1ae9 commit b75b53f

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

server/db/url.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const mongoose = require('mongoose')
2+
3+
const schema = new mongoose.Schema({
4+
company: String,
5+
edition: String,
6+
kind: String,
7+
url: String
8+
})
9+
10+
schema.index({ 'company': 1, 'edition': 1, 'kind': 1 }, { 'unique': true })
11+
12+
module.exports = mongoose.model('Url', schema)
13+

server/resources/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ require('./promo-code')
1313
require('./happy-hour')
1414
require('./prize')
1515
require('./connection')
16+
require('./url')

server/resources/url.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const server = require('../').hapi
2+
const Url = require('../db/url')
3+
4+
server.method('url.get', get, {})
5+
6+
async function get(companyId, editionId) {
7+
const filterAll = {
8+
edition: editionId,
9+
kind: 'all'
10+
}
11+
const filterCompanyConnections = {
12+
company: companyId,
13+
edition: editionId,
14+
kind: 'company'
15+
}
16+
17+
const all = await Url.findOne(filterAll)
18+
const companyConnections = await Url.findOne(filterCompanyConnections)
19+
20+
return { all, companyConnections }
21+
}

server/routes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ require('./promo-code')
1414
require('./google')
1515
require('./prize')
1616
require('./connection')
17+
require('./url')

server/routes/url/handlers.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const Joi = require('joi')
2+
const render = require('../../views/url')
3+
const log = require('../../helpers/logger')
4+
const Boom = require('@hapi/boom')
5+
6+
exports = module.exports
7+
8+
exports.get = {
9+
options: {
10+
tags: ['api', 'company-endpoint'],
11+
auth: {
12+
strategies: ['default'],
13+
scope: ['team', 'admin', 'company']
14+
},
15+
validate: {
16+
params: Joi.object({
17+
companyId: Joi.string().required().description('Id of the company')
18+
}),
19+
},
20+
description: 'Gets a company download urls'
21+
},
22+
handler: async (request, h) => {
23+
try {
24+
const latestEdition = await request.server.methods.deck.getLatestEdition()
25+
const downloadLinks = await request.server.methods.url.get(request.params.companyId, latestEdition.id)
26+
return h.response(render(downloadLinks))
27+
} catch (err) {
28+
log.error({ err: err}, 'error getting company')
29+
throw Boom.internal()
30+
}
31+
},
32+
}

server/routes/url/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const server = require('../../').hapi
2+
const handlers = require('./handlers')
3+
4+
// server.route({
5+
// method: 'POST',
6+
// path: '/url',
7+
// options: handlers.create.options,
8+
// handler: handlers.create.handler
9+
// })
10+
//
11+
// server.route({
12+
// method: ['PUT', 'PATCH'],
13+
// path: '/url/{id}',
14+
// options: handlers.update.options,
15+
// handler: handlers.update.handler
16+
// })
17+
//
18+
// server.route({
19+
// method: 'GET',
20+
// path: '/url/{id}',
21+
// options: handlers.get.options,
22+
// handler: handlers.get.handler
23+
// })
24+
25+
server.route({
26+
method: 'GET',
27+
path: '/company/{companyId}/url',
28+
options: handlers.get.options,
29+
handler: handlers.get.handler
30+
})
31+
32+
// server.route({
33+
// method: 'GET',
34+
// path: '/url',
35+
// options: handlers.list.options,
36+
// handler: handlers.list.handler
37+
// })
38+
//
39+
// server.route({
40+
// method: 'DELETE',
41+
// path: '/company-endpoint/{companyId}',
42+
// options: handlers.remove.options,
43+
// handler: handlers.remove.handler
44+
// })
45+
//

server/views/url.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function render (content) {
2+
if (content instanceof Array) {
3+
return content.map(renderObject)
4+
}
5+
6+
return renderObject(content)
7+
}
8+
9+
function renderObject (model) {
10+
return {
11+
all: model.all,
12+
companyConnections: model.companyConnections
13+
}
14+
}

0 commit comments

Comments
 (0)