1- import { json , type LoaderFunctionArgs } from "@remix-run/node" ;
2- import { type ActionFunctionArgs } from "react-router" ;
1+ import { type LoaderFunctionArgs , type ActionFunctionArgs } from "react-router" ;
32import { BoxesQuerySchema , deleteDevice } from "~/lib/devices-service.server" ;
43import { getUserFromJwt } from "~/lib/jwt" ;
54import {
@@ -290,10 +289,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
290289 if ( ! parseResult . success ) {
291290 const { fieldErrors, formErrors } = parseResult . error . flatten ( ) ;
292291 if ( fieldErrors . format ) {
293- throw json ( { error : "Invalid format parameter" } , { status : 422 } ) ;
292+ throw Response . json (
293+ { error : "Invalid format parameter" } ,
294+ { status : 422 } ,
295+ ) ;
294296 }
295297
296- throw json ( { error : parseResult . error . flatten ( ) } , { status : 422 } ) ;
298+ throw Response . json (
299+ { error : parseResult . error . flatten ( ) } ,
300+ { status : 422 } ,
301+ ) ;
297302 }
298303
299304 const params : FindDevicesOptions = parseResult . data ;
@@ -363,19 +368,19 @@ async function del(request: Request, user: User, params: any) {
363368 const { deviceId } = params ;
364369
365370 if ( ! deviceId ) {
366- throw json ( { message : "Device ID is required" } , { status : 400 } ) ;
371+ throw Response . json ( { message : "Device ID is required" } , { status : 400 } ) ;
367372 }
368373
369374 const device = ( await getDevice ( { id : deviceId } ) ) as unknown as Device ;
370375
371376 if ( ! device ) {
372- throw json ( { message : "Device not found" } , { status : 404 } ) ;
377+ throw Response . json ( { message : "Device not found" } , { status : 404 } ) ;
373378 }
374379
375380 const body = await request . json ( ) ;
376381
377382 if ( ! body . password ) {
378- throw json (
383+ throw Response . json (
379384 { message : "Password is required for device deletion" } ,
380385 { status : 400 } ,
381386 ) ;
@@ -408,7 +413,7 @@ async function post(request: Request, user: User) {
408413 const body = await request . json ( ) ;
409414
410415 if ( ! body . location ) {
411- throw json (
416+ throw Response . json (
412417 { message : "missing required parameter location" } ,
413418 { status : 400 } ,
414419 ) ;
@@ -419,7 +424,7 @@ async function post(request: Request, user: User) {
419424 if ( Array . isArray ( body . location ) ) {
420425 // Handle array format [lat, lng, height?]
421426 if ( body . location . length < 2 ) {
422- throw json (
427+ throw Response . json (
423428 {
424429 message : `Illegal value for parameter location. missing latitude or longitude in location [${ body . location . join ( "," ) } ]` ,
425430 } ,
@@ -432,7 +437,7 @@ async function post(request: Request, user: User) {
432437 } else if ( typeof body . location === "object" && body . location !== null ) {
433438 // Handle object format { lat, lng, height? }
434439 if ( ! ( "lat" in body . location ) || ! ( "lng" in body . location ) ) {
435- throw json (
440+ throw Response . json (
436441 {
437442 message :
438443 "Illegal value for parameter location. missing latitude or longitude" ,
@@ -444,7 +449,7 @@ async function post(request: Request, user: User) {
444449 longitude = Number ( body . location . lng ) ;
445450 height = body . location . height ? Number ( body . location . height ) : undefined ;
446451 } else {
447- throw json (
452+ throw Response . json (
448453 {
449454 message :
450455 "Illegal value for parameter location. Expected array or object" ,
@@ -454,15 +459,18 @@ async function post(request: Request, user: User) {
454459 }
455460
456461 if ( isNaN ( latitude ) || isNaN ( longitude ) ) {
457- throw json (
462+ throw Response . json (
458463 { message : "Invalid latitude or longitude values" } ,
459464 { status : 422 } ,
460465 ) ;
461466 }
462467
463468 const rawAuthorizationHeader = request . headers . get ( "authorization" ) ;
464469 if ( ! rawAuthorizationHeader ) {
465- throw json ( { message : "Authorization header required" } , { status : 401 } ) ;
470+ throw Response . json (
471+ { message : "Authorization header required" } ,
472+ { status : 401 } ,
473+ ) ;
466474 }
467475 const [ , jwtString ] = rawAuthorizationHeader . split ( " " ) ;
468476
@@ -474,7 +482,7 @@ async function post(request: Request, user: User) {
474482
475483 const newDevice = await createDevice ( deviceData , user . id ) ;
476484
477- return json (
485+ return Response . json (
478486 {
479487 data : {
480488 ...newDevice ,
@@ -490,6 +498,6 @@ async function post(request: Request, user: User) {
490498 throw error ;
491499 }
492500
493- throw json ( { message : "Internal server error" } , { status : 500 } ) ;
501+ throw Response . json ( { message : "Internal server error" } , { status : 500 } ) ;
494502 }
495503}
0 commit comments