Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last_check_date mapping when check updates service is disabled #6171

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading