1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "napi_domain_account_common.h"
17 
18 #include "account_log_wrapper.h"
19 #include "napi_account_common.h"
20 #include "napi/native_common.h"
21 
22 namespace OHOS {
23 namespace AccountJsKit {
24 using namespace AccountSA;
ParseDomainAccountInfo(napi_env env,napi_value object,DomainAccountInfo & info)25 bool ParseDomainAccountInfo(napi_env env, napi_value object, DomainAccountInfo &info)
26 {
27     napi_valuetype type = napi_undefined;
28     napi_typeof(env, object, &type);
29     if (type != napi_object) {
30         ACCOUNT_LOGE("Value is not an object.");
31         return false;
32     }
33     if (!GetStringPropertyByKey(env, object, "domain", info.domain_)) {
34         ACCOUNT_LOGE("Get domainInfo's domain failed");
35         return false;
36     }
37     if (!GetStringPropertyByKey(env, object, "accountName", info.accountName_)) {
38         ACCOUNT_LOGE("Get domainInfo's accountName failed");
39         return false;
40     }
41     if (!GetOptionalStringPropertyByKey(env, object, "accountId", info.accountId_)) {
42         ACCOUNT_LOGE("Get domainInfo's accountId failed");
43         return false;
44     }
45     if (!GetOptionalStringPropertyByKey(env, object, "serverConfigId", info.serverConfigId_)) {
46         ACCOUNT_LOGE("Get domainInfo's serverConfigId failed");
47         return false;
48     }
49     return true;
50 }
51 } // namespace AccountJsKit
52 } // namespace OHOS