Commit 7c05c757 authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v1.1.0

parent 8c4650c5
'use strict'; 'use strict';
function* createTables() { function * createTables() {
try { try {
yield this.db.queryAsync( yield this
` .db
.queryAsync(`
CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.INSTANCES}\` ( CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.INSTANCES}\` (
\`id\` CHAR(36) NOT NULL, \`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL, \`name\` CHAR(255) NOT NULL,
...@@ -12,11 +13,11 @@ function* createTables() { ...@@ -12,11 +13,11 @@ function* createTables() {
PRIMARY KEY (\`id\`), PRIMARY KEY (\`id\`),
UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC) UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC)
) )
` `);
);
yield this.db.queryAsync( yield this
` .db
.queryAsync(`
CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.PROJECTS}\` ( CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.PROJECTS}\` (
\`id\` CHAR(36) NOT NULL, \`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL, \`name\` CHAR(255) NOT NULL,
...@@ -25,12 +26,22 @@ function* createTables() { ...@@ -25,12 +26,22 @@ function* createTables() {
PRIMARY KEY (\`id\`), PRIMARY KEY (\`id\`),
UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC) UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC)
) )
` `);
);
this.logger.log(__filename, 'tables created successfully'); yield this
.db
.queryAsync(`
ALTER TABLE \`${this.tablesNames.PROJECTS}\` ADD \`project_id\` MEDIUMINT
`);
this.logger.log(
__filename,
'tables created successfully'
);
} catch (err) { } catch (err) {
this.logger.error(err); this.logger.error(
err
);
throw err; throw err;
} }
......
{ {
"name": "service-sdk", "name": "service-sdk",
"version": "1.0.6", "version": "1.1.0",
"private": true, "private": true,
"description": "Service SDK for LViS", "description": "Service SDK for LViS",
"keywords": [], "keywords": [],
......
...@@ -3,9 +3,12 @@ ...@@ -3,9 +3,12 @@
function* post() { function* post() {
const project = { const project = {
id: this.checkBody('project_uuid').isUUID().value, id: this.checkBody('project_uuid').isUUID().value,
name: this.checkBody('project_name').notBlank().isLength(1, 255).value, name: this.checkBody('project_name')
feed_uuid: this.checkBody('feed_uuid').isUUID().value, .notBlank()
.isLength(1, 255).value,
config: this.checkBody('config').eq('[object Object]').value, config: this.checkBody('config').eq('[object Object]').value,
feed_uuid: this.checkBody('feed_uuid').isUUID().value,
project_id: this.checkBody('project_id').isInt().value,
}; };
const str = JSON.stringify(project); const str = JSON.stringify(project);
...@@ -20,29 +23,31 @@ function* post() { ...@@ -20,29 +23,31 @@ function* post() {
if (projects.length) { if (projects.length) {
yield this.db.queryAsync( yield this.db.queryAsync(
`UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, feed_uuid = ?, config = ? WHERE id = ?`, `UPDATE \`${
[project.name, project.feed_uuid, project.config, project.id] this.tablesNames.PROJECTS
); }\` SET name = ?, feed_uuid = ?, project_id = ?, config = ? WHERE id = ?`,
[project.name, project.feed_uuid, project.project_id, project.config, project.id]
);
this.logger.log( this.logger.log(
__filename, __filename,
'update row with id', 'update row with id',
project.id, project.id,
'in table', 'in table',
this.tablesNames.PROJECTS, this.tablesNames.PROJECTS,
'successfully' 'successfully'
); );
} else { } else {
yield this.db.queryAsync(`INSERT INTO \`${this.tablesNames.PROJECTS}\` SET ?`, project); yield this.db.queryAsync(`INSERT INTO \`${this.tablesNames.PROJECTS}\` SET ?`, project);
this.logger.log( this.logger.log(
__filename, __filename,
'inserted project with id', 'inserted project with id',
project.id, project.id,
'to table', 'to table',
this.tablesNames.PROJECTS, this.tablesNames.PROJECTS,
'successfully' 'successfully'
); );
} }
this.body = {}; this.body = {};
...@@ -50,7 +55,9 @@ function* post() { ...@@ -50,7 +55,9 @@ function* post() {
function* put() { function* put() {
const project = { const project = {
name: this.checkBody('project_name').notBlank().isLength(1, 255).value, name: this.checkBody('project_name')
.notBlank()
.isLength(1, 255).value,
config: this.checkBody('config').eq('[object Object]').value, config: this.checkBody('config').eq('[object Object]').value,
}; };
const str = JSON.stringify(project); const str = JSON.stringify(project);
...@@ -61,20 +68,19 @@ function* put() { ...@@ -61,20 +68,19 @@ function* put() {
project.config = JSON.stringify(project.config); project.config = JSON.stringify(project.config);
yield this.db.queryAsync(`UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, config = ? WHERE id = ?`, [ yield this.db.queryAsync(
project.name, `UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, config = ? WHERE id = ?`,
project.config, [project.name, project.config, this.state.project.id]
this.state.project.id, );
]);
this.logger.log( this.logger.log(
__filename, __filename,
'update row with id', 'update row with id',
this.state.project.id, this.state.project.id,
'in table', 'in table',
this.tablesNames.PROJECTS, this.tablesNames.PROJECTS,
'successfully' 'successfully'
); );
this.body = {}; this.body = {};
} }
...@@ -82,18 +88,20 @@ function* put() { ...@@ -82,18 +88,20 @@ function* put() {
function* del() { function* del() {
this.logger.log(__filename, 'DELETE'); this.logger.log(__filename, 'DELETE');
yield this.db.queryAsync(`DELETE FROM \`${this.tablesNames.PROJECTS}\` WHERE id = ?`, [this.state.project.id]); yield this.db.queryAsync(`DELETE FROM \`${this.tablesNames.PROJECTS}\` WHERE id = ?`, [
this.state.project.id,
]);
this.logger.log( this.logger.log(
__filename, __filename,
'delete row with id', 'delete row with id',
this.state.project.id, this.state.project.id,
'in table', 'in table',
this.tablesNames.PROJECTS, this.tablesNames.PROJECTS,
'successfully' 'successfully'
); );
this.body = {}; this.body = {};
} }
module.exports = {post, put, del}; module.exports = { post, put, del };
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment