createLocation method

Future<Location> createLocation({
  1. required String name,
  2. required String code,
  3. String? description,
  4. String? type,
  5. String? parentId,
  6. Address? address,
  7. ContactInfo? contactInfo,
  8. Map<String, dynamic>? metadata,
})

Create new location

Implementation

Future<Location> createLocation({
  required String name,
  required String code,
  String? description,
  String? type,
  String? parentId,
  Address? address,
  ContactInfo? contactInfo,
  Map<String, dynamic>? metadata,
}) async {
  final response = await _apiClient.post<Map<String, dynamic>>(
    '/api/v1/locations',
    data: {
      'name': name,
      'code': code,
      if (description != null) 'description': description,
      if (type != null) 'type': type,
      if (parentId != null) 'parentId': parentId,
      if (address != null) 'address': address.toJson(),
      if (contactInfo != null) 'contactInfo': contactInfo.toJson(),
      if (metadata != null) 'metadata': metadata,
    },
  );

  final data = response['data'] as Map<String, dynamic>;
  return Location.fromJson(data);
}