diff --git a/README.md b/README.md index bb94140..5b1d078 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ In addition, it sets up the mongo deamon to start up automatically with the syst For production setup run the script, described in _Setup for development_, adding the parameter `prod` - ./docs/opt-cc-environment/3rd-party-install.sh prod + ./docs/opt-cc-environment/3rd-party-install.sh prod This adds the [`pm2` process manager](http://pm2.keymetrics.io/) to be installed and start the _opt-cc_ server as `pm2` process. Run the `sudo` command printed as last output to configure the `pm2` process for automatic start on the system. diff --git a/api/apib/overview/army.apib b/api/apib/army-management/army.apib similarity index 100% rename from api/apib/overview/army.apib rename to api/apib/army-management/army.apib diff --git a/api/apib/army-management/awardings.apib b/api/apib/army-management/awardings.apib index 825767e..f469a5d 100644 --- a/api/apib/army-management/awardings.apib +++ b/api/apib/army-management/awardings.apib @@ -1,18 +1,24 @@ -### GET Awardings [GET /awardings{?userId,confirmed}] +### GET Awardings [GET /awardings{?userId,inProgress,fractFilter}] List all awardings + Parameters + userId (string, optional) - specific army member Id to show the awardings for + specific army member Id to show the awardings for - + confirmed (number, optional) - Field to filter by request awarding state + + inProgress (boolean, optional) + true to filter by awarding state 'in progress' + + + Default: false + + + fractFilter (enum[string], optional) + Field to filter by fraction + Members - + 0 - not decided - + 1 - confirmed - + 2 - rejected + + `BLUFOR` + + `OPFOR` + + `GLOBAL` + + Response 200 diff --git a/api/apib/army-management/promotions.apib b/api/apib/army-management/promotions.apib new file mode 100644 index 0000000..09dea0f --- /dev/null +++ b/api/apib/army-management/promotions.apib @@ -0,0 +1,25 @@ +### GET Promotions [GET /promotion{?squadId,inProgress,fractFilter}] + +List all promotion requests + ++ Parameters + + squadId (string, optional) + specific squad Id to show the promotion requests for + + + inProgress (boolean, optional) + true to filter by promotion state 'in progress' + + + Default: false + + + fractFilter (enum[string], optional) + Field to filter by fraction + + + Members + + `BLUFOR` + + `OPFOR` + + `GLOBAL` + + ++ Response 200 + + + Attributes (array[Promotion]) diff --git a/api/apib/army-management/users.apib b/api/apib/army-management/users.apib index 60d441a..d0c6159 100644 --- a/api/apib/army-management/users.apib +++ b/api/apib/army-management/users.apib @@ -1,7 +1,38 @@ -### GET User [GET /users/:id] +### GET Users [GET /users{?q,fractFilter,limit,offset}] Get single army member information ++ Parameters + + q: `hardi` (string, optional) - filter string which filters for partial username + + + fractFilter (enum[string], optional) + Field to filter by fraction + + + Members + + `BLUFOR` + + `OPFOR` + + `GLOBAL` + + + limit: 20 (number, optional) + Maximum number of users to return + + + offset (number, optional) + Offset into result-set (useful for pagination) + + + Default: 0 + ++ Response 200 + + + Attributes (array[User]) + + +### GET User [GET /users/{id}] + +Get single army member information + ++ Parameters + + id: `5ab68d42f547ed304064e5f7` (string, required) - unique id of army-member + + Response 200 + Attributes (User) diff --git a/api/apib/auth/login.apib b/api/apib/auth/login.apib index 9d13aed..e0a4023 100644 --- a/api/apib/auth/login.apib +++ b/api/apib/auth/login.apib @@ -2,7 +2,7 @@ Generate a token which can be used to make API requests. -+ Request Generate Token ++ Request Generate Token (application/json) + Attributes (Login) diff --git a/api/apib/base/file-resources.apib b/api/apib/base/file-resources.apib new file mode 100644 index 0000000..847f9e0 --- /dev/null +++ b/api/apib/base/file-resources.apib @@ -0,0 +1,36 @@ +The running express server instance saves entity related files like squad logos and statistic logs on the file system. +In the original mean application they are served in the `/resource` path of the application server. + +The following examples show where those files are located, to be accessed on the cloud instance. + +## Images +**Decoration Image** + +`https://cc.noarch.de/resource/decoration/{decorationId}.png` + +**Rank Image** + +`https://cc.noarch.de/resource/rank/{rankId}.png` + +**Signature Image** + +`https://cc.noarch.de/resource/signature/{userId}.png` + +**Squad Logo** + +`https://cc.noarch.de/resource/squad/{squadId}.png` + +## Log-Files + +**Sanitized Log File** + +`https://cc.noarch.de/resource/logs/{warId}/clean.log` + +**Original Uploaded Log File** + +`https://cc.noarch.de/resource/logs/{warId}/war.log` + + + + + diff --git a/api/apib/data_structures/_app-user.apib b/api/apib/data_structures/_app-user.apib new file mode 100644 index 0000000..28ec103 --- /dev/null +++ b/api/apib/data_structures/_app-user.apib @@ -0,0 +1,8 @@ +# Proposer (object) +Representation of an app user who proposed an awarding or a promotion + +## Properties + ++ _id: `593d5e3f72d35225222bcaba` (string, required) - unique id of the app user ++ username: `hardiready` (string, required) - username of the app user ++ squad: `591470249e9fae286e308e41` (string, required) - squad id associated with the app user diff --git a/api/apib/data_structures/_auth.apib b/api/apib/data_structures/_auth.apib index 1caf9da..cdafe3b 100644 --- a/api/apib/data_structures/_auth.apib +++ b/api/apib/data_structures/_auth.apib @@ -3,7 +3,7 @@ User related entity for creating a token using application credentials ## Properties -+ username: `hardiready` (string, required) - username of the app-user ++ username: `testuser` (string, required) - username of the app-user + password: `password` (string, required) - password of the app-user # LoginResponse (object) diff --git a/api/apib/data_structures/_awarding.apib b/api/apib/data_structures/_awarding.apib index 14076a1..e49da85 100644 --- a/api/apib/data_structures/_awarding.apib +++ b/api/apib/data_structures/_awarding.apib @@ -7,6 +7,7 @@ Awarding associating a decoration to a user + date: `2017-05-17T19:44:24.926Z` (string, required) - date when the awarding was requested + decorationId (Decoration, required) - populated decoration object that is given with the awarding + reason: `war dabei` (string, required) - reason for giving the awarding ++ proposer (Proposer, required) - app user who requested this awarding, null if awarding was given directly + timestamp: `2017-05-17T19:44:28.751Z` (string, required) - creation date + updatedAt: `"2017-05-17T19:44:28.751Z` (string, required) - version date + userId: `5918d2ca574b0b1d820a0b24` (string, required) - the unique id of the user who got this awarding diff --git a/api/apib/data_structures/_promotion.apib b/api/apib/data_structures/_promotion.apib new file mode 100644 index 0000000..4c8a7ad --- /dev/null +++ b/api/apib/data_structures/_promotion.apib @@ -0,0 +1,13 @@ +# Promotion (object) +Representation of a promotion request for a army member + +## Properties ++ _id: `5as7d05dcb90ce4da68c4f5f` (string, required) - unique id of the promotion request ++ confirmed: 0 (number, required) - number representing status of the promotion (0 - in progress, 1 - approved, 2 - rejected) ++ newRankLvl: 14 - new rank level that is requested in this promotion ++ oldRankLvl: 10 - old rank level of the user ++ proposer (Proposer, required) - app user who requested the promotion ++ timestamp: `2018-03-25T18:54:21.609Z` (string, required) - creation timestamp ++ updatedAt: `2018-03-25T18:54:21.609Z` (string, required) - version timestamp ++ userId (User, required) - populated user instance of user the promotion is requested for ++ __v: 0 (number, required) - version number of promotion instance diff --git a/api/apib/data_structures/_user.apib b/api/apib/data_structures/_user.apib index 67de2a9..9d94d1d 100644 --- a/api/apib/data_structures/_user.apib +++ b/api/apib/data_structures/_user.apib @@ -2,7 +2,7 @@ A participant managed in the system ## Properties -+ _id: `5918d2ca574b0b1d820a0b24` (string, required) - unique id of the army member ++ _id: `5ab68d42f547ed304064e5f7` (string, required) - unique id of the army member + username: `Jagernaut` - the displayed username of the army member + rankLvl: 22 (number, required) - rank level representing the rank + squadId (Squad, required) - populated squad which the army member is part of diff --git a/api/apib/data_structures/index.apib b/api/apib/data_structures/index.apib index 013bbdc..9f2c0ca 100644 --- a/api/apib/data_structures/index.apib +++ b/api/apib/data_structures/index.apib @@ -1,5 +1,7 @@ # Data Structures +:[Gists](_app-user.apib) + :[Gists](_army.apib) :[Gists](_auth.apib) @@ -8,6 +10,8 @@ :[Gists](_decoration.apib) +:[Gists](_promotion.apib) + :[Gists](_squad.apib) :[Gists](_user.apib) diff --git a/api/apib/dev-doc.apib b/api/apib/dev-doc.apib index aeac9a4..b755033 100644 --- a/api/apib/dev-doc.apib +++ b/api/apib/dev-doc.apib @@ -10,6 +10,10 @@ FORMAT: 1A :[Gists](base/datetime.apib) +# Group File Resources + +:[Gists](base/file-resources.apib) + # Group Access :[Gists](auth/signup.apib) @@ -18,6 +22,10 @@ FORMAT: 1A # Group Account +# Group Army Overview + +:[Gists](army-management/army.apib) + # Group Awardings :[Gists](army-management/awardings.apib) @@ -30,16 +38,14 @@ FORMAT: 1A # Group Logs -# Group Overview - -:[Gists](overview/army.apib) - # Group Players # Group Ranks # Group Requests +:[Gists](army-management/promotions.apib) + # Group Squads # Group Users diff --git a/api/apib/dredd/data/app_user.json b/api/apib/dredd/data/app_user.json new file mode 100644 index 0000000..706e70b --- /dev/null +++ b/api/apib/dredd/data/app_user.json @@ -0,0 +1 @@ +{"_id":{"$oid":"5ab68ceef547ed304064e5f6"},"squad":null,"permission":3,"activated":true,"username":"testuser","secret":"my secret","password":"$2a$10$wvgBbcckHrFu8Ctw8hSPNuFLoBy4sRubioyiK1NabOC0UgYD.KITi","timestamp":{"$date":"2018-03-24T17:37:50.668Z"},"updatedAt":{"$date":"2018-03-24T17:37:50.668Z"},"__v":0} diff --git a/api/apib/dredd/data/awarding.json b/api/apib/dredd/data/awarding.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/campaign.json b/api/apib/dredd/data/campaign.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/decoration.json b/api/apib/dredd/data/decoration.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logBudget.json b/api/apib/dredd/data/logBudget.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logFlag.json b/api/apib/dredd/data/logFlag.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logKill.json b/api/apib/dredd/data/logKill.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logPoints.json b/api/apib/dredd/data/logPoints.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logRespawn.json b/api/apib/dredd/data/logRespawn.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logRevive.json b/api/apib/dredd/data/logRevive.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/logTransport.json b/api/apib/dredd/data/logTransport.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/player.json b/api/apib/dredd/data/player.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/promotion.json b/api/apib/dredd/data/promotion.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/rank.json b/api/apib/dredd/data/rank.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/squad.json b/api/apib/dredd/data/squad.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/data/user.json b/api/apib/dredd/data/user.json new file mode 100644 index 0000000..45b6e36 --- /dev/null +++ b/api/apib/dredd/data/user.json @@ -0,0 +1 @@ +{"_id":{"$oid":"5ab68d42f547ed304064e5f7"},"rankLvl":0,"squadId":null,"username":"user1","timestamp":{"$date":"2018-03-24T17:39:14.841Z"},"updatedAt":{"$date":"2018-03-24T17:39:14.841Z"},"__v":0} diff --git a/api/apib/dredd/data/war.json b/api/apib/dredd/data/war.json new file mode 100644 index 0000000..e69de29 diff --git a/api/apib/dredd/populate-data.sh b/api/apib/dredd/populate-data.sh new file mode 100755 index 0000000..0232f00 --- /dev/null +++ b/api/apib/dredd/populate-data.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +########## IMPORT EXPORT/SCRIPT FOR DREDD TEST DATA ############ +###----------------------------------------------------------### +###------------------ HOW TO USE THIS FILE ------------------### +###----------------------------------------------------------### +### 1. start express server with `npm run start-test` ### +### 2. import data by executing script: `./populate-data.sh` ### +### 3. change data in app as you need for tests ### +### 4. export data state with: `./populate-data.sh save` ### +################################################################ + +# execute script in its location folder +cd $(dirname $0) + +# array of available collection names +col=(app_user awarding campaign decoration logBudget logFlag logKill logPoints logRespawn logRevive logTransport player promotion rank squad user war ) + +for i in "${col[@]}" +do + # provide date for restore process, if data import is needed + if [ "$1" == "save" ] + then + echo -e "$(date "+%Y-%m-%dT%T.%3N%z")\tTable: ${i}" + mongoexport --db cc-test --collection $i --out data/${i}.json; + else + mongoimport --db cc-test --collection $i --drop --file data/${i}.json + fi +done diff --git a/api/package.json b/api/package.json index 728bd33..8b040f0 100644 --- a/api/package.json +++ b/api/package.json @@ -14,7 +14,7 @@ "start-test": "DEBUG='cc:*' NODE_ENV=test node server.js", "api:compile-docs": "$(npm bin)/hercule apib/dev-doc.apib -o apib/documentation.apib", "api:publish-docs": "$(npm bin)/aglio --theme-variables slate -i ./apib/documentation.apib -o ../public/api-docs.html", - "api:test-docs": "$(npm bin)/dredd", + "api:test-docs": "npm run api:docs && ./apib/dredd/populate-data.sh && $(npm bin)/dredd", "api:docs": "npm run api:compile-docs && npm run api:publish-docs" }, "dependencies": { diff --git a/api/routes/awardings.js b/api/routes/awardings.js index 7fbb84c..2402632 100644 --- a/api/routes/awardings.js +++ b/api/routes/awardings.js @@ -32,47 +32,30 @@ awarding.route('/') if (req.query.inProgress) { filter.confirmed = 0; } - if (req.query.simple) { - AwardingModel.find(filter, {}, {sort: {date: 'desc'}}, (err, items) => { - if (err) { - err.status = codes.servererror; - return next(err); - // with return before (or after) the next(err) we prevent that the code continues here after next(err) - // has finished. this saves an extra else {..} - } - // if the collection is empty we do not send empty arrays back. - if (items && items.length > 0) { - res.locals.items = items; - } - res.locals.processed = true; - next(); - }); - } else { - AwardingModel.find(filter, {}, {sort: {date: 'desc'}}) - .populate('decorationId').populate('proposer', resultSet) - .exec((err, items) => { - if (err) { - err.status = codes.servererror; - return next(err); - // with return before (or after) the next(err) we prevent that the code continues here - // after next(err) has finished. this saves an extra else {..} - } - let results = []; - if (req.query.fractFilter) { - for (let item of items) { - if (item.decorationId.fraction === req.query.fractFilter) { - results.push(item); - } + AwardingModel.find(filter, {}, {sort: {date: 'desc'}}) + .populate('decorationId').populate('proposer', resultSet) + .exec((err, items) => { + if (err) { + err.status = codes.servererror; + return next(err); + // with return before (or after) the next(err) we prevent that the code continues here + // after next(err) has finished. this saves an extra else {..} + } + let results = []; + if (req.query.fractFilter) { + for (let item of items) { + if (item.decorationId.fraction === req.query.fractFilter) { + results.push(item); } - res.locals.items = results; - } else { - res.locals.items = items; } + res.locals.items = results; + } else { + res.locals.items = items; + } - res.locals.processed = true; - next(); - }); - } + res.locals.processed = true; + next(); + }); }) .post(apiAuthenticationMiddleware, checkHl, (req, res, next) => { diff --git a/api/routes/request.js b/api/routes/request.js index 0dfdfc4..17916b6 100644 --- a/api/routes/request.js +++ b/api/routes/request.js @@ -58,7 +58,7 @@ request.route('/award') request.route('/promotion') .get((req, res, next) => { - // TODO: add SQL authentication + // TODO: add SQL authentication? const squadFilter = req.query.squadId; const fractFilter = req.query.fractFilter; const progressFilter = req.query.inProgress; diff --git a/package.json b/package.json index 0eaab0e..59608ba 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test": "npm test --prefix ./api", "e2e": "npm run deploy-static && concurrently \"npm run start-test --prefix ./api\" \"wait-on -t 60000 http://localhost:3001/ && npm run e2e --prefix ./static\" --success first --kill-others", "start-e2e": "npm run deploy-static && npm run start-test --prefix ./api", - "test-e2e": "npm run e2e --prefix ./static" + "test-e2e": "npm run e2e --prefix ./static", + "test-api": "npm run api:test-docs --prefix ./api" }, "dependencies": {}, "devDependencies": {