From 87333971c22635caa80427fb861659a5a1be19c3 Mon Sep 17 00:00:00 2001 From: dgiot Date: Wed, 9 Mar 2022 20:26:11 +0800 Subject: [PATCH] fix: Restoration model category query --- .../dgiot_api/src/handler/dgiot_data_handler.erl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/dgiot_api/src/handler/dgiot_data_handler.erl b/apps/dgiot_api/src/handler/dgiot_data_handler.erl index 9a924682..9dd85493 100644 --- a/apps/dgiot_api/src/handler/dgiot_data_handler.erl +++ b/apps/dgiot_api/src/handler/dgiot_data_handler.erl @@ -599,9 +599,9 @@ postThing(ProductId, Item, SessionToken) -> case dgiot_parse:get_object(<<"Product">>, ProductId, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of {ok, #{<<"thing">> := Thing}} -> ModuleType = maps:get(<<"moduleType">>, Item, <<"properties">>), - Properties = maps:get(<<"properties">>, Thing, []), + Modules = maps:get(ModuleType, Thing, []), #{<<"identifier">> := Identifier} = Item, - {Ids, NewProperties} = + {Ids, NewModules} = lists:foldl(fun(X, {Ids1, Acc}) -> case X of #{<<"identifier">> := Identifier} -> @@ -609,11 +609,11 @@ postThing(ProductId, Item, SessionToken) -> _ -> {Ids1, Acc ++ [X]} end - end, {[], [Item]}, Properties), + end, {[], [Item]}, Modules), case length(Ids) == 0 of true -> {_, R} = dgiot_parse:update_object(<<"Product">>, ProductId, - #{<<"thing">> => Thing#{ModuleType => NewProperties}}, + #{<<"thing">> => Thing#{ModuleType => NewModules}}, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]), {ok, R#{<<"code">> => 200}}; false -> @@ -631,8 +631,8 @@ putTing(ProductId, Item, SessionToken) -> #{<<"identifier">> := Identifier} = Item, case dgiot_parse:get_object(<<"Product">>, ProductId, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of {ok, #{<<"thing">> := Thing}} -> - Properties = maps:get(ModuleType, Thing, []), - NewProperties = + Modules = maps:get(ModuleType, Thing, []), + NewModules = lists:foldl(fun(X, Acc) -> case X of #{<<"identifier">> := Identifier} -> @@ -640,9 +640,9 @@ putTing(ProductId, Item, SessionToken) -> _ -> Acc ++ [X] end - end, [], Properties), + end, [], Modules), {_, R} = dgiot_parse:update_object(<<"Product">>, ProductId, - #{<<"thing">> => Thing#{ModuleType => NewProperties}}, + #{<<"thing">> => Thing#{ModuleType => NewModules}}, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]), {ok, R#{<<"code">> => 200}}; Error ->