diff --git a/client/api/store.ts b/client/api/store.ts index 55103937..e4c929b5 100644 --- a/client/api/store.ts +++ b/client/api/store.ts @@ -10,19 +10,21 @@ import { API } from './api' import applicationSlice from './applicationSlice' import authSlice from './authSlice' +export const reducer = { + application: applicationSlice, + auth: authSlice, + loginModal: loginModalSlice, + sidebar: sidebarSlice, + + [API.reducerPath]: API.reducer, + [APIMeteo.reducerPath]: APIMeteo.reducer +} + export const store = () => configureStore({ devTools: process.env.NODE_ENV !== 'production', middleware: (gDM) => gDM().concat(API.middleware, APIMeteo.middleware), - reducer: { - application: applicationSlice, - auth: authSlice, - loginModal: loginModalSlice, - sidebar: sidebarSlice, - - [API.reducerPath]: API.reducer, - [APIMeteo.reducerPath]: APIMeteo.reducer - } + reducer }) export type AppStore = ReturnType diff --git a/client/functions/helpers.test.ts b/client/functions/helpers.test.ts index b10e89ff..9be1df43 100644 --- a/client/functions/helpers.test.ts +++ b/client/functions/helpers.test.ts @@ -66,7 +66,7 @@ describe('helpers', () => { describe('timeAgo function', () => { it('returns "обновлено недавно" for null or non-positive seconds', () => { - expect(timeAgo(null)).toBe('обновлено недавно') + expect(timeAgo(undefined)).toBe('') expect(timeAgo(0)).toBe('обновлено недавно') expect(timeAgo(-5)).toBe('обновлено недавно') }) diff --git a/client/functions/helpers.ts b/client/functions/helpers.ts index 8b45f4bb..0e426527 100644 --- a/client/functions/helpers.ts +++ b/client/functions/helpers.ts @@ -126,7 +126,8 @@ export const dateAddMonth = ( export const timeAgo = (seconds?: number | string): string => { let sec = Number(seconds) - if (!sec || sec <= 0) return '' + if (!sec || sec < 0) return '' + if (sec === 0) return 'обновлено недавно' let h = (sec / 3600) ^ 0 let m = ((sec - h * 3600) / 60) ^ 0 diff --git a/client/package.json b/client/package.json index d0631fb1..526ac50a 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "astronomy-portal", - "version": "3.4.6", + "version": "3.4.7", "private": true, "engines": { "node": ">=20.11.0" diff --git a/client/setupTests.config.tsx b/client/setupTests.config.tsx index c691b660..53312541 100644 --- a/client/setupTests.config.tsx +++ b/client/setupTests.config.tsx @@ -1,5 +1,5 @@ import { API } from '@/api/api' -import { RootState, reducers } from '@/api/store' +import { RootState, reducer } from '@/api/store' import { configureStore } from '@reduxjs/toolkit' import '@testing-library/jest-dom' import { render } from '@testing-library/react' @@ -20,7 +20,7 @@ export const testStore = (state: Partial) => { return configureStore({ middleware: (gDM) => gDM().concat(API.middleware) as any, preloadedState: state, - reducer: reducers as any + reducer: reducer as any }) } diff --git a/server/app/Config/Routes.php b/server/app/Config/Routes.php index 4f707694..13cc4b45 100644 --- a/server/app/Config/Routes.php +++ b/server/app/Config/Routes.php @@ -5,9 +5,6 @@ /** * @var RouteCollection $routes */ -$routes->get('weather/current', 'Weather::current'); -$routes->get('weather/statistic', 'Weather::statistic'); -$routes->options('weather/(:any)', 'Weather'); // Events $routes->get('events', 'Events::list'); diff --git a/server/app/Controllers/Weather.php b/server/app/Controllers/Weather.php deleted file mode 100644 index 74a97ce1..00000000 --- a/server/app/Controllers/Weather.php +++ /dev/null @@ -1,103 +0,0 @@ -request('GET', 'https://meteo.miksoft.pro/api/get/current'); - $weather = json_decode($response->getBody()); - - return $this->respond([ - 'timestamp' => $weather->timestamp, - 'conditions' => $weather->payload - ]); - } catch (\Exception $e) { - log_message('error', '{exception}', ['exception' => $e]); - - return $this->fail('Weather error'); - } - } - - /** - * @return ResponseInterface - */ - public function statistic(): ResponseInterface { - $period = $this->request->getGet('period', FILTER_SANITIZE_SPECIAL_CHARS) ?? date('m-Y'); - $client = \Config\Services::curlrequest(); - - $weatherStart = date('Y-m-d', strtotime("01-{$period}")); - $weatherStop = date('Y-m-t', strtotime("01-{$period}")); - - $response = $client->request('GET', "https://meteo.miksoft.pro/api/get/sensors_period?date_start={$weatherStart}&date_end={$weatherStop}&sensors=clouds,temperature,wind_speed"); - $weather = json_decode($response->getBody()); - - $days = []; - - foreach ($weather->payload as $item) { - $sunData = date_sun_info($item->date, getenv('app.latitude'), getenv('app.longitude')); - - $sunrise = $sunData['astronomical_twilight_end']; - $sunset = $sunData['astronomical_twilight_begin']; - - if ($item->date > $sunset && $item->date < $sunrise) { continue; } - - $day = date('Y-m-d', $item->date); - - if (!isset($days[$day])) { - $days[$day] = (object) ['count' => 0]; - } - - foreach ($item as $var => $val) { - if ($var === 'date') { - continue; - } - - if ($val === null) { - $days[$day]->$var = null; - } else { - if (!isset($days[$day]->$var)) { - $days[$day]->$var = (float) $val; - } else { - $days[$day]->$var += (float) $val; - } - } - } - - $days[$day]->count++; - } - - $result = []; - - foreach ($days as $date => $item) { - - foreach ($item as $var => $value) { - if ($var === 'count') { - continue; - } - - if ($value !== null) { - $item->$var = round($value / $item->count, 1); - } - } - - unset($item->count); - - $result[] = array_merge(['date' => $date], (array) $item); - } - - return $this->respond([ - 'date' => $period, - 'weather' => $result - ]); - } -} \ No newline at end of file