Skip to content

Commit

Permalink
Fix last_check_date mapping when check updates service is disabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianogorza authored Nov 28, 2023
1 parent e6e6e94 commit e21fb9c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions plugins/wazuh-check-updates/server/services/updates/get-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { SAVED_OBJECT_UPDATES } from '../../../common/constants';
import { getSavedObject, setSavedObject } from '../saved-object';
import { getWazuhCore } from '../../plugin-services';
import _ from 'lodash';

export const getUpdates = async (checkAvailableUpdates?: boolean): Promise<AvailableUpdates> => {
try {
Expand Down Expand Up @@ -43,26 +42,38 @@ export const getUpdates = async (checkAvailableUpdates?: boolean): Promise<Avail

const update = response.data.data as ResponseApiAvailableUpdates;

const {
current_version,
update_check,
last_available_major,
last_available_minor,
last_available_patch,
last_check_date,
} = update;

const getStatus = () => {
if (update?.update_check === false) {
if (update_check === false) {
return API_UPDATES_STATUS.DISABLED;
}

if (
update?.last_available_patch?.tag ||
update?.last_available_minor?.tag ||
update?.last_available_patch?.tag
last_available_major?.tag ||
last_available_minor?.tag ||
last_available_patch?.tag
) {
return API_UPDATES_STATUS.AVAILABLE_UPDATES;
}

return API_UPDATES_STATUS.UP_TO_DATE;
};

const updateWithoutUUID = _.omit(update, 'uuid');

return {
...updateWithoutUUID,
current_version,
update_check,
last_available_major,
last_available_minor,
last_available_patch,
last_check_date: last_check_date || undefined,
api_id: api.id,
status: getStatus(),
};
Expand Down

0 comments on commit e21fb9c

Please sign in to comment.