Skip to content

Commit

Permalink
Merge pull request #24 from SirSeim/backend
Browse files Browse the repository at this point in the history
Alpha 2
  • Loading branch information
mreid10 authored Nov 3, 2016
2 parents 7d9b5e1 + d506764 commit f3637ef
Show file tree
Hide file tree
Showing 57 changed files with 4,638 additions and 987 deletions.
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
language: node_js
node_js:
- '4.5'
- '4.5'
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
env:
- TRAVIS=travis CXX=g++-4.8
script:
- npm test
- npm run lint
- npm test
- npm run lint
after_script:
- npm run codecov
- npm run codecov
notifications:
email: false
slack:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

[Read our Software Development Plan](docs/Software_Development_Plan.md)

[Read our Architecture Design](docs/Architecture_Design_Document.md)

### Requirements
Install `npm` and `postgres` if you don't already have them installed
```
Expand Down Expand Up @@ -41,7 +43,8 @@ configure server with database access by having `config/set_env.sh`
echo 'postgres://{user}:{password}@{host, default localhost}:{port, default 5432}/{db, default spfy}'
```

Alternately, get the most recent config folder from Team member/Slack
Alternately, get the most recent config folder from Team member/Slack.
The most recent config is from _Oct, 30_.

### Using Database

Expand Down Expand Up @@ -76,6 +79,8 @@ Alternately, start server to auto restart when a file changes, _provided by [nod
npm run nodemon
```

_Note that since_ `authorization` _now is partially functional, you will most likely have to login to try out the site._

Run Tests
```
npm test
Expand All @@ -84,7 +89,7 @@ npm run lint

To view a coverage report, run `npm test`, then `npm run report`, then open up `coverage/lcov-report/index.html` in a webbrowser

[version-img]: https://img.shields.io/badge/version-alpha-red.svg
[version-img]: https://img.shields.io/badge/version-alpha%202-red.svg
[version-url]: https://github.com/SirSeim/SPFY

[build-img]: https://travis-ci.org/SirSeim/SPFY.svg?branch=master
Expand Down
181 changes: 179 additions & 2 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var api = {

createDropIn: function (request, reply) {
Service.createDropIn(request.postgres, request.payload, function (err, result) {
if (err) {
if (err) {
Respond.failedToCreateDropIn(reply, err);
} else {
Respond.createDropIn(reply, result);
Expand Down Expand Up @@ -112,6 +112,16 @@ var api = {
});
},

getDropinEnrollment: function (request, reply) {
Service.getDropinEnrollment(request.postgres, request.params.dropinID, function (err, result) {
if (err) {
Respond.failedToGetDropinEnrollment(reply, err);
} else {
Respond.getDropinEnrollment(reply, result);
}
});
},

enroll: function (request, reply) {
Service.enroll(request.postgres, request.payload, function (err, result) {
if (err) {
Expand All @@ -122,6 +132,16 @@ var api = {
});
},

getEnrollmentByActivity: function (request, reply) {
Service.getEnrollmentByActivity(request.postgres, request.params.activityID, function (err, result) {
if (err) {
Respond.failedToGetEnrollmentByActivity(reply, err);
} else {
Respond.getEnrollmentByActivity(reply, result);
}
});
},

checkin: function (request, reply) {
Service.checkin(request.postgres, request.payload, function (err, result) {
if (err) {
Expand All @@ -131,6 +151,15 @@ var api = {
}
});
},
getCheckIn: function (request, reply) {
Service.getCheckIn(request.postgres, function (err, result) {
if (err) {
Respond.failedToGetCheckIn(reply, err);
} else {
Respond.gotCheckIn(reply, result);
}
});
},

dataBrowserGetClients: function (request, reply) {
Service.dataBrowserGetClients(request.postgres, function (err, result) {
Expand All @@ -154,7 +183,6 @@ var api = {
},

createActivity: function (request, reply){
console.log(request.payload);
Service.createActivity(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateActivity(reply, err);
Expand Down Expand Up @@ -182,6 +210,155 @@ var api = {
Respond.editClient(reply, result);
}
});
},

createCaseNote: function (request, reply) {
Service.createCaseNote(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateCaseNote(reply, err);
} else {
Respond.createCaseNote(reply, result);
}
});
},


getClientCaseNotes: function (request, reply) {
Service.getClientCaseNotes(request.postgres, request.params.clientID, function (err, result) {
if (err) {
Respond.failedToGetClientCaseNotes(reply, err);
} else {
Respond.getClientCaseNotes(reply, result);
}
});
},

editCaseNote: function (request, reply) {
Service.editCaseNote(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToEditCaseNote(reply, err);
} else {
Respond.editCaseNote(reply, result);
}
});
},

getUserList: function (request, reply) {
if (request.query.username) {
Service.getUserByUsername(request.postgres, request.query.username, function (err, user) {
if (err) {
Respond.failedToGetUserByUsername(reply, err);
} else if (user) {
Respond.gotUserByUsername(reply, {
id: user.id,
username: user.username
});
} else {
Respond.noUserByUsernameFound(reply);
}
});
} else {
Service.getUserList(request.postgres, function (err, result) {
if (err) {
Respond.failedToGetUsers(reply, err);
} else {
Respond.gotUsers(reply, result);
}
});
}
},

createUser: function (request, reply) {
Service.getUserByUsername(request.postgres, request.payload.username, function (err, user) {
if (err) {
Respond.failedToGetUserByUsername(reply, err);
} else if (user) {
Respond.usernameAlreadyExists(reply);
} else {
Service.createUser(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateUser(reply, err);
} else {
Respond.createdUser(reply, result);
}
});
}
});
},

login: function (request, reply) {
Service.getUserByUsername(request.postgres, request.payload.username, function (err, user) {
if (err) {
Respond.failedToGetUserByUsername(reply, err);
} else if (!user) {
Respond.userPassNoMatch(reply);
} else {
Service.matchPasswords(request.payload.password, user.hashedPassword, function (err, match) {
if (err) {
Respond.failedToComparePasswords(reply, err);
} else if (!match) {
Respond.userPassNoMatch(reply);
} else {
Service.genToken({
id: user.id,
username: user.username
}, function (err, token) {
if (err) {
Respond.failedToGenToken(reply, err);
} else {
Respond.loggedIn(reply, token);
}
});
}
});
}
});
},

changeCurrentUserPassword: function (request, reply) {
Service.getUserById(request.postgres, request.auth.credentials.id, function (err, user) {
if (err) {
Respond.failedToGetUserById(reply, err);
} else if (!user) {
Respond.noSuchUserExists(reply);
} else {
Service.matchPasswords(request.payload.password, user.hashedPassword, function (err, match) {
if (err) {
Respond.failedToComparePasswords(reply, err);
} else if (!match) {
Respond.passNoMatch(reply);
} else {
var newPassword = request.payload.newPassword;
Service.changeUserPassword(request.postgres, user.id, newPassword, function (err, result) {
if (err) {
Respond.failedToChangeUserPassword(reply, err);
} else {
Service.genToken({
id: user.id,
username: user.username
}, function (err, token) {
if (err) {
Respond.failedToGenToken(reply, err);
} else {
Respond.changeCurrentUserPassword(reply, result, token);
}
});
}
});
}
});
}
});
},

getUsersNotifications: function (request, reply) {
Service.getUsersNotifications(request.postgres, request.auth.credentials, function (err, result) {
if (err) {
Respond.failedToGetUsersNotifications(reply, err);
} else {
Respond.getUsersNotifications(reply, result);
}
});
}
};

Expand Down
Loading

0 comments on commit f3637ef

Please sign in to comment.