Commit 7ca5ab40 by Jose Antonio

Issue #208, timestamps

parent fee15f4f
......@@ -42,7 +42,6 @@ module.exports = {
if (!params.type) return res.json(500, {error: "No type of action defined"});
// Optional params
var timestamp = params.timestamp ? params.timestamp : null;
var sup = null; if(params.supervisor) sup = params.supervisor;
var _try = null; if(params._try) _try = params._try;
var description = null; if(params.description) description = params.description;
......@@ -52,7 +51,7 @@ module.exports = {
// Create a generic Action. Return open (=current, new) try
Action.create({
"type": params.type,
"timestamp": timestamp,
"timestamp": new Date().toISOString(),
"supervisor": sup,
"student": params.student,
"_try": _try,
......
......@@ -40,7 +40,7 @@ module.exports = {
name: req.param('name'),
objective: req.param('objective'),
status: req.param('status'),
begin: req.param('begin'),
begin: new Date().toISOString(),
end: req.param('end')
}).then(function (instruction) {
if (instruction) {
......
......@@ -7,11 +7,10 @@ module.exports = {
var params = req.allParams();
if (!params.ws) return res.badRequest("No workingSession defined");
if (!params.begin) return res.badRequest("No begin defined");
Try.create({
"workingSession":params.ws,
"begin": params.begin
"begin": new Date().toISOString()
}).exec(function(err, tr){
if(err || !tr){
sails.log.debug("Creating new Try: " + err);
......@@ -23,11 +22,15 @@ module.exports = {
/**
* Update a try
* Note that in order to update `end` field, value must be sent, the server
* will set the value acording to it's time. If no `end` is submited to this
* method, it wont be updated.
*/
update: function(req, res) {
var params = req.allParams();
if (!params.id) return res.badRequest("No try defined");
if (params.end) prams.end = new Date().toISOString();
Try.update(params.id, params)
.then(function (t) {
......
......@@ -19,7 +19,7 @@ module.exports = {
if (!req.params.id_ws)
res.badRequest("No working session defined");
var ws_end = req.params.end ? req.params.end : new Date().toISOString();
var ws_end = new Date().toISOString();
WorkingSession.update({id: req.params.id_ws}, {end: ws_end})
.then(function(t) {
res.ok({end: ws_end});
......@@ -48,7 +48,6 @@ module.exports = {
id_sup: <supervisor ID>
id_stu: <student ID>
id_ins: <instruction ID>
begin: <begin timestamp in ISO format>
* }
* @param {response} res
* {
......@@ -63,15 +62,14 @@ module.exports = {
if (!params.id_sup) res.badRequest("No supervisor defined");
if (!params.id_ins) res.badRequest("No instruction defined");
if (!params.id_stu) res.badRequest("No student defined");
if (!params.begin) res.badRequest("No start timestamp defined");
if (!params.desc) params.desc = "";
var data = {};
data.supervisor = params.id_sup;
data.instruction = params.id_ins;
data.description = params.desc;
sails.log.debug("BEGIN " + params.begin);
data.begin = params.begin; // data comes in ISO format
sails.log.debug("BEGIN " + new Date().toISOString());
data.begin = new Date().toISOString(); // data comes in ISO format
StuOpenTry.findOne({or: [ // pending open try?
{ id_sup : params.id_sup },
......@@ -161,7 +159,7 @@ module.exports = {
// Create the EndSession Action
Action.create({
"type": "endsession",
"timestamp": ws[0].end.toISOString(),
"timestamp": new Date().toISOString(),
"supervisor": ws[0].supervisor,
"student": params.id_stu
}).exec(function(err, action){
......
......@@ -40,7 +40,8 @@ module.exports = {
]
},
timestamp: {
type: "datetime"
type: "datetime",
defaultsTo: function() { return new Date(); }
},
supervisor: { // FK de Supervisor. 1 a N
columnName: "id_sup",
......
......@@ -29,7 +29,8 @@ module.exports = {
via: '_try'
},
begin: {
type: "datetime"
type: "datetime",
defaultsTo: function() { return new Date(); }
},
end: {
type: "datetime"
......
......@@ -34,7 +34,7 @@ module.exports = {
},
begin: {
type: "datetime",
defaultsTo: function() { return new Date(); }
defaultsTo: function() { return new Date().toISOString(); }
},
end: {
type: "datetime"
......
......@@ -178,8 +178,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/ws', {
"id_sup": $scope.user.id,
"id_stu": $scope.studentData.id,
"id_ins": $scope.selected.instruction.id,
"begin": new Date().toISOString()
"id_ins": $scope.selected.instruction.id
})
.success(function(data, status, headers, config) {
// Actual WS
......@@ -240,7 +239,6 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(
config.backend+'/ws/' + $scope.ws.id + '/close',
{
"end": $scope.ws.end.toISOString(),
"id_stu": $scope.studentData.id
}
)
......@@ -272,8 +270,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', {
"type": "pausesession",
"student": $scope.studentData.id,
"supervisor": $scope.user.id,
"timestamp": (new Date()).toISOString()
"supervisor": $scope.user.id
})
.success(function(data, status, headers, config) {
// adding pause action to the list of actions
......@@ -301,7 +298,6 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
"type": "resumesession",
"student": $scope.studentData.id,
"supervisor": $scope.user.id,
"timestamp": (new Date()).toISOString()
})
.success(function(data, status, headers, config) {
// Adding resume action to the list of actions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment