mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01: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 */
|
||||
'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 mapRow = (row) => ({
|
||||
@ -9,6 +10,7 @@ const mapRow = (row) => ({
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at,
|
||||
description: row.description,
|
||||
strategies: row.strategies,
|
||||
url: row.url,
|
||||
color: row.color,
|
||||
icon: row.icon,
|
||||
@ -21,6 +23,7 @@ const remapRow = (input, old = {}) => ({
|
||||
url: input.url || old.url,
|
||||
color: input.color || old.color,
|
||||
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) => {
|
||||
const data = req.body;
|
||||
const clientIp = req.ip;
|
||||
|
||||
joi.validate(data, clientRegisterSchema, (err, cleaned) => {
|
||||
joi.validate(data, clientRegisterSchema, (err, clientRegistration) => {
|
||||
if (err) {
|
||||
return res.status(400).json(err);
|
||||
}
|
||||
|
||||
clientStrategyStore
|
||||
.insert(cleaned.appName, cleaned.strategies)
|
||||
.then(() => clientInstanceStore.insert({
|
||||
appName: cleaned.appName,
|
||||
instanceId: cleaned.instanceId,
|
||||
clientIp,
|
||||
}))
|
||||
clientRegistration.clientIp = req.ip;
|
||||
|
||||
clientApplicationsStore
|
||||
.upsert(clientRegistration)
|
||||
.then(() => clientInstanceStore.insert(clientRegistration))
|
||||
.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));
|
||||
|
||||
res.status(202).end();
|
||||
|
Loading…
Reference in New Issue
Block a user