Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 99410ba

Browse files
Fix hapi issues and auth issues
1 parent 970deb7 commit 99410ba

11 files changed

+83
-105
lines changed

app-bootstrap.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
/**
2-
* App bootstrap
2+
* add logger and joi to services
33
*/
4+
5+
const fs = require('fs')
6+
const path = require('path')
7+
const logger = require('./src/common/logger')
8+
49
global.Promise = require('bluebird')
510
const Joi = require('joi')
611

712
Joi.id = () => Joi.string().uuid().required()
13+
14+
/**
15+
* add logger and joi schema to service
16+
* @param dir
17+
*/
18+
function buildServices (dir) {
19+
const files = fs.readdirSync(dir)
20+
files.forEach((file) => {
21+
const curPath = path.join(dir, file)
22+
const stats = fs.statSync(curPath)
23+
if (stats.isDirectory()) {
24+
buildServices(curPath)
25+
} else if (path.extname(file) === '.js') {
26+
logger.buildService(require(curPath)); // eslint-disable-line
27+
}
28+
})
29+
}
30+
31+
buildServices(path.join(__dirname, 'src', 'services'))

app-constants.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
require('./app-bootstrap')
66

7-
const path = require('path')
87
const config = require('config')
98
const express = require('express')
109
const interceptor = require('express-interceptor')

package-lock.json

Lines changed: 37 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"url": ""
2020
},
2121
"dependencies": {
22-
"@hapi/joi": "^16.1.8",
2322
"aws-sdk": "^2.627.0",
2423
"axios": "^0.19.2",
2524
"bluebird": "^3.5.1",
@@ -33,6 +32,7 @@
3332
"file-type": "^14.6.2",
3433
"get-parameter-names": "^0.3.0",
3534
"http-status-codes": "^1.3.0",
35+
"joi": "^17.2.1",
3636
"js-yaml": "^3.14.0",
3737
"lodash": "^4.17.19",
3838
"multer": "^1.4.2",

src/bootstrap.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/common/helper.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const _ = require('lodash')
55
const config = require('config')
66
const AWS = require('aws-sdk')
77
const path = require('path')
8-
const axios = require('axios')
9-
const querystring = require('querystring')
10-
const NodeCache = require('node-cache')
118
const models = require('../models')
129
const errors = require('./errors')
1310
const logger = require('./logger')

src/common/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ logger.decorateWithValidators = function (service) {
119119
service[name] = async function () {
120120
const args = Array.prototype.slice.call(arguments)
121121
const value = _combineObject(params, args)
122-
const normalized = Joi.attempt(value, method.schema)
122+
const normalized = Joi.attempt(value, Joi.object(method.schema))
123123

124124
const newArgs = []
125125
// Joi will normalize values

src/consts.js renamed to src/constants.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ const AllAuthenticatedUsers = [
2626
*/
2727
const AdminUser = [UserRoles.admin, UserRoles.administrator]
2828

29+
const Scopes = {
30+
CreateUpload: 'create:upload',
31+
GetUpload: 'read:upload',
32+
UpdateUpload: 'update:upload',
33+
AllUpload: 'all:upload',
34+
CreateTemplate: 'create:template',
35+
GetTemplate: 'read:template',
36+
AllTemplate: 'all:template',
37+
GetSkill: 'read:skill',
38+
AllSkill: 'all:skill'
39+
}
40+
2941
module.exports = {
30-
UserRoles,
3142
AllAuthenticatedUsers,
32-
AdminUser
43+
AdminUser,
44+
Scopes
3345
}

src/routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const multer = require('multer')
55
const config = require('config')
66
const _ = require('lodash')
7-
const constants = require('../app-constants')
7+
const constants = require('./constants')
88
const fileUpload = multer({ storage: multer.memoryStorage() })
99

1010
// config template upload properties

src/services/UploadService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const logger = require('../common/logger')
1414
* Checks the type of uploaded file and ensures it's allowed.
1515
* @param {Object} upload The uploaded file
1616
*/
17-
async function ensureFileTypeIsValid(upload) {
17+
async function ensureFileTypeIsValid (upload) {
1818
const allowedExtensions = ['xls', 'xlsx', 'csv']
1919
const allowedMimeTypes = [
2020
'application/vnd.ms-excel',
2121
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
22-
'text/csv',
22+
'text/csv'
2323
]
2424
const fileType = await FileType.fromBuffer(upload.buffer)
2525
const fileExt = upload.originalname.split('.').pop().toLowerCase()
@@ -30,7 +30,7 @@ async function ensureFileTypeIsValid(upload) {
3030
if (isAllowed === false) {
3131
throw new errors.ForbiddenError(`You are allowed to upload only ${_.join(allowedExtensions, ',')} types.`)
3232
}
33-
}
33+
}
3434

3535
/**
3636
* Get upload entity by id.
@@ -117,7 +117,7 @@ partiallyUpdate.schema = {
117117
id: Joi.id(),
118118
authUser: Joi.object().required(),
119119
data: Joi.object().keys({
120-
status: Joi.string().valid(['pending', 'completed', 'failed']).required(),
120+
status: Joi.string().valid('pending', 'completed', 'failed').required(),
121121
info: Joi.string()
122122
}).required()
123123
}

0 commit comments

Comments
 (0)