feat: add weather unit preferences
Some checks failed
CI / Lint, test, typecheck and build (push) Has been cancelled
Some checks failed
CI / Lint, test, typecheck and build (push) Has been cancelled
This commit is contained in:
@@ -3,8 +3,14 @@ import { upsertPushSubscription, removePushSubscription } from "@/lib/push-store
|
||||
import { isWebPushConfigured } from "@/lib/push-service";
|
||||
import { normalizeProvinceName } from "@/lib/provinces";
|
||||
import {
|
||||
DEFAULT_DISTANCE_UNIT,
|
||||
DEFAULT_PRECIPITATION_UNIT,
|
||||
DEFAULT_PRESSURE_UNIT,
|
||||
DEFAULT_TEMPERATURE_UNIT,
|
||||
DEFAULT_WIND_SPEED_UNIT,
|
||||
isDistanceUnit,
|
||||
isPrecipitationUnit,
|
||||
isPressureUnit,
|
||||
isTemperatureUnit,
|
||||
isWindSpeedUnit,
|
||||
} from "@/lib/weather-utils";
|
||||
@@ -45,6 +51,9 @@ export async function POST(request: Request) {
|
||||
countyTeryt?: unknown;
|
||||
temperatureUnit?: unknown;
|
||||
windSpeedUnit?: unknown;
|
||||
precipitationUnit?: unknown;
|
||||
pressureUnit?: unknown;
|
||||
distanceUnit?: unknown;
|
||||
} | null;
|
||||
const subscription = body?.subscription;
|
||||
const region: WeatherRegion = body?.region === "GLOBAL" ? "GLOBAL" : "PL";
|
||||
@@ -52,6 +61,9 @@ export async function POST(request: Request) {
|
||||
const language: Language = body?.language === "en" ? "en" : "pl";
|
||||
const rawTemperatureUnit = body?.temperatureUnit;
|
||||
const rawWindSpeedUnit = body?.windSpeedUnit;
|
||||
const rawPrecipitationUnit = body?.precipitationUnit;
|
||||
const rawPressureUnit = body?.pressureUnit;
|
||||
const rawDistanceUnit = body?.distanceUnit;
|
||||
|
||||
const enabled = body?.enabled !== false && region === "PL";
|
||||
if (!isBrowserPushSubscription(subscription) || (enabled && !province)) {
|
||||
@@ -76,6 +88,9 @@ export async function POST(request: Request) {
|
||||
countyTeryt: typeof body?.countyTeryt === "string" && /^\d{4}$/.test(body.countyTeryt) ? body.countyTeryt : null,
|
||||
temperatureUnit: isTemperatureUnit(rawTemperatureUnit) ? rawTemperatureUnit : DEFAULT_TEMPERATURE_UNIT,
|
||||
windSpeedUnit: isWindSpeedUnit(rawWindSpeedUnit) ? rawWindSpeedUnit : DEFAULT_WIND_SPEED_UNIT,
|
||||
precipitationUnit: isPrecipitationUnit(rawPrecipitationUnit) ? rawPrecipitationUnit : DEFAULT_PRECIPITATION_UNIT,
|
||||
pressureUnit: isPressureUnit(rawPressureUnit) ? rawPressureUnit : DEFAULT_PRESSURE_UNIT,
|
||||
distanceUnit: isDistanceUnit(rawDistanceUnit) ? rawDistanceUnit : DEFAULT_DISTANCE_UNIT,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user