From 6c792cbced89ef6c8909f35739e771ac6924d6de Mon Sep 17 00:00:00 2001 From: nextwo <1234> Date: Tue, 2 May 2023 15:37:04 +0300 Subject: [PATCH] changed to new apis --- lib/api/gas_refill_api_client.dart | 48 ++++++++++++++++++++++-------- lib/models/device/device.dart | 2 +- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/lib/api/gas_refill_api_client.dart b/lib/api/gas_refill_api_client.dart index 87d6c631..d4447679 100644 --- a/lib/api/gas_refill_api_client.dart +++ b/lib/api/gas_refill_api_client.dart @@ -91,23 +91,47 @@ class GasRefillApiClient { required GasRefillModel? oldModel, required GasRefillModel newModel, }) async { + Map body = { - "uid": UserApiClient().user?.id.toString(), - "token": UserApiClient().user?.token, - "title": newModel.title, - "status": newModel.status?.id.toString(), + "id": oldModel?.id, + "gazRefillNo": await generateGazRefillNo(), + "assignedEmployee": { + "id": UserApiClient().user?.id.toString(), + "name": UserApiClient().user?.username.toString() + }, + "status": { + "id": 0, + "name": "", + "value": 0 + }, }; - body["gazRefillDetails"] = jsonEncode(newModel.details + body["gazRefillDetails"] = newModel.details ?.map((model) => { - "gasType": model.type?.id.toString(), - "cylinderSize": model.cylinderSize?.id.toString(), - "requestedQty": model.requestedQuantity.toString(), - "deliverdQty": model.deliveredQuantity.toString(), - }) - .toList()); + "gasType": { + "id": model.type?.id, + "name": model.type?.label.toString(), + "value": model.type?.id + }, + "cylinderType": { + "id": 0, + "name": "", + "value": 0 + }, + "cylinderSize": { + "id": model.cylinderSize?.id, + "name": model.cylinderSize?.label.toString(), + "value": model.cylinderSize?.id, + }, + "requestedQty": model.requestedQuantity, + "deliverdQty": 0 + + }) + .toList(); + + - final reponse = await ApiClient().postJsonForResponse("${URLs.host1}${URLs.updateGasRefill}/${newModel.id}", body); + final reponse = await ApiClient().putJsonForResponse("${URLs.host1}${URLs.updateGasRefill}/${newModel.id}", body); oldModel?.fromGasRefillModel(newModel); } diff --git a/lib/models/device/device.dart b/lib/models/device/device.dart index e266d366..db628c73 100644 --- a/lib/models/device/device.dart +++ b/lib/models/device/device.dart @@ -27,7 +27,7 @@ class Device { factory Device.fromJson(Map parsedJson) { return Device( - id: parsedJson["nid"] ?? parsedJson["id"], + id: parsedJson["nid"] ?? parsedJson["id"].toString(), serialNumber: parsedJson["sn"] ?? parsedJson["value"], number: parsedJson["asset_no"], brand: parsedJson["brand"] as String?,