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

v1.1.0

parent 8c4650c5
'use strict';
function* createTables() {
function * createTables() {
try {
yield this.db.queryAsync(
`
yield this
.db
.queryAsync(`
CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.INSTANCES}\` (
\`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL,
......@@ -12,11 +13,11 @@ function* createTables() {
PRIMARY KEY (\`id\`),
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}\` (
\`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL,
......@@ -25,12 +26,22 @@ function* createTables() {
PRIMARY KEY (\`id\`),
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) {
this.logger.error(err);
this.logger.error(
err
);
throw err;
}
......
{
"name": "service-sdk",
"version": "1.0.6",
"version": "1.1.0",
"private": true,
"description": "Service SDK for LViS",
"keywords": [],
......
......@@ -3,9 +3,12 @@
function* post() {
const project = {
id: this.checkBody('project_uuid').isUUID().value,
name: this.checkBody('project_name').notBlank().isLength(1, 255).value,
feed_uuid: this.checkBody('feed_uuid').isUUID().value,
name: this.checkBody('project_name')
.notBlank()
.isLength(1, 255).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);
......@@ -20,29 +23,31 @@ function* post() {
if (projects.length) {
yield this.db.queryAsync(
`UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, feed_uuid = ?, config = ? WHERE id = ?`,
[project.name, project.feed_uuid, project.config, project.id]
);
`UPDATE \`${
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(
__filename,
'update row with id',
project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
__filename,
'update row with id',
project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
} else {
yield this.db.queryAsync(`INSERT INTO \`${this.tablesNames.PROJECTS}\` SET ?`, project);
this.logger.log(
__filename,
'inserted project with id',
project.id,
'to table',
this.tablesNames.PROJECTS,
'successfully'
);
__filename,
'inserted project with id',
project.id,
'to table',
this.tablesNames.PROJECTS,
'successfully'
);
}
this.body = {};
......@@ -50,7 +55,9 @@ function* post() {
function* put() {
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,
};
const str = JSON.stringify(project);
......@@ -61,20 +68,19 @@ function* put() {
project.config = JSON.stringify(project.config);
yield this.db.queryAsync(`UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, config = ? WHERE id = ?`, [
project.name,
project.config,
this.state.project.id,
]);
yield this.db.queryAsync(
`UPDATE \`${this.tablesNames.PROJECTS}\` SET name = ?, config = ? WHERE id = ?`,
[project.name, project.config, this.state.project.id]
);
this.logger.log(
__filename,
'update row with id',
this.state.project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
__filename,
'update row with id',
this.state.project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
this.body = {};
}
......@@ -82,18 +88,20 @@ function* put() {
function* del() {
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(
__filename,
'delete row with id',
this.state.project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
__filename,
'delete row with id',
this.state.project.id,
'in table',
this.tablesNames.PROJECTS,
'successfully'
);
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