File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
77import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
88import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
99import { Context , type UserDevices } from '@hello.nrfcloud.com/proto-map/api'
10+ import { models } from '@hello.nrfcloud.com/proto-map/models'
1011import middy from '@middy/core'
1112import { type Static } from '@sinclair/typebox'
1213import type {
@@ -51,12 +52,15 @@ const h = async (
5152
5253 const res : Static < typeof UserDevices > = {
5354 '@context' : Context . userDevices . toString ( ) ,
54- devices : devices . map ( ( d ) => ( {
55- id : d . id ,
56- deviceId : d . deviceId ,
57- model : d . model ,
58- expires : new Date ( d . ttl * 1000 ) . toISOString ( ) ,
59- } ) ) ,
55+ devices : devices
56+ // Filter out devices with unknown models
57+ . filter ( ( d ) => isModel ( d . model ) )
58+ . map ( ( d ) => ( {
59+ id : d . id ,
60+ deviceId : d . deviceId ,
61+ model : d . model ,
62+ expires : new Date ( d . ttl * 1000 ) . toISOString ( ) ,
63+ } ) ) ,
6064 }
6165
6266 return aResponse (
@@ -82,3 +86,6 @@ export const handler = middy()
8286 )
8387 . use ( problemResponse ( ) )
8488 . handler ( h )
89+
90+ const isModel = ( model : string ) : model is string =>
91+ Object . keys ( models ) . includes ( model )
You can’t perform that action at this time.
0 commit comments