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

Feat/initial kraken setup #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"browser": true,
"mocha": true
},
"parser": "babel-eslint",
"extends": "eslint:recommended"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.idea/
.build/
66 changes: 49 additions & 17 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
{






"i18n": {
"contentPath": "path:./locales",
"fallback": "en-US"
"databaseConfig": {
"uri": "",
"databases": {
"core": "core",
"factcheck": "factcheck"
}
},


"specialization": {
},

"middleware": {



"compress": {
"priority": 10,
"enabled": true
},
"appsec": {
"priority": 110,
"module": {
"name": "lusca",
"arguments": [
{
"csrf": false,
"xframe": "SAMEORIGIN",
"p3p": false,
"csp": false
}
]
}
},
"logger": {
"enabled": true,
"route": "/*",
"priority": 20,
"module": {
"name": "path:middleware/logHandler",
"arguments": [
{
"writeToDisk": true,
"component": "dega_video_analyzer",
"logDir": "/tmp/dega",
"writeToConsole": true,
"level": "info"
}
]
}
},
"static": {
"module": {
"arguments": [ "path:./.build" ]
}
},

"router": {
"module": {
"arguments": [{ "directory": "path:./controllers" }]
}
},
"errorHandler": {
"enabled": true,
"priority": 140,
"module": {
"name": "path:middleware/errorHandler",
"arguments": []
}
}

}
}
12 changes: 7 additions & 5 deletions config/development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{


"databaseConfig": {
"uri": "mongodb://localhost:27017/core",
"databases": {
"core": "core",
"factcheck": "factcheck"
}
},
"middleware": {

"devtools": {
"enabled": true,
"priority": 35,
Expand All @@ -12,8 +16,6 @@
"path:./public",
"path:./.build",
{


"copier": {
"module": "construx-copier",
"files": "**/*"
Expand Down
28 changes: 28 additions & 0 deletions config/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"databaseConfig": {
"uri": "mongodb://root:[email protected]:27017/admin",
"databases": {
"core": "core",
"factcheck": "factcheck"
}
},
"middleware": {
"devtools": {
"enabled": true,
"priority": 35,
"module": {
"name": "construx",
"arguments": [
"path:./public",
"path:./.build",
{
"copier": {
"module": "construx-copier",
"files": "**/*"
}
}
]
}
}
}
}
48 changes: 48 additions & 0 deletions controllers/api/v1/ratings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const RatingModel = require('../../../models/ratings');
const utils = require('../../../lib/utils');

function getRatingList(req, res, next) {
const logger = req.logger;
utils.setLogTokens(logger, 'ratings', 'getRating', req.query.client, null);
const model = new RatingModel(logger);
const clientId = req.query.client;
return model.getRating(
req.app.kraken,
'',
req.query.sortBy,
req.query.sortAsc,
req.query.limit,
req.query.next,
req.query.previous
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}


function getRatingDetails(req, res, next) {
const logger = req.logger;
utils.setLogTokens(logger, 'ratings', 'getRating', req.query.client, null);
const clientId = req.query.client;
var model = new RatingModel(logger);
return model.getRatingDetails(
req.app.kraken,
'',
req.params.ratingId
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}

module.exports = function routes(router) {
router.get('/', getRatingList);
router.get('/:ratingId', getRatingDetails);
};
189 changes: 189 additions & 0 deletions controllers/api/v1/videoAnalysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
const VideoAnalysisModel = require('../../../models/videoAnalysis');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the file names should be all small separated by - between words thats the convention we follow today. rename videoAnalysis to video-analysis.js

const utils = require('../../../lib/utils');
const Joi = require('@hapi/joi');
const ObjectId = require('mongodb').ObjectId;


function getVideoAnalysisList(req, res, next) {
const logger = req.logger;
const clientId = req.query.client;
utils.setLogTokens(logger, 'videoAnalysis', 'getVideoAnalysisList', req.query.client, null);
let model = new VideoAnalysisModel(logger);
return model.getVideoAnalysisList(
req.app.kraken,
clientId,
req.query.videoId,
req.query.sortBy,
req.query.sortAsc,
req.query.limit,
req.query.next,
req.query.previous
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}


function getVideoAnalysisDetails(req, res, next) {
const logger = req.logger;
const clientId = req.query.client;
utils.setLogTokens(logger, 'videoAnalysis', 'getVideoAnalysisDetails', req.query.client, null);
let model = new VideoAnalysisModel(logger);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create model object outside all functions and resuse it (change it to const instead of let)

return model.getVideoDetails(
req.app.kraken,
clientId,
req.params.videoId
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}

function createVideoAnalysis(req, res, next) {
const logger = req.logger;
utils.setLogTokens(logger, 'videoAnalysis', 'createVideoAnalysis', req.query.client, null);
const clientId = req.query.client;
var requestBody = req.body;
const schema = Joi.object().keys({
shown_title: Joi.string().required(),
shown_description: Joi.string(),
reality_title: Joi.string().required(),
reality_description: Joi.string(),
reality_source: Joi.string().required(),
youtube_link: Joi.string().required(),
rating_id: Joi.string().alphanum().min(24).max(24).required(),
video_id: Joi.string().alphanum().min(24).max(24).required(),
end_time_in_sec: Joi.number().required()
});

const {error, value} = Joi.validate(requestBody, schema);
if (error) {
return res.status(400).json({error: error.message});
}

const videoAnalysisObj = {
'shown_title': value.shown_title,
'shown_description': value.shown_description,
'reality_title': value.reality_title,
'reality_description': value.reality_description,
'reality_source': value.reality_source,
'youtube_link': value.youtube_link,
'rating': {
'$id': ObjectId(value.rating_id),
'$ref': 'video'
},
'video': {
'$id': ObjectId(value.video_id),
'$ref': 'video'
},
'end_time_in_sec': value.end_time_in_sec,
'client_id': clientId
};

let model = new VideoAnalysisModel(logger);
return model.createVideoAnalysis(
req.app.kraken,
videoAnalysisObj
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}

function updateVideoAnalysis(req, res, next) {
const logger = req.logger;
utils.setLogTokens(logger, 'videoAnalysis', 'updateVideoAnalysis', req.query.client, null);
const clientId = req.query.client;
let requestBody = req.body;
const schema = Joi.object().keys({
_id: Joi.string().alphanum().min(24).max(24).required(),
shown_title: Joi.string().required(),
shown_description: Joi.string(),
reality_title: Joi.string().required(),
reality_description: Joi.string(),
reality_source: Joi.string().required(),
youtube_link: Joi.string().required(),
rating_id: Joi.string().alphanum().min(24).max(24).required(),
video_id: Joi.string().alphanum().min(24).max(24).required(),
end_time_in_sec: Joi.number().required()
});

const {error, value} = Joi.validate(requestBody, schema);
if (error) {
return res.status(400).json({error: error.message});
}

const videoAnalysisObj = {
'shown_title': value.shown_title,
'shown_description': value.shown_description,
'reality_title': value.reality_title,
'reality_description': value.reality_description,
'reality_source': value.reality_source,
'youtube_link': value.youtube_link,
'rating': {
'$id': ObjectId(value.rating_id),
'$ref': 'video'
},
'video': {
'$id': ObjectId(value.video_id),
'$ref': 'video'
},
'end_time_in_sec': value.end_time_in_sec,
'client_id': clientId
};



let model = new VideoAnalysisModel(logger);
return model.updateVideoAnalysis(
req.app.kraken,
clientId,
req.params.id,
videoAnalysisObj
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}

function deleteVideoAnalysis(req, res, next) {
const logger = req.logger;
utils.setLogTokens(logger, 'videoAnalysis', 'deleteVideoAnalysis', req.query.client, null);
const clientId = req.query.client;

let model = new VideoAnalysisModel(logger);
return model.deleteVideoAnalysis(
req.app.kraken,
clientId,
req.params.id
).then((result) => {
if (result) {
res.status(200).json(result);
return;
}
res.sendStatus(404);
}).catch(next);
}



module.exports = function routes(router) {
router.get('/', getVideoAnalysisList);
router.post('/', createVideoAnalysis);
router.get('/:id', getVideoAnalysisDetails);
router.put('/:id', updateVideoAnalysis);
router.delete('/:id', deleteVideoAnalysis);
};
Loading