Commit a0121eb9 authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v0.0.16

parent 6525a250
{ {
"name": "service-sdk", "name": "service-sdk",
"version": "0.0.15", "version": "0.0.16",
"private": true, "private": true,
"description": "Service SDK for LViS", "description": "Service SDK for LViS",
"keywords": [], "keywords": [],
......
'use strict'; 'use strict';
function * post() { function * post() {
const instance = { let instance = {
id: this.checkBody('id').isUUID().value, id: this.checkBody('id').isUUID().value,
name: this.checkBody('name').notBlank().isLength(1, 255).value, name: this.checkBody('name').notBlank().isLength(1, 255).value,
auth_endpoint: this.checkBody('auth_endpoint').isUrl().isLength(1, 255).value, auth_endpoint: this.checkBody('auth_endpoint').isUrl().isLength(1, 255).value,
...@@ -13,13 +13,32 @@ function * post() { ...@@ -13,13 +13,32 @@ function * post() {
this.throwResponseErrorIfNeed(this.errors); this.throwResponseErrorIfNeed(this.errors);
yield this.db.queryAsync(`INSERT INTO \`${this.tablesNames.INSTANCES}\` SET ?`, instance); const selectQuery = `SELECT * FROM \`${this.tablesNames.INSTANCES}\` WHERE \`id\` = "${[instance.id]}"`;
const oldInstances = yield this.db.queryAsync(selectQuery);
const oldInstance = oldInstances[0];
this.logger.log(__filename, if (oldInstance) {
'inserted instance with id', instance.id, instance = Object.assign({}, oldInstance, instance);
'to table', this.tablesNames.INSTANCES,
'successfully' yield this.db.queryAsync(
); `UPDATE \`${this.tablesNames.INSTANCES}\` SET name = ?, auth_endpoint = ?, feed_endpoint = ? WHERE id = ?`,
[instance.name, instance.auth_endpoint, instance.feed_endpoint, instance.id]
);
this.logger.log(__filename,
'updated instance with id', instance.id,
'in table', this.tablesNames.INSTANCES,
'successfully'
);
} else {
yield this.db.queryAsync(`INSERT INTO \`${this.tablesNames.INSTANCES}\` SET ?`, instance);
this.logger.log(__filename,
'inserted instance with id', instance.id,
'to table', this.tablesNames.INSTANCES,
'successfully'
);
}
this.body = { this.body = {
service_id: this.config.service.id, service_id: this.config.service.id,
......
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