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

Olly dev #1

Open
wants to merge 6 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
74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"pino": "^4.10.2",
"pm2": "^2.7.1",
"querymen": "^2.0.0",
"request": "^2.85.0",
"request-promise": "^4.1.1",
"sanitize-html": "^1.15.0",
"shortid": "^2.2.8",
Expand Down
21 changes: 21 additions & 0 deletions src/api/company/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { asyncHandler, removeEmptyParams } = require('../../utils');
const ComapnySearcher = require('../../services/companysearcher');
// const Company = require('./model');


/**
* GENERIC FUNCTIONS (do not modify)
*/

exports.search = asyncHandler(async ({ query }, res) => {
console.log(query);
let results = '';
const warnings = [];
const cleanQuery = removeEmptyParams(query);
try {
results = await ComapnySearcher(cleanQuery.companyid);
} catch (err) {
warnings.push(err);
}
res.json({ 'companyname': results });
}, 'Unable to retrieve news articles.');
30 changes: 30 additions & 0 deletions src/api/company/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { Router } = require('express');
const { token } = require('../../services/passport');
const {
search, // create,
} = require('./controller');

const router = new Router();

/**
* CUSTOM ROUTES
*/

/**
* GENERIC ROUTES (do not modify these)
*/
/*
router.post(
'/',
token({ required: true }),
create,
);
*/

router.get(
'/',
token({ required: true }),
search,
);

module.exports = router;
2 changes: 2 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Router, static } = require('express');
const path = require("path");
const user = require('./user');
const company = require('./company');
const auth = require('./auth');
const config = require('../config');
const debug = require('./debug');
Expand Down Expand Up @@ -34,6 +35,7 @@ const router = new Router();
* @apiParam {String[]} [fields] Fields to be returned.
*/
router.use('/users', user);
router.use('/company', company);
router.use('/auth', auth);
router.use('/search', search);
router.use('/news', news);
Expand Down
24 changes: 24 additions & 0 deletions src/api/search/controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { asyncHandler, removeEmptyParams } = require('../../utils');
const Searcher = require('../../services/searcher');
const { responseWrapper } = require('../../services/response');
const ComapnySearcher = require('../../services/companysearcher');

/**
* CUSTOM FUNCTIONS
Expand Down Expand Up @@ -28,7 +29,30 @@ exports.search = asyncHandler(async ({ query, user }, res) => {
if (!cleanQuery.topics) warnings.push('Topics not specified.');
if (!cleanQuery.companyids) warnings.push('Company id\'s not specified.');
if (!cleanQuery.page || cleanQuery.page <= 0) cleanQuery.page = 1;

const comps = cleanQuery.companyids.split(',');

async function getCompanies(companies) {
const pArray = companies.map(async (company) => {
// make it lower case and strip whitespace
const companyStr = company.toLowerCase().replace(/^\s+|\s+$/g, '');
let response = '';
if (companyStr.includes('.ax')) {
// take the part before ax
response = await ComapnySearcher(companyStr.split('.')[0]);
} else {
response = company;
}
return response;
});
const users = await Promise.all(pArray);
return users;
}
const newcomps = await getCompanies(comps);
cleanQuery.companyids = newcomps.join(',');

try {
console.log(cleanQuery);
results = await Searcher(cleanQuery, user);
} catch (err) {
warnings.push(err);
Expand Down
4 changes: 2 additions & 2 deletions src/api/user/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ exports.create = asyncHandler(async (req, res, next) => {
if (body.role) throw new APIError(400, 'Users are not allowed to change the role.');
if (!body.password) throw new APIError(400, 'No password provided');
const zxcvbnResult = zxcvbn(body.password, [body.email, body.name]);
if (zxcvbnResult.score < 1) errors.add('password.insecure', 'password', 'The password you\'ve chosen is too insecure.');
if (body.password.length < 8) errors.add('password.tooShort', 'password');
if (zxcvbnResult.score < 1) errors.add('password.insecure', 'password', 'The password you\'ve chosen is too insecure. Make sure it contains at least one lowercase and one uppercase letter and a number');
if (body.password.length < 8) errors.add('password.tooShort', 'password', 'The password you \'ve created is too short, it needs to be longer than 8 characters.');
if (typeof body.email === 'string' && !isEmail(body.email)) errors.add('invalidEmail', 'email', 'The email you\'ve chosen is invalid.');
if (errors.length > 0) throw new APIError(400, errors);
await User.create({
Expand Down
29 changes: 29 additions & 0 deletions src/services/companysearcher/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const axios = require('axios');

const index = async (query) => {
let result = '';
const companycode = query;
await axios.get('https://www.asx.com.au/asx/research/ASXListedCompanies.csv')
.then(async (response) => {
const vals = response.data.split('\n');
let i = 0;
for(i = 0; i < vals.length; i += 1) {
const line = vals[i];
const words = line.split(',');
if (words.length > 2) {
if (words[1].replace(/["]+/g, '').toLowerCase() === companycode.toLowerCase()) {
result = words[0].replace(/["]+/g, '').toLowerCase().split(' ')[0];
break;
}
}
}
if (i >= vals.length){
result = companycode;
}
});


return result;
};

module.exports = index;
31 changes: 0 additions & 31 deletions src/services/sourcer/yahoo.js

This file was deleted.