Skip to content

Commit

Permalink
Fix silly mapping bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeijao committed Aug 16, 2023
1 parent ffbdb38 commit 1e3f24b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/api_cvr_ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ function ConnectWebsocket(username, accessKey) {
if (Object.values(RESPONSE_TYPE).includes(responseType)) {
const processedData = preProcessEntities(responseType, data);
EventEmitter.emit(responseType, processedData, message);
log.debug(`[ConnectWebsocket] [onMessage] {${socket.uniqueId}} Type: ${GetResponseTypeName(responseType)} (${responseType}), Msg: ${message}`, data, processedData);
const logObj = { 'API Original Data': data, 'CVRX Processed Data': processedData };
log.debug(`[ConnectWebsocket] [onMessage] {${socket.uniqueId}} Type: ${GetResponseTypeName(responseType)} (${responseType}), Msg: ${message}`, logObj);
}
else {
log.warn(`[ConnectWebsocket] [onMessage] {${socket.uniqueId}} Response type ${responseType} is not mapped! Msg: ${message}`, data);
Expand Down
10 changes: 9 additions & 1 deletion server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ exports.MapEntity = (entity, mapping) => {
const ourKey = mapping[apiKey];
// If the mapping is an object, it means it's a nested mapping
if (typeof ourKey === 'object' && ourKey !== null) {
entityToMap[ourKey.root] = exports.MapEntity(entityToMap[apiKey], ourKey.mapping);
const entityValue = entityToMap[apiKey];
// If it's an object and not null or is an array, use the object/array mapping
if (typeof entityValue === 'object' && entityValue !== null || Array.isArray(entityValue)) {
entityToMap[ourKey.root] = exports.MapEntity(entityValue, ourKey.mapping);
}
// If it's a primitive or null just set the value
else {
entityToMap[ourKey.root] = entityValue;
}
}
// Otherwise let's just fix the key
else {
Expand Down

0 comments on commit 1e3f24b

Please sign in to comment.