Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0bcffb20
authored
Dec 28, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #725 fixed
parent
beb487da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
14 deletions
sails/src/api/controllers/StudentController.js
sails/src/assets/scripts/modules/student/controllers/setup.js
sails/src/api/controllers/StudentController.js
View file @
0bcffb20
...
...
@@ -203,26 +203,40 @@ module.exports = {
//
update
:
function
(
req
,
res
)
{
if
(
!
req
.
params
.
id_stu
)
{
res
.
badRequest
();
function
promisifyLicenseActivate
(
license_number
,
stu_id
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
License
.
activate
(
license_number
,
stu_id
,
function
(
err
,
result
)
{
if
(
err
)
return
reject
(
err
);
resolve
(
result
);
});
});
}
if
(
!
req
.
params
.
id_stu
)
return
res
.
badRequest
();
Student
.
findOne
(
req
.
params
.
id_stu
)
.
populate
(
'license'
)
.
then
(
function
(
stu
)
{
var
k
;
var
current_license
;
if
(
!
stu
)
throw
new
Error
(
"Student not found"
);
console
.
log
(
"->s1"
+
JSON
.
stringify
(
stu
));
// Update license
if
(
req
.
body
.
license_number
)
if
(
!
stu
.
license
[
0
]
||
req
.
body
.
license_number
!=
stu
.
license
[
0
].
number
)
{
License
.
activate
(
req
.
body
.
license_number
,
stu
.
id
,
function
(
err
,
license
)
{
if
(
err
)
return
res
.
badRequest
(
err
);
});
}
if
(
req
.
body
.
license_number
&&
(
!
stu
.
license
[
0
]
||
req
.
body
.
license_number
!=
stu
.
license
[
0
].
number
))
current_license
=
promisifyLicenseActivate
(
req
.
body
.
license_number
,
stu
.
id
);
else
current_license
=
Promise
.
resolve
(
stu
.
license
);
return
([
stu
,
current_license
]);
})
.
spread
(
function
(
stu
,
license
)
{
console
.
log
(
"->s3"
+
JSON
.
stringify
(
stu
));
console
.
log
(
"->l4"
+
JSON
.
stringify
(
license
));
// copy attributes
for
(
k
in
req
.
body
)
stu
[
k
]
=
req
.
body
[
k
];
...
...
@@ -230,9 +244,6 @@ module.exports = {
if
(
!
req
.
body
.
password
)
// to avoid change password when no one is provided
delete
stu
.
password
;
// delete license attribute as this has been already handled
delete
stu
.
license
;
// delete username, as this should never be updated from requests
delete
stu
.
username
;
...
...
@@ -240,6 +251,8 @@ module.exports = {
if
(
err
)
throw
err
;
console
.
log
(
"->s5"
+
JSON
.
stringify
(
stu
));
stu
.
license
=
license
;
res
.
ok
(
stu
);
// Send websocket message
...
...
@@ -249,6 +262,7 @@ module.exports = {
(
req
.
isSocket
)
?
req
.
socket
:
undefined
);
});
})
.
catch
(
function
(
err
)
{
res
.
notFound
();
...
...
sails/src/assets/scripts/modules/student/controllers/setup.js
View file @
0bcffb20
...
...
@@ -138,9 +138,9 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
})
.
error
(
function
(
err
)
{
console
.
log
(
err
);
if
(
err
.
message
.
search
(
'nvalid license'
))
if
(
err
.
message
&&
err
.
message
.
search
(
'nvalid license'
))
ngToast
.
danger
({
content
:
$translate
.
instant
(
'license_invalid'
)
});
else
if
(
err
.
message
.
search
(
'in use'
))
else
if
(
err
.
message
&&
err
.
message
.
search
(
'in use'
))
ngToast
.
danger
({
content
:
$translate
.
instant
(
'license_already_activated'
)
});
else
ngToast
.
danger
({
content
:
$translate
.
instant
(
'student_not_updated'
)
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment