Skip to content

Commit

Permalink
intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nolafs committed Dec 11, 2018
0 parents commit 899875f
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/.idea/*
**/npm-debug.log*
**/node_modules
**/.npm
**/build/*
**/.DS_Store
**/.env
**/.gradle/*
**/out/*
**/*.log
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Cardano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
![Cardano](https://cardano.github.io/assets/images/cardano-logo.svg)
# JavaScript Coding Challenge

## Goal
* Create a web API to retrieve data from a mock database and structure it in a hierarchy before returning to the caller.

## Time
* You can spend as long or short as you desire though under an hour would should be fine for seniors or several hours for more junior. It does not have to be complete but show you know the main ideas of modern development. Its up to you.

## Tasks
* In the data positions belong to portfolios. There are many positions for each portfolio. Take a look at /src/database/data.
* Create an endpoint, /portfolios or similar, with the ability to retrieve a JSON list of all portfolios and positions from the mock database module in the starter template. The data returned should be correctly structured so each portfolio has a property with the collection of positions related to each.
* Add the ability to retrieve only those portfolios which have the currency specified in the query. The data should be structured as above with positions as a property on each portfolio.
* Add whatever features you think necessary to make this a production ready application but you don't need a complete implementation as long as samples of each of the key ideas that should be implemented are included.
* Fork this project to your repo, work on a branch with your full name in the name and create a pull request with the same name when you are ready for us to look at it. If you have not done this before take a look at [this guide](https://akrabat.com/the-beginners-guide-to-contributing-to-a-github-project).

## Notes
* Once installed and started the service is located at [http://localhost:8085](http://localhost:8085).
* You do not need to access a real database. There is a mock database implementation in the "database" directory. Like any database, you first use the client to ```connect```. This returns a connection which you can use to ```load``` data.
* There is no right or wrong solution to this problem, it is designed to see how you approach the task along with your understanding and explanation of your code and decisions made.
* It is complete open book so google and stackoverflow until your hearts content. After all that is how everyone codes today.
* Feel free to ask us questions at any time. You will not be punished for this and in fact may get rewarded for it. Do whatever you would do when designing and building a real world system.
* You can add any libraries or configuration you choose.
* Your favourite editor is probably the best choice so you are comfortable.
* There are no "intentional" bugs, we are not trying to catch you out, it probably really is a bug so please let us know and give us the fix.
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "javascript-code-test",
"version": "1.0.17",
"date": "2018-06-14T13:15:31.964Z",
"description": "Cardano Javascript Code Test",
"main": "index.js",
"scripts": {
"start": "nodemon -r babel-register --nolazy ./src/index.js",
"test": "jest"
},
"author": "Cardano",
"license": "MIT",
"homepage": "https://cardano.github.io",
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "8"
}
}
]
],
"plugins": [
"transform-object-rest-spread"
]
},
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"express": "^4.16.3",
"http": "^0.0.0",
"nodemon": "^1.17.5"
}
}
4 changes: 4 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
port: 8085,
url: "http://localhost:8085",
};
54 changes: 54 additions & 0 deletions src/database/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const portfolios = [
{
id: 1,
name: "Investor 1"
},
{
id: 2,
name: "Investor 2"
},
{
id: 3,
name: "Investor 3"
}
];

const positions = [
{
id: 1,
portfolioId: 1,
currency: "GBP",
value: -2.02,
date: "2018-06-07"
},
{
id: 2,
portfolioId: 1,
currency: "EUR",
value: 1906302.15,
date: "2018-06-07"
},
{
id: 3,
portfolioId: 2,
currency: "GBP",
value: 1379804.1,
date: "2018-06-07"
},
{
id: 4,
portfolioId: 2,
currency: "CAD",
value: 2401938.18,
date: "2018-06-07"
},
{
id: 5,
portfolioId: 3,
currency: "GBP",
value: 724.29,
date: "2018-06-07T00:00:00.000Z"
}
];

export default { portfolios, positions };
41 changes: 41 additions & 0 deletions src/database/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable class-methods-use-this */
import data from './data';
import log from '../logger';

class DatabaseConnection {
constructor(server) {
this.server = server;
}

// noinspection JSUnusedGlobalSymbols
// noinspection JSMethodCanBeStatic
/**
* Loads all data.
* @returns {Promise<{portfolios, positions}>}
*/
load() {
log.info('Database: load');
return Promise.resolve(data);
}
}

/**
* A mock database client that simulates getting data from a database and a slow initial connection.
*/
class DatabaseClient {
connect(server) {
return new Promise((resolve, reject) => {
if (server === null) {
reject(new Error("No server specified"));
}
setTimeout(
() => {
log.info('Database: connected');
resolve(new DatabaseConnection(server));
},
2000);
});
}
}

export default new DatabaseClient();
19 changes: 19 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from 'express';
import http from 'http';
import config from './config';
import log from './logger';
import routes from './routes';

const app = express();

routes(app);

const server = http.createServer(app);
server.listen(config.port);
server.on('error', error => log.error(error));
server.on('listening', () => log.info(`Listening at ${config.url}`));

process.on('uncaughtException', (error) => {
log.error(error);
});

6 changes: 6 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-console */
export default {
debug: (...args) => console.debug(...args),
info: (...args) => console.info(...args),
error: (...args) => console.error(...args),
};
8 changes: 8 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import log from "../logger";

export default (app) => {
app.get('/', (req, res) => {
log.info('/ called');
res.json({ message: 'You Made it!' });
});
};

0 comments on commit 899875f

Please sign in to comment.