36 |
public async update(request: Request) { |
public async update(request: Request) { |
37 |
const { id } = request.params; |
const { id } = request.params; |
38 |
const { config } = request.body; |
const { config } = request.body; |
39 |
|
|
40 |
|
console.log(config); |
41 |
|
|
42 |
const currentConfigDotObject = dot(this.client.config.props[id]); |
const currentConfigDotObject = dot(this.client.config.props[id]); |
43 |
const newConfigDotObject = {...currentConfigDotObject}; |
const newConfigDotObject = {...currentConfigDotObject}; |
44 |
|
|
45 |
console.log("Input: ", config); |
console.log("Input: ", config); |
46 |
|
|
47 |
for (const configKey in config) { |
for (const configKey in config) { |
48 |
if (!(configKey in currentConfigDotObject)) { |
if (typeof currentConfigDotObject[configKey] === 'undefined') { |
49 |
return { error: `The key '${configKey}' is not allowed` }; |
return this.response({ error: `The key '${configKey}' is not allowed` }, 422); |
50 |
} |
} |
51 |
|
|
52 |
if (typeof config[configKey] !== typeof currentConfigDotObject[configKey] || (config[configKey] !== null && currentConfigDotObject[configKey] === null) || (config[configKey] === null && currentConfigDotObject[configKey] !== null)) { |
if (config[configKey] !== null && config[configKey] !== null && typeof config[configKey] !== typeof currentConfigDotObject[configKey]) { |
53 |
return { error: `The key '${configKey}' has incompatible value type '${config[configKey] === null ? 'null' : typeof config[configKey]}'` }; |
console.log(typeof config[configKey], typeof currentConfigDotObject[configKey]); |
54 |
|
|
55 |
|
if (typeof currentConfigDotObject[configKey] === 'number' && typeof config[configKey] === 'string') { |
56 |
|
const int = parseInt(config[configKey]); |
57 |
|
|
58 |
|
if (int !== NaN) { |
59 |
|
newConfigDotObject[configKey] = int; |
60 |
|
console.log("Updating: ", configKey, config[configKey], newConfigDotObject[configKey]); |
61 |
|
continue; |
62 |
|
} |
63 |
|
} |
64 |
|
|
65 |
|
return this.response({ error: `The key '${configKey}' has incompatible value type '${config[configKey] === null ? 'null' : typeof config[configKey]}'` }, 422); |
66 |
} |
} |
67 |
|
|
68 |
newConfigDotObject[configKey] = config[configKey]; |
newConfigDotObject[configKey] = config[configKey]; |