NEW: MIH Home & Mzansi Profile Provider Setup pt 2 done
This commit is contained in:
@@ -120,7 +120,7 @@ class MihBusinessDetailsServices {
|
||||
}
|
||||
|
||||
Future<Response> createBusinessDetails(
|
||||
String appId,
|
||||
MzansiProfileProvider provider,
|
||||
String busineName,
|
||||
String businessType,
|
||||
String businessRegistrationNo,
|
||||
@@ -141,9 +141,6 @@ class MihBusinessDetailsServices {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
String logoPath = businessLogoFilename.isNotEmpty
|
||||
? "$appId/business_files/$businessLogoFilename"
|
||||
: "";
|
||||
var response = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business/insert/"),
|
||||
headers: <String, String>{
|
||||
@@ -154,7 +151,7 @@ class MihBusinessDetailsServices {
|
||||
"type": businessType,
|
||||
"registration_no": businessRegistrationNo,
|
||||
"logo_name": businessLogoFilename,
|
||||
"logo_path": logoPath,
|
||||
"logo_path": "",
|
||||
"contact_no": businessPhoneNumber,
|
||||
"bus_email": businessEmail,
|
||||
"gps_location": businessLocation,
|
||||
@@ -165,7 +162,50 @@ class MihBusinessDetailsServices {
|
||||
"mission_vision": businessMissionVision,
|
||||
}),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
context.pop();
|
||||
if (response.statusCode == 201) {
|
||||
int finalStatusCode = await updateBusinessDetailsV2(
|
||||
jsonDecode(response.body)['business_id'],
|
||||
busineName,
|
||||
businessType,
|
||||
businessRegistrationNo,
|
||||
businessPracticeNo,
|
||||
businessVatNo,
|
||||
businessEmail,
|
||||
businessPhoneNumber,
|
||||
businessLocation,
|
||||
businessLogoFilename,
|
||||
businessWebsite,
|
||||
businessRating,
|
||||
businessMissionVision,
|
||||
provider,
|
||||
context,
|
||||
);
|
||||
if (finalStatusCode == 200) {
|
||||
String logoPath = businessLogoFilename.isNotEmpty
|
||||
? "${jsonDecode(response.body)['business_id']}/business_files/$businessLogoFilename"
|
||||
: "";
|
||||
provider.setBusiness(
|
||||
newBusiness: Business(
|
||||
jsonDecode(response.body)['business_id'],
|
||||
busineName,
|
||||
businessType,
|
||||
businessRegistrationNo,
|
||||
businessLogoFilename,
|
||||
logoPath,
|
||||
businessPhoneNumber,
|
||||
businessEmail,
|
||||
provider.user!.app_id,
|
||||
businessLocation,
|
||||
businessPracticeNo,
|
||||
businessVatNo,
|
||||
businessWebsite,
|
||||
businessRating,
|
||||
businessMissionVision,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -227,7 +267,7 @@ class MihBusinessDetailsServices {
|
||||
filePath,
|
||||
business_phone_number,
|
||||
business_email,
|
||||
provider.business!.app_id,
|
||||
business_id,
|
||||
business_location,
|
||||
business_practice_no,
|
||||
business_vat_no,
|
||||
|
||||
142
Frontend/lib/mih_services/mih_business_employee_services.dart
Normal file
142
Frontend/lib/mih_services/mih_business_employee_services.dart
Normal file
@@ -0,0 +1,142 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_employee.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class MihBusinessEmployeeServices {
|
||||
Future<int> fetchEmployees(
|
||||
MzansiProfileProvider mzansiProfileProvider, BuildContext context) async {
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/business-user/employees/${mzansiProfileProvider.businessUser!.business_id}"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<BusinessEmployee> employeeList = List<BusinessEmployee>.from(
|
||||
l.map((model) => BusinessEmployee.fromJson(model)));
|
||||
mzansiProfileProvider.setEmployeeList(employeeList: employeeList);
|
||||
} else {
|
||||
throw Exception('failed to load employees');
|
||||
}
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int> addEmployee(
|
||||
MzansiProfileProvider provider,
|
||||
AppUser newEmployee,
|
||||
String access,
|
||||
BuildContext context,
|
||||
) async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
var response = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/insert/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": provider.business!.business_id,
|
||||
"app_id": newEmployee.app_id,
|
||||
"signature": "",
|
||||
"sig_path": "",
|
||||
"title": "",
|
||||
"access": access,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 201) {
|
||||
provider.addEmployee(
|
||||
newEmployee: BusinessEmployee(
|
||||
provider.business!.business_id,
|
||||
newEmployee.app_id,
|
||||
"",
|
||||
access,
|
||||
newEmployee.fname,
|
||||
newEmployee.lname,
|
||||
newEmployee.email,
|
||||
newEmployee.username,
|
||||
),
|
||||
);
|
||||
provider.setBusinessIndex(2);
|
||||
}
|
||||
context.pop();
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int> updateEmployeeDetails(
|
||||
MzansiProfileProvider provider,
|
||||
BusinessEmployee employee,
|
||||
String newTitle,
|
||||
String newAccess,
|
||||
BuildContext context) async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
var response = await http.put(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/employees/update/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": employee.business_id,
|
||||
"app_id": employee.app_id,
|
||||
"title": newTitle,
|
||||
"access": newAccess,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
provider.updateEmplyeeDetails(
|
||||
updatedEmployee: BusinessEmployee(
|
||||
employee.business_id,
|
||||
employee.app_id,
|
||||
newTitle,
|
||||
newAccess,
|
||||
employee.fname,
|
||||
employee.lname,
|
||||
employee.email,
|
||||
employee.username,
|
||||
),
|
||||
);
|
||||
}
|
||||
context.pop();
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int> deleteEmployee(
|
||||
MzansiProfileProvider provider,
|
||||
BusinessEmployee employee,
|
||||
BuildContext context,
|
||||
) async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
var response = await http.delete(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/employees/delete/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": employee.business_id,
|
||||
"app_id": employee.app_id,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
provider.deleteEmplyee(deletedEmployee: employee);
|
||||
}
|
||||
context.pop();
|
||||
return response.statusCode;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||
@@ -44,8 +45,9 @@ class MihFileApi {
|
||||
fileUrl = decodedData['minioURL'];
|
||||
} else {
|
||||
// internetConnectionPopUp(context);
|
||||
print("Error: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
KenLogger.error("Get File Error: $url");
|
||||
KenLogger.error("Get File Error: ${response.statusCode}");
|
||||
KenLogger.error("Get File Error: ${response.body}");
|
||||
}
|
||||
} catch (e) {
|
||||
// internetConnectionPopUp(context);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -24,7 +23,7 @@ class MihMyBusinessUserServices {
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
KenLogger.success(response.body);
|
||||
// KenLogger.success(response.body);
|
||||
BusinessUser? businessUser =
|
||||
BusinessUser.fromJson(jsonDecode(response.body));
|
||||
context
|
||||
@@ -42,6 +41,7 @@ class MihMyBusinessUserServices {
|
||||
String signatureFilename,
|
||||
String title,
|
||||
String access,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
showDialog(
|
||||
@@ -50,6 +50,7 @@ class MihMyBusinessUserServices {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
String sigPath = "$business_id/business_files/$signatureFilename";
|
||||
var response = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/business-user/insert/"),
|
||||
headers: <String, String>{
|
||||
@@ -59,13 +60,17 @@ class MihMyBusinessUserServices {
|
||||
"business_id": business_id,
|
||||
"app_id": app_id,
|
||||
"signature": signatureFilename,
|
||||
"sig_path": "$business_id/business_files/$signatureFilename",
|
||||
"sig_path": sigPath,
|
||||
"title": title,
|
||||
"access": access,
|
||||
}),
|
||||
);
|
||||
context.pop();
|
||||
if (response.statusCode == 201) {
|
||||
provider.setBusinessUser(
|
||||
newBusinessUser: BusinessUser(
|
||||
0, business_id, app_id, signatureFilename, sigPath, title, access),
|
||||
);
|
||||
return 201;
|
||||
} else {
|
||||
internetConnectionPopUp(context);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
||||
@@ -132,11 +133,13 @@ class MihUserServices {
|
||||
var fileName = profilePicture.replaceAll(RegExp(r' '), '-');
|
||||
var filePath = "${signedInUser.app_id}/profile_files/$fileName";
|
||||
String profileType;
|
||||
KenLogger.success("is Busines User: $isBusinessUser");
|
||||
if (isBusinessUser) {
|
||||
profileType = "business";
|
||||
} else {
|
||||
profileType = "personal";
|
||||
}
|
||||
KenLogger.success("Profile Type: $profileType");
|
||||
var response = await http.put(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user/update/v2/"),
|
||||
headers: <String, String>{
|
||||
|
||||
Reference in New Issue
Block a user