Skip to content

Commit

Permalink
Merge pull request #48 from SirSeim/caseplan
Browse files Browse the repository at this point in the history
Caseplan
  • Loading branch information
Irakli Khizanishvili authored Dec 2, 2016
2 parents 1d0711a + e32052c commit 9b5cab9
Show file tree
Hide file tree
Showing 14 changed files with 482 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,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%202-red.svg
[version-img]: https://img.shields.io/badge/version-alpha%203-red.svg
[version-url]: https://github.com/SirSeim/SPFY

[build-img]: https://travis-ci.org/SirSeim/SPFY.svg?branch=master
Expand Down
35 changes: 32 additions & 3 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,15 @@ var api = {
});
},

createCasePlan: function (request, reply) {
Service.createCasePlan(request.postgres, request.payload, function (err, result) {
if (err) {
Respond.failedToCreateCasePlan(reply, err);
} else {
Respond.createCasePlan(reply, result);
}
});
},
createNotification: function (request, reply) {
var userId;
if (request.params.userId === 'self') {
Expand All @@ -489,7 +498,7 @@ var api = {
}
});
},

getUsersNotificationsById: function (request, reply) {
var userId;
if (request.params.userId === 'self') {
Expand Down Expand Up @@ -551,6 +560,27 @@ var api = {
}
});
},
getCasePlan: function (request, reply) {
console.log('We are inside of api.js');
Service.getCasePlan(request.postgres, request.params.clientID, function (err, result) {
if (err) {
Respond.failedToGetCasePlan(reply, err);
} else {
Respond.getCasePlan(reply, result);
}
});

},

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

getClientFiles: function (request, reply) {
Service.getClientFiles(request.postgres, request.params.clientID, function (err, result) {
Expand Down Expand Up @@ -621,7 +651,7 @@ var api = {
}
});
},

getClientFlags: function (request, reply) {
Service.getClientFlags(request.postgres, request.params.clientID, function (err, result) {
if (err) {
Expand All @@ -641,7 +671,6 @@ var api = {
}
});
}

};


Expand Down
39 changes: 33 additions & 6 deletions api/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ var queries = {

getClient: function (clientID) {
var queryString = 'SELECT id, first_name, last_name, intake_date, phone_number, email, ' +
'date_of_birth, age(date_of_birth), status FROM client WHERE id = ' +
'date_of_birth, age(date_of_birth), status, caseplan FROM client WHERE id = ' +

'\'' + clientID + '\'' + ';';
return queryString;
},
Expand Down Expand Up @@ -407,7 +408,7 @@ var queries = {

queryString += 'WHERE id = ' + '\'' + payload.id + '\'' + ' ';

queryString += 'RETURNING id, first_name, last_name, date_of_birth, ' +
queryString += 'RETURNING id, first_name, last_name, date_of_birth, ' +
'intake_age, phone_number, email, case_manager, status;';

return queryString;
Expand Down Expand Up @@ -747,7 +748,7 @@ var queries = {
var queryString = 'UPDATE status SET ' +
'name = \'' + payload.name + '\', ' +
'color = \'' + payload.color + '\' ' +
'WHERE id = \'' + statusID + '\'' +
'WHERE id = \'' + statusID + '\'' +
'RETURNING id, name, color;';
return queryString;
},
Expand All @@ -774,7 +775,7 @@ var queries = {
'message = \'' + payload.message + '\', ' +
'color = \'' + payload.color + '\', ' +
'note = \'' + payload.note + '\' ' +
'WHERE id = ' + flagID +
'WHERE id = ' + flagID +
' RETURNING id, type, message, color, note;';
return queryString;
},
Expand Down Expand Up @@ -803,10 +804,36 @@ var queries = {
},

getProfilePicture: function (clientID) {
var queryString = 'SELECT name, type, base_64_string FROM file WHERE client_id = ' + clientID +
var queryString = 'SELECT name, type, base_64_string FROM file WHERE client_id = ' + clientID +
'AND type=\'profile_picture\';';
return queryString;
}
},

createCasePlan: function (payload) {
var queryString = 'INSERT INTO caseplan (client_id, case_manager_id, date, note, ) VALUES (' +
'\'' + parseProperty(payload.clientID) + '\'' + ', ' +
'\'' + parseProperty(payload.caseManagerID) + '\'' + ', ' +
'\'' + parseProperty(payload.date) + '\'' + ', ' +
'\'' + parseProperty(payload.note) + '\'' + ', ';

return queryString;
},

editCasePlan: function (payload) {
var queryString = 'UPDATE client SET ';
queryString += 'caseplan = ' + '\'' + payload.text + '\'' + ' ';
queryString += 'WHERE id = ' + '\'' + payload.clientID + '\'' + ' ';

queryString += 'RETURNING caseplan;';

return queryString;
},

getCasePlan: function (clientID) {
var queryString = 'SELECT caseplan FROM client WHERE id =' + clientID + ";";

return queryString;
},
};

module.exports = queries;
56 changes: 46 additions & 10 deletions api/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,27 @@ var query = {
});
});
},
createCasePlan: function (postgres, payload, callback) {
postgres.connect(function (err, client, done) {
if (err) {
return callback(err);
}
client.query(Queries.createCasePlan(payload), function (err, result) {
done();
if (err) {
return callback(err);
}

return callback(undefined, result);
});
});
},
deleteUser: function (postgres, userId, callback) {
postgres.connect(function (err, client, done) {
if (err) {
return callback(err);
}

client.query(Queries.deleteUser(userId), function (err, result) {
done();
if (err) {
Expand Down Expand Up @@ -678,7 +692,7 @@ var query = {
return callback(undefined, result);
});
});
},
},

getStatuses: function (postgres, callback) {
postgres.connect(function (err, client, done) {
Expand Down Expand Up @@ -721,11 +735,7 @@ var query = {
if (err) {
return callback(err);
}

// var data = Queries.editStatus(statusID);
// // unstringify the data passed in
client.query(Queries.editStatus(statusID, payload), function (err, result) {
// client.query(data.string, data.params, function (err, result) {
done();
if (err) {
return callback(err);
Expand All @@ -736,6 +746,22 @@ var query = {
});
},

getCasePlan: function (postgres, clientID, callback) {
console.log('We are inside of query.js');
postgres.connect(function (err, client, done) {
if (err) {
return callback(err);
}
client.query(Queries.getCasePlan(clientID), function (err, result) {
done();
if (err) {
return callback(err);
}

return callback(undefined, result);
});
});
},
getFlags: function (postgres, callback) {
postgres.connect(function (err, client, done) {
if (err) {
Expand All @@ -757,8 +783,6 @@ var query = {
if (err) {
return callback(err);
}
// var data = Queries.createFlag(payload);
// // unstringify the data passed in
client.query(Queries.createFlag(payload), function (err, result) {
// client.query(data.string, data.params, function (err, result) {
done();
Expand Down Expand Up @@ -789,7 +813,21 @@ var query = {
});
});
},
editCasePlan: function (postgres, payload, callback) {
postgres.connect(function (err, client, done) {
if (err) {
return callback(err);
}
client.query(Queries.editCasePlan(payload), function (err, result) {
done();
if (err) {
return callback(err);
}

return callback(undefined, result);
});
});
},
getClientFiles: function (postgres, clientID, callback) {
postgres.connect(function (err, client, done) {
if (err) {
Expand All @@ -805,7 +843,6 @@ var query = {
});
});
},

getClientFlags: function (postgres, clientID, callback) {
postgres.connect(function (err, client, done) {
if (err) {
Expand All @@ -824,7 +861,6 @@ var query = {
});
});
},

getProfilePicture: function (postgres, clientID, callback) {
postgres.connect(function (err, client, done) {
if (err) {
Expand Down
42 changes: 42 additions & 0 deletions api/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,48 @@ var respond = {
result: result
}).code(200).header("Authorization", token);
},
failedToGetCasePlan: function (reply, err) {
reply({
statusCode: 500,
message: "Unable to get client's case plan!",
error: err
}).code(500);
},
getCasePlan: function (reply, result) {
reply({
statusCode: 200,
message: "Successfully got client's case plan.",
result: result
}).code(200);
},
failedToEditCasePlan: function (reply, err) {
reply({
statusCode: 500,
message: "Unable to edit case plan!",
error: err
}).code(500);
},
editCasePlan: function (reply, result) {
reply({
statusCode: 200,
message: "Successfully edited case plan.",
result: result
}).code(200);
},
failedToCreateCasePlan: function (reply, err) {
reply({
statusCode: 500,
message: "Unable to create case plan!",
error: err
}).code(500);
},
createCasePlan: function (reply, result) {
reply({
statusCode: 200,
message: "Successfully created case plan.",
result: result
}).code(200);
},
failedToDeleteUser: function (reply, err) {
reply({
statusCode: 500,
Expand Down
41 changes: 40 additions & 1 deletion api/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,36 @@ var service = {
});
},

createCasePlan: function (postgres, data, callback) {
Query.createCasePlan(postgres, data, function (err, result) {
if (err) {
return callback(err);
}
return callback(undefined, result);
});
},

getCasePlan: function (postgres, data, callback) {
console.log('We are inside of service.js');

Query.getCasePlan(postgres, data, function (err, result) {
if (err) {
return callback(err);
}
if (!result.rows[0]) {
return callback();
}
var arr = [];
for (var i = 0; i < result.rows.length; i++) {
var local = result.rows[i];
arr.push({
caseplan: local.caseplan
});
}
return callback(undefined, arr);
});
},

deleteUser: function (postgres, userId, callback) {
Query.deleteUser(postgres, userId, callback);
},
Expand Down Expand Up @@ -633,7 +663,16 @@ var service = {
note: local.note
});
}
return callback(undefined, arr);
callback(undefined, arr);
});
},

editCasePlan: function (postgres, data, callback) {
Query.editCasePlan(postgres, data, function (err, result) {
if (err) {
return callback(err);
}
return callback(undefined, result);
});
},

Expand Down
Loading

0 comments on commit 9b5cab9

Please sign in to comment.