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
fd4cd3e5
authored
May 10, 2017
by
Jose Antonio
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Issue
#200
, column in table student
parent
46eab3b8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
48 deletions
sails/roles/database/files/pictodb-schema.sql
sails/roles/database/files/scene_adapt.sql
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
sails/src/CHANGES.md
sails/src/api/controllers/StudentController.js
sails/src/api/models/Student.js
sails/roles/database/files/pictodb-schema.sql
View file @
fd4cd3e5
...
@@ -289,6 +289,7 @@ CREATE TABLE IF NOT EXISTS `student` (
...
@@ -289,6 +289,7 @@ CREATE TABLE IF NOT EXISTS `student` (
`lang`
varchar
(
5
)
COLLATE
utf8_unicode_ci
NOT
NULL
,
`lang`
varchar
(
5
)
COLLATE
utf8_unicode_ci
NOT
NULL
,
`attributes`
varchar
(
4096
)
COLLATE
utf8_unicode_ci
DEFAULT
NULL
COMMENT
'Attributes describing student along with his/her configuration'
,
`attributes`
varchar
(
4096
)
COLLATE
utf8_unicode_ci
DEFAULT
NULL
COMMENT
'Attributes describing student along with his/her configuration'
,
`id_off`
int
(
11
)
DEFAULT
NULL
,
`id_off`
int
(
11
)
DEFAULT
NULL
,
`id_active_scene`
int
(
11
)
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`username`
(
`username`
),
UNIQUE
KEY
`username`
(
`username`
),
KEY
`id_off`
(
`id_off`
)
KEY
`id_off`
(
`id_off`
)
...
@@ -441,7 +442,6 @@ COMMENT="This table stores working session information. Every working session is
...
@@ -441,7 +442,6 @@ COMMENT="This table stores working session information. Every working session is
CREATE
TABLE
IF
NOT
EXISTS
`scene`
(
CREATE
TABLE
IF
NOT
EXISTS
`scene`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
100
)
COLLATE
utf8_unicode_ci
DEFAULT
NULL
,
`name`
varchar
(
100
)
COLLATE
utf8_unicode_ci
DEFAULT
NULL
,
`active`
boolean
NOT
NULL
DEFAULT
0
,
`categories`
boolean
NOT
NULL
DEFAULT
0
,
`categories`
boolean
NOT
NULL
DEFAULT
0
,
`id_sup`
int
(
11
)
DEFAULT
NULL
,
`id_sup`
int
(
11
)
DEFAULT
NULL
,
`id_stu`
int
(
11
)
NOT
NULL
,
`id_stu`
int
(
11
)
NOT
NULL
,
...
@@ -451,11 +451,6 @@ CREATE TABLE IF NOT EXISTS `scene` (
...
@@ -451,11 +451,6 @@ CREATE TABLE IF NOT EXISTS `scene` (
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_unicode_ci
AUTO_INCREMENT
=
1
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_unicode_ci
AUTO_INCREMENT
=
1
COMMENT
=
"Scene table information. Every scene is related to some stu_pictos"
;
COMMENT
=
"Scene table information. Every scene is related to some stu_pictos"
;
CREATE
TABLE
IF
NOT
EXISTS
`scene_aux`
(
`id_stu`
int
(
11
)
NOT
NULL
,
`id_scene`
int
(
11
)
NOT
NULL
)
ENGINE
=
MEMORY
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_unicode_ci
COMMENT
=
"Aux table to use with triggers-enrolments-integrity-constraints when create a new student"
;
-- CREATE INDEX ix_ws_begin ON working_session (`begin`);
-- CREATE INDEX ix_ws_begin ON working_session (`begin`);
--
--
...
...
sails/roles/database/files/scene_adapt.sql
View file @
fd4cd3e5
...
@@ -48,7 +48,7 @@ BEGIN
...
@@ -48,7 +48,7 @@ BEGIN
SET
LID
=
LAST_INSERT_ID
();
SET
LID
=
LAST_INSERT_ID
();
UPDATE
student
SET
attributes
=
JSON_SET
(
attributes
,
"$.id_active_scene"
,
LID
)
WHERE
id
=
_id_stu
;
UPDATE
student
SET
id_active_scene
=
LID
WHERE
id
=
_id_stu
;
UPDATE
`stu_picto`
UPDATE
`stu_picto`
SET
`id_scene`
=
LID
SET
`id_scene`
=
LID
...
...
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
View file @
fd4cd3e5
...
@@ -50,35 +50,19 @@ thisTrigger: BEGIN
...
@@ -50,35 +50,19 @@ thisTrigger: BEGIN
END
IF
;
END
IF
;
-- Load core collection for student
-- Load core collection for student
INSERT
INTO
scene
(
id_stu
,
id_sup
,
name
,
categories
)
VALUES
(
new
.
id
,
null
,
'with_categories'
,
TRUE
);
INSERT
INTO
scene
(
id_stu
,
id_sup
,
name
,
categories
)
VALUES
(
NEW
.
id
,
null
,
'with_categories'
,
TRUE
);
SET
LID
=
LAST_INSERT_ID
();
SET
LID
=
LAST_INSERT_ID
();
CALL
scene_create_core
(
LID
,
new
.
id
);
CALL
scene_create_core
(
LID
,
new
.
id
);
INSERT
INTO
scene_aux
(
id_stu
,
id_scene
)
VALUES
(
new
.
id
,
LID
);
END
;;
END
;;
DROP
PROCEDURE
IF
EXISTS
NEW_STUDENT_AUX
;
CREATE
PROCEDURE
NEW_STUDENT_AUX
()
BEGIN
DECLARE
_id_stu
INT
;
DECLARE
_id_scene
INT
;
DECLARE
done
INT
DEFAULT
FALSE
;
DECLARE
aux
CURSOR
FOR
SELECT
*
FROM
pictodb
.
scene_aux
;
DECLARE
CONTINUE
HANDLER
FOR
NOT
FOUND
SET
done
=
TRUE
;
OPEN
aux
;
read_loop
:
LOOP
FETCH
aux
INTO
_id_stu
,
_id_scene
;
IF
done
THEN
DROP
PROCEDURE
IF
EXISTS
active_scene_update
;
LEAVE
read_loop
;
CREATE
PROCEDURE
active_scene_update
(
IN
_id_stu
INTEGER
)
END
IF
;
BEGIN
DECLARE
_id_scene
INTEGER
;
UPDATE
student
SET
attributes
=
JSON_SET
(
attributes
,
'$.id_active_scene'
,
_id_scene
)
WHERE
id
=
_id_stu
;
END
LOOP
;
SELECT
id
INTO
_id_scene
FROM
scene
WHERE
id_stu
=
_id_stu
LIMIT
1
;
CLOSE
aux
;
UPDATE
student
SET
id_active_scene
=
_id_scene
WHERE
id
=
_id_stu
;
DELETE
FROM
scene_aux
;
END
;;
END
;;
-- Procedure to add core when new scene is created
-- Procedure to add core when new scene is created
...
...
sails/src/CHANGES.md
View file @
fd4cd3e5
...
@@ -15,22 +15,13 @@ Changes to be performed manually in servers to upgrade
...
@@ -15,22 +15,13 @@ Changes to be performed manually in servers to upgrade
-
Delete active column from scene table (deleted from
`already done in dev`
sql
`create scene table`
statement)
-
Delete active column from scene table (deleted from
`already done in dev`
sql
`create scene table`
statement)
`alter table scene drop active;`
`alter table scene drop active;`
-
Alter table scene to add ON DELETE CASCADE constraint
-
Add id_active_scene to student table
`ALTER TABLE `
scene
` ADD CONSTRAINT `
stu_scene_fk
` FOREIGN KEY (`
id_stu
`) REFERENCES `
student
` (`
id
`) ON DELETE CASCADE;`
`ALTER TABLE student ADD COLUMN id_active_scene INT(11) DEFAULT NULL;`
`ALTER TABLE student ADD CONSTRAINT fk_active_scene FOREIGN KEY (`
id_active_scene
`) REFERENCES scene (`
id
`);`
-
Create aux table for scene
`CREATE TABLE IF NOT EXISTS `
scene_aux
`(
`
id_stu
` int(11) NOT NULL,
`
id_scene
` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
COMMENT="Aux table to use with triggers-enrolments-integrity-constraints when create a new student";`
-
Reload enrolments trigger
-
Reload enrolments trigger
`source /vagrant/roles/database/files/triggers-enrolments-integrity-constraints.sql;`
`source /vagrant/roles/database/files/triggers-enrolments-integrity-constraints.sql;`
To Do only in PRE:
-
Load scene_adapt
`source /vagrant/roles/database/files/scene_adapt.sql`
(already done in dev)
(already done in dev)
...
...
sails/src/api/controllers/StudentController.js
View file @
fd4cd3e5
...
@@ -187,9 +187,6 @@ module.exports = {
...
@@ -187,9 +187,6 @@ module.exports = {
Student
.
create
(
params
)
Student
.
create
(
params
)
.
then
(
function
(
created
)
{
.
then
(
function
(
created
)
{
Scene
.
query
(
'CALL NEW_STUDENT_AUX() '
,[],
function
(
err
,
result
)
{
});
sails
.
log
.
debug
(
'Student '
+
created
.
id
+
' created: '
+
JSON
.
stringify
(
created
));
sails
.
log
.
debug
(
'Student '
+
created
.
id
+
' created: '
+
JSON
.
stringify
(
created
));
License
.
activate
(
params
.
license_number
,
created
.
id
,
function
(
err
,
license
)
{
License
.
activate
(
params
.
license_number
,
created
.
id
,
function
(
err
,
license
)
{
if
(
err
)
if
(
err
)
...
@@ -830,7 +827,7 @@ module.exports = {
...
@@ -830,7 +827,7 @@ module.exports = {
if
(
typeof
req
.
params
.
id_stu
==
'undefined'
||
!
req
.
params
.
id_stu
)
if
(
typeof
req
.
params
.
id_stu
==
'undefined'
||
!
req
.
params
.
id_stu
)
return
res
.
badRequest
(
"id_stu not defined"
);
return
res
.
badRequest
(
"id_stu not defined"
);
Student
.
findOne
({
id
:
req
.
params
.
id_stu
}).
then
(
function
(
student
){
Student
.
findOne
({
id
:
req
.
params
.
id_stu
}).
then
(
function
(
student
){
Scene
.
findOne
({
id
:
student
.
attributes
.
id_active_scene
})
Scene
.
findOne
({
id
:
student
.
id_active_scene
})
.
then
(
function
(
scene
){
.
then
(
function
(
scene
){
if
(
!
scene
)
if
(
!
scene
)
return
res
.
badRequest
(
"Scene not found"
);
return
res
.
badRequest
(
"Scene not found"
);
...
@@ -860,7 +857,7 @@ module.exports = {
...
@@ -860,7 +857,7 @@ module.exports = {
var
params
=
req
.
allParams
();
var
params
=
req
.
allParams
();
Student
.
findOne
({
id
:
params
.
id_stu
})
Student
.
findOne
({
id
:
params
.
id_stu
})
.
then
(
student
=>
{
.
then
(
student
=>
{
student
.
attributes
.
id_active_scene
=
params
.
id_scene
;
student
.
id_active_scene
=
params
.
id_scene
;
delete
student
.
password
;
delete
student
.
password
;
student
.
save
(
function
(
error
){
student
.
save
(
function
(
error
){
if
(
error
){
if
(
error
){
...
@@ -891,7 +888,7 @@ module.exports = {
...
@@ -891,7 +888,7 @@ module.exports = {
return
res
.
serverError
(
"No scenes found"
);
return
res
.
serverError
(
"No scenes found"
);
}
else
{
}
else
{
scenes
.
forEach
(
function
(
scene
,
cb
){
scenes
.
forEach
(
function
(
scene
,
cb
){
scene
.
active
=
scene
.
id
==
student
.
attributes
.
id_active_scene
;
scene
.
active
=
scene
.
id
==
student
.
id_active_scene
;
});
});
return
res
.
ok
(
scenes
);
return
res
.
ok
(
scenes
);
}
}
...
...
sails/src/api/models/Student.js
View file @
fd4cd3e5
...
@@ -73,6 +73,12 @@ module.exports = {
...
@@ -73,6 +73,12 @@ module.exports = {
required
:
false
,
required
:
false
,
model
:
'Office'
model
:
'Office'
},
},
id_active_scene
:
{
columnName
:
'id_active_scene'
,
type
:
'integer'
,
required
:
false
,
model
:
'Scene'
},
// Relación con StuSup
// Relación con StuSup
stuSup
:
{
stuSup
:
{
collection
:
'stusup'
,
collection
:
'stusup'
,
...
@@ -259,6 +265,19 @@ module.exports = {
...
@@ -259,6 +265,19 @@ module.exports = {
attrs
.
pic
=
sails
.
config
.
pictogram
.
paths
.
defaultAvatarFileName
;
attrs
.
pic
=
sails
.
config
.
pictogram
.
paths
.
defaultAvatarFileName
;
next
();
next
();
},
},
/**
* Call a stored procedure to update the active scene of the student
* @param {Object} student All student properties to be stored
* @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed
* to the function if necesary)
*/
afterCreate
:
function
(
student
,
next
)
{
Student
.
query
(
'CALL active_scene_update(?) '
,[
student
.
id
],
function
(
err
,
result
)
{
sails
.
log
.
debug
(
'call to active_scene_update stored procedure after create student'
);
});
next
();
},
/**
/**
* Checks the given properties before updating a new Student
* Checks the given properties before updating a new Student
...
...
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