-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #217 : StateTypeParam are no longer inserted in duplicate
- Loading branch information
1 parent
209c80c
commit 507c783
Showing
7 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
module.exports.create = require('./stateTypeParam.create.js'); | ||
module.exports.cleanDuplicate = require('./stateTypeParam.cleanDuplicate.js'); | ||
module.exports.getByStateType = require('./stateTypeParam.getByStateType.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var queries = require('./stateTypeParam.queries.js'); | ||
|
||
module.exports = function(){ | ||
return gladys.utils.sql(queries.cleanDuplicateStateTypeParams, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
var queries = require('./stateTypeParam.queries.js'); | ||
|
||
module.exports = function (stateTypeParam){ | ||
return StateTypeParam.create(stateTypeParam); | ||
|
||
// test if StateTypeParam already exist | ||
return gladys.utils.sql(queries.getByStateTypeAndVariableName, [stateTypeParam.statetype, stateTypeParam.variablename]) | ||
.then((rows) => { | ||
|
||
// if StateTypeParam already exist, update it | ||
if(rows.length) return StateTypeParam.update({id: rows[0].id}, stateTypeParam); | ||
|
||
// if not, update it | ||
return StateTypeParam.create(stateTypeParam); | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
|
||
module.exports = { | ||
getByStateType: 'SELECT * FROM statetypeparam WHERE statetype = ?;' | ||
getByStateType: 'SELECT * FROM statetypeparam WHERE statetype = ?;', | ||
getByStateTypeAndVariableName: 'SELECT * FROM statetypeparam WHERE statetype = ? AND variablename = ?;', | ||
cleanDuplicateStateTypeParams: ` | ||
DELETE FROM statetypeparam | ||
WHERE id NOT IN | ||
( | ||
SELECT MIN(id) as rowId | ||
FROM (SELECT * FROM statetypeparam) AS stp | ||
GROUP BY variablename, statetype | ||
); | ||
` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/unit/api/core/statetypeparam/stateTypeParam.cleanDuplicate.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var should = require('should'); | ||
var validateStateTypeParam = require('../../validator/stateTypeParamValidator.js'); | ||
|
||
describe('StateTypeParam', function() { | ||
|
||
describe('cleanDuplicate', function() { | ||
|
||
it('should cleanDuplicate', function (done) { | ||
|
||
|
||
gladys.stateTypeParam.cleanDuplicate() | ||
.then(function(){ | ||
|
||
done(); | ||
}).catch(done); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters