mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-26 01:17:00 +02:00
A client-register should upsert client_applications table
This commit is contained in:
parent
ac846b9879
commit
46c8d83dc1
@ -1,7 +1,8 @@
|
|||||||
/* eslint camelcase:off */
|
/* eslint camelcase:off */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const COLUMNS = ['app_name', 'created_at', 'updated_at', 'description', 'url', 'color', 'icon'];
|
const COLUMNS = [
|
||||||
|
'app_name', 'created_at', 'updated_at', 'description', 'strategies', 'url', 'color', 'icon'];
|
||||||
const TABLE = 'client_applications';
|
const TABLE = 'client_applications';
|
||||||
|
|
||||||
const mapRow = (row) => ({
|
const mapRow = (row) => ({
|
||||||
@ -9,6 +10,7 @@ const mapRow = (row) => ({
|
|||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
updatedAt: row.updated_at,
|
updatedAt: row.updated_at,
|
||||||
description: row.description,
|
description: row.description,
|
||||||
|
strategies: row.strategies,
|
||||||
url: row.url,
|
url: row.url,
|
||||||
color: row.color,
|
color: row.color,
|
||||||
icon: row.icon,
|
icon: row.icon,
|
||||||
@ -21,6 +23,7 @@ const remapRow = (input, old = {}) => ({
|
|||||||
url: input.url || old.url,
|
url: input.url || old.url,
|
||||||
color: input.color || old.color,
|
color: input.color || old.color,
|
||||||
icon: input.icon || old.icon,
|
icon: input.icon || old.icon,
|
||||||
|
strategies: JSON.stringify(input.strategies || old.strategies),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,22 +77,19 @@ module.exports = function (app, config) {
|
|||||||
|
|
||||||
app.post('/client/register', (req, res) => {
|
app.post('/client/register', (req, res) => {
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
const clientIp = req.ip;
|
|
||||||
|
|
||||||
joi.validate(data, clientRegisterSchema, (err, cleaned) => {
|
joi.validate(data, clientRegisterSchema, (err, clientRegistration) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(400).json(err);
|
return res.status(400).json(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientStrategyStore
|
clientRegistration.clientIp = req.ip;
|
||||||
.insert(cleaned.appName, cleaned.strategies)
|
|
||||||
.then(() => clientInstanceStore.insert({
|
clientApplicationsStore
|
||||||
appName: cleaned.appName,
|
.upsert(clientRegistration)
|
||||||
instanceId: cleaned.instanceId,
|
.then(() => clientInstanceStore.insert(clientRegistration))
|
||||||
clientIp,
|
|
||||||
}))
|
|
||||||
.then(() => logger.info(`New client registered with
|
.then(() => logger.info(`New client registered with
|
||||||
appName=${cleaned.appName} and instanceId=${cleaned.instanceId}`))
|
appName=${clientRegistration.appName} and instanceId=${clientRegistration.instanceId}`))
|
||||||
.catch(err => logger.error('failed to register client', err));
|
.catch(err => logger.error('failed to register client', err));
|
||||||
|
|
||||||
res.status(202).end();
|
res.status(202).end();
|
||||||
|
Loading…
Reference in New Issue
Block a user