-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Move configurations code from core-pg to ept-configurations
- Loading branch information
Showing
12 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
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,42 @@ | ||
var path = require('path'); | ||
var dbc = require(path.normalize(__dirname + '/db')); | ||
var db = dbc.db; | ||
var helper = dbc.helper; | ||
|
||
module.exports = function(config) { | ||
if (config.portal && config.portal.board_id) { | ||
config.portal.board_id = helper.deslugify(config.portal.board_id); | ||
} | ||
|
||
// Copy fields from config | ||
var storedConfig = (({ | ||
gaKey, | ||
images, | ||
portal, | ||
emailer, | ||
website, | ||
postMaxLength, | ||
inviteOnly, | ||
logEnabled, | ||
rateLimiting, | ||
loginRequired, | ||
verifyRegistration | ||
}) => ({ | ||
gaKey, | ||
images, | ||
portal, | ||
emailer, | ||
website, | ||
postMaxLength, | ||
inviteOnly, | ||
logEnabled, | ||
rateLimiting, | ||
loginRequired, | ||
verifyRegistration | ||
}))(config); | ||
|
||
// For now we are hardcoding 'default' as the main config | ||
// In the future we can support swappable configs | ||
var q = 'INSERT INTO configurations (name, config) VALUES (\'default\', $1)'; | ||
return db.sqlQuery(q, [storedConfig]); | ||
}; |
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,2 @@ | ||
var dbc = require('epochtalk-core-pg')(); | ||
module.exports = dbc; |
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,28 @@ | ||
var path = require('path'); | ||
var _ = require('lodash'); | ||
var changeCase = require('change-case'); | ||
var renameKeys = require('deep-rename-keys'); | ||
var dbc = require(path.normalize(__dirname + '/db')); | ||
var db = dbc.db; | ||
var errors = dbc.errors; | ||
var NotFoundError = errors.NotFoundError; | ||
|
||
// returns object of private configurations | ||
module.exports = function() { | ||
var q = 'SELECT config FROM configurations WHERE name = \'default\''; | ||
return db.sqlQuery(q) | ||
.then(function(queryResults) { | ||
if (queryResults.length > 0) { | ||
var privateConfigurations = queryResults[0].config; | ||
|
||
if (_.isObject(privateConfigurations)) { | ||
privateConfigurations = renameKeys(privateConfigurations, function(key) { | ||
return changeCase.camel(key); | ||
}); | ||
} | ||
|
||
return privateConfigurations; | ||
} | ||
else { throw new NotFoundError('Configurations Not Found'); } | ||
}); | ||
}; |
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,12 @@ | ||
var path = require('path'); | ||
var dbc = require(path.normalize(__dirname + '/db')); | ||
var db = dbc.db; | ||
|
||
// returns object of public configurations | ||
module.exports = function() { | ||
var q = 'SELECT config->>\'website\' as website FROM configurations WHERE name = \'default\''; | ||
return db.scalar(q) | ||
.then(function(queryResults) { | ||
return queryResults.website; | ||
}); | ||
}; |
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,8 @@ | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
create: require(path.normalize(__dirname + '/create')), | ||
get: require(path.normalize(__dirname + '/get')), | ||
getPublic: require(path.normalize(__dirname + '/getPublic')), | ||
update: require(path.normalize(__dirname + '/update')) | ||
}; |
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,9 @@ | ||
var path = require('path'); | ||
var dbc = require(path.normalize(__dirname + '/db')); | ||
var db = dbc.db; | ||
|
||
// updates configurations from an object | ||
module.exports = function(config) { | ||
var query = 'UPDATE configurations SET config = $1 WHERE name = \'default\''; | ||
return db.sqlQuery(query, [config]); | ||
}; |
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,13 @@ | ||
var path = require('path'); | ||
var db = require(path.normalize(__dirname + '/db')); | ||
// var routes = require(path.normalize(__dirname + '/routes')); | ||
// var authorization = require(path.normalize(__dirname + '/authorization')); | ||
// var permissions = require(path.normalize(__dirname + '/permissions')); | ||
|
||
module.exports = { | ||
name: 'configurations', | ||
// authorization: authorization, | ||
// permissions: permissions, | ||
// routes: routes, | ||
db: db | ||
}; |
Empty file.
Empty file.
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
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