Skip to content

Commit

Permalink
Merge pull request #15 from SirSeim/frontend
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
NAnguiano authored Oct 23, 2016
2 parents c67a41e + 2ab9649 commit 338a933
Show file tree
Hide file tree
Showing 107 changed files with 12,146 additions and 237 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
db
log
.DS_Store
.sass-cache
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ cd SPFY
npm install
```

configure server with config file to go into `config/default.json`
configure database with user and database for project by having `config/create_spfy.sql`
```
CREATE USER {user} WITH PASSWORD '{password}';
CREATE DATABASE {db, default spfy} OWNER {user};
ALTER USER {user} WITH SUPERUSER;
GRANT ALL PRIVILEGES ON DATABASE "{db, default spfy}" to "{user}";
```
{
"Node-Server": {
"host": <desired host>,
"port": <desired port>,
"logToConsole": <desired logging boolean>

}
}
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

### Using Database
Expand All @@ -57,6 +59,10 @@ Stop Database
```
npm run db-stop
```
Reset Database (stop, initialize, start)
```
npm run db-reset
```

### Running & Development

Expand All @@ -65,6 +71,11 @@ Start server
npm start
```

Alternately, start server to auto restart when a file changes, _provided by [nodemon](https://github.com/remy/nodemon/)_
```
npm run nodemon
```

Run Tests
```
npm test
Expand All @@ -73,7 +84,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-in%20development-red.svg
[version-img]: https://img.shields.io/badge/version-alpha-red.svg
[version-url]: https://github.com/SirSeim/SPFY

[build-img]: https://travis-ci.org/SirSeim/SPFY.svg?branch=master
Expand Down
180 changes: 176 additions & 4 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,188 @@ var Path = require('path');
var Service = require(Path.join(__dirname, 'service.js'));
var Respond = require(Path.join(__dirname, 'respond.js'));

// these functions get called from routes/api_routes.js
var api = {
createClient: function (req, res) {
Service.createClient(req.postgres, req.payload, function (err, result) {
// Where do request and reply come from?
// request - object with details of end user's request (path, payload, auth info, . . .)
// reply - method used to repond to the request
// reply() is an interface that come from Hapi, and Hapi doesn't seem to provide
// the implementation for it, we just have to know that it sends a reply
// back to the frontend containing the data, so calling reply(data) will
// send data as a JSON back to the frontend
createClient: function (request, reply) {
Service.createClient(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateClient(res, err);
Respond.failedToCreateClient(reply, err);
} else {
Respond.createdClient(res, result);
Respond.createdClient(reply, result);
}
});
},

getAllCaseManagers: function (request, reply) {
// this is the getAllCaseManagers() one level deeper in service.js
Service.getAllCaseManagers(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToGetAllCaseManagers(reply, err);
} else {
Respond.getAllCaseManagers(reply, result);
}
});
},

getClient: function (request, reply) {
Service.getClient(request.postgres, request.params.client, function (err, result) {
if (err) {
Respond.failedToGetClient(reply, err);
} else {
Respond.getClient(reply, result);
}
});
},

getClients: function (request, reply) {
if (request.query.firstName || request.query.lastName) {
Service.searchClient(request.postgres, request.query.firstName, request.query.lastName, function (err, result) {
if (err) {
Respond.failedToSearchClient(reply, err);
} else {
Respond.searchClient(reply, result);
}
});
} else {
Service.getClients(request.postgres, function (err, result) {
if (err) {
Respond.failedToGetClients(reply, err);
} else {
Respond.gotClients(reply, result);
}
});
}
},

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

getDropIns: function (request, reply) {
Service.getDropIns(request.postgres, function (err, result) {
if (err) {
Respond.failedToGetDropIns(reply, err);
} else {
Respond.gotDropIns(reply, result);
}
});
},

getDropIn: function (request, reply) {
Service.getDropIn(request.postgres, request.params.dropin, function (err, result) {
if (err) {
Respond.failedToGetDropIn(reply, err);
} else {
Respond.gotDropIns(reply, result);
}
});
},

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

getDropinActivities: function (request, reply) {
Service.getDropinActivities(request.postgres, request.params.dropin, function (err, result) {
if (err) {
Respond.failedToGetDropinActivities(reply, err);
} else {
Respond.gotDropinActivities(reply, result);
}
});
},

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

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

dataBrowserGetClients: function (request, reply) {
Service.dataBrowserGetClients(request.postgres, function (err, result) {
if (err) {
Respond.failedToGetClients(reply, err);
} else {
Respond.dataBrowserGetClients(reply, result);
}
});
},

dataBrowserSearchClients: function (request, reply) {
var data = JSON.parse(request.params.data);
Service.dataBrowserSearchClients(request.postgres, data, function (err, result) {
if (err) {
Respond.failedToGetClient(reply, err);
} else {
Respond.dataBrowserSearchClients(reply, result);
}
});
},

createActivity: function (request, reply){
console.log(request.payload);
Service.createActivity(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateActivity(reply, err);
} else {
Respond.createActivity(reply, result);
}
});
},

editActivity: function (request, reply) {
Service.editActivity(request.postgres, request.params.activity, function (err, result) {
if (err) {
Respond.failedToEditActivity(reply, err);
} else {
Respond.gotEditActivity(reply, result);
}
});
},

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


module.exports = api;
Loading

0 comments on commit 338a933

Please sign in to comment.