Skip to content

Commit

Permalink
Merge pull request #32 from BugBusterSWE/activity#2
Browse files Browse the repository at this point in the history
Activity#2
  • Loading branch information
korut94 committed May 16, 2016
2 parents 9659619 + edc1558 commit 5ca71dc
Show file tree
Hide file tree
Showing 42 changed files with 4,495 additions and 18 deletions.
2 changes: 1 addition & 1 deletion burstmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"moduleResolution" : "node",
"target": "es5",
"declaration": false,
"noImplicitAny": true,
"noImplicitAny": false,
"noEmitOnError": true,
"sourceMap": true
},
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
"author": "BugBusters [email protected]",
"license": "MIT",
"dependencies": {
"express": "^4.13.1"
"express": "^4.13.1",
"mongoose": "^4.4.14",
"promise": "^7.1.1",
"body-parser": "^1.15.1",
"helmet": "^2.0.0"

},
"devDependencies": {
"apidoc": "^0.15.1",
Expand All @@ -50,8 +55,8 @@
"mocha": "^2.4.5",
"rimraf": "^2.5.2",
"tslint": "^3.5.0",
"typedoc": "^0.3.12",
"typedoc": "latest",
"typescript": "^1.8.7",
"typings": "^0.7.9"
"typings": "latest"
}
}
8 changes: 4 additions & 4 deletions src/apidoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example",
"name": "MaaS",
"version": "0.1.0",
"description": "apiDoc basic example",
"title": "Custom apiDoc browser title",
"url" : "https://api.github.com/v1"
"description": "API for MaaS",
"title": "MaaS: MongoDB as a Service API documentation",
"url" : "http://bugbusterswe.github.io/MaaS/"
}
71 changes: 71 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import MongoConnection from "./mongoConnection";

/**
* This is the base class for the configuration hierarchy. This class
* contains some useful information about the configuration of the
* environment.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
abstract class Configuration {
/**
* @description String which represents the name of the environment.
*/
private envName : string;

/**
* @description Parameters used for the connection with the MongoDB
* database.
*/
private mongoConnection : MongoConnection;

/**
* @description String which is used for the JWT token encryption.
*/
private serverSecret : string;

/**
* @description Configuration constructor.
* @param envName The name of the environment
* @param connection The parameters of the MongoDB connection
* @param serverSecret The string for the JWT token encryption.
*/
constructor(envName : string,
connection : MongoConnection,
serverSecret : string) {
this.envName = envName;
this.mongoConnection = connection;
this.serverSecret = serverSecret;
}

/**
* @description Getter for the environment name
* @returns {string} The environment name
*/
public getEnvName() : string {
return this.envName;
}

/**
* @description Getter for the MongoDB connection's parameters
* @returns {MongoConnection} The parameters of the MongoDB connection
*/
public getMongoConnection() : MongoConnection {
return this.mongoConnection;
}

/**
* @description Getter for the JWT token encryption string
* @returns {string} The the JWT token encryption string
*/
public getServerSecret() : string {
return this.serverSecret;
}
}

export default Configuration;
24 changes: 24 additions & 0 deletions src/config/devConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Configuration from "./configuration";
import MongoConnection from "./mongoConnection";
/**
* Development configuration.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
class DevConfiguration extends Configuration {
/**
* @description Complete constructor of the development configuration
* @param connection The parameters for the connection to the database
* @param serverSecret The JWT token's encryption string
*/
constructor(connection : MongoConnection, serverSecret : string) {
super("development", connection, serverSecret);
}
}

export default DevConfiguration;
62 changes: 62 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import MongoConnection from "./mongoConnection";
import Configuration from "./configuration";
import DevConfiguration from "./devConfiguration";
import TestConfiguration from "./testConfiguration";
import ProdConfiguration from "./prodConfiguration";
import {readFileSync} from "fs";

/**
* Class used for get the necessary configuration.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
class ChooseConfiguration {

/**
* @description Return the right configuration according to the Node.js
* environment variable. It may be: 'development', 'test' or 'production'.
* The default configuration is the 'production' one.
* The connection's parameters are read fro an external json file named
* mongoParameters.json.
* @returns {Configuration} The configuration.
*/
public static getConfig() : Configuration {
let params : MongoConnection = JSON.parse(readFileSync(
"src/config/mongoParameters.json",
"utf-8"
));
let connection : MongoConnection = new MongoConnection(
params["user"],
params["password"],
params["host"],
params["port"],
params["dbName"]
);
let serverSecret : string = "serverSecret";
let config : Configuration;

// Export the right configurations according to the NODE_ENV variable
switch (process.env.NODE_ENV) {
case "development":
config = new DevConfiguration(connection, serverSecret);
break;
case "test":
config = new TestConfiguration(connection, serverSecret);
break;
case "production":
config = new ProdConfiguration(connection, serverSecret);
break;
default:
config = new ProdConfiguration(connection, serverSecret);
break;
}
return config;
}
}

export default ChooseConfiguration;
102 changes: 102 additions & 0 deletions src/config/mongoConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* This class stores the parameters for the MondoDB connection.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
class MongoConnection {
/**
* @description The username of the user used for read data from the
* database.
*/
private user : string;

/**
* @description The password of the user used for read data from the
* database.
*/
private password : string;

/**
* @description The host of the database.
*/
private host : string;

/**
* @description The port of the database.
*/
private port : number;

/**
* @description The name of the database.
*/
private dbName : string;

/**
* @description Complete constructor
* @param user Username of the user used for read data from the database
* @param password Password of the user used for read data from the
* database.
* @param host Database's host.
* @param port database's port.
* @param db Database's name.
*/
constructor(user : string, password : string, host : string, port : number,
db : string) {
this.user = user;
this.password = password;
this.host = host;
this.port = port;
this.dbName = db;
}

/**
* @description Getter for the username of the user used for read data from
* the database.
* @returns {string} The username of the user used for read data from the
* database.
*/
public getUser() : string {
return this.user;
}

/**
* @description Getter for the password of the user used for read data from
* the database.
* @returns {string} The password of the user used for read data from the
* database.
*/
public getPassword() : string {
return this.password;
}

/**
* @description Getter for the database's host.
* @returns {string} The host of the database.
*/
public getHost() : string {
return this.host;
}

/**
* @description Getter for database's port.
* @returns {string} The name of the database.
*/
public getDatabasePort() : number {
return this.port;
}

/**
* @description Getter for database's name.
* @returns {string} The name of the database.
*/
public getDatabaseName() : string {
return this.dbName;
}
}

export default MongoConnection;
7 changes: 7 additions & 0 deletions src/config/mongoParameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"user" : "admin",
"password" : "admin",
"host" : "ds013250.mlab.com",
"port" : 13250,
"dbName" : "mongocbtest"
}
26 changes: 26 additions & 0 deletions src/config/prodConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Configuration from "./configuration";
import MongoConnection from "./mongoConnection";

/**
* Production configuration.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
class ProdConfiguration extends Configuration {
/**
* @description Complete constructor of the development configuration
* @param connection The parameters for the connection to the database
* @param serverSecret The JWT token's encryption string
*/
constructor(connection : MongoConnection, serverSecret : string) {
super("production", connection, serverSecret);
}
}

export default ProdConfiguration;

25 changes: 25 additions & 0 deletions src/config/testConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Configuration from "./configuration";
import MongoConnection from "./mongoConnection";

/**
* @description Test configuration.
* @history
* | Author | Action Performed | Data |
* | --- | --- | --- |
* | Matteo Di Pirro | Create class | 04/05/2016 |
*
* @author Matteo Di Pirro
* @license MIT
*/
class TestConfiguration extends Configuration {
/**
* @description Complete constructor of the development configuration
* @param connection The parameters for the connection to the database
* @param serverSecret The JWT token's encryption string
*/
constructor(connection : MongoConnection, serverSecret : string) {
super("test", connection, serverSecret);
}
}

export default TestConfiguration;
Loading

0 comments on commit 5ca71dc

Please sign in to comment.