Skip to content

Commit 1b9d281

Browse files
sneurlaxjulian-CStack
authored andcommitted
feat(shopinbit): split tracking links
1 parent ad6cde6 commit 1b9d281

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

lib/services/shopinbit/src/models/ticket.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import '../../../../utilities/logger.dart';
22

3+
/// Splits a raw `tracking_link` value into individual tracking URLs.
4+
///
5+
/// Multiple links may be joined with any of `,`, `|`, or `;` (and a single
6+
/// value may mix them). Returns an empty list for null/empty input. Each URL is
7+
/// trimmed and empty segments are discarded.
8+
List<String> splitTrackingLinks(String? raw) {
9+
if (raw == null) return const [];
10+
return raw
11+
.split(RegExp(r'[,|;]'))
12+
.map((s) => s.trim())
13+
.where((s) => s.isNotEmpty)
14+
.toList();
15+
}
16+
317
enum TicketState {
418
newTicket('NEW'),
519
checking('CHECKING'),
@@ -88,6 +102,14 @@ class TicketStatus {
88102
this.trackingLink,
89103
});
90104

105+
/// The tracking link(s) split into individual URLs.
106+
///
107+
/// A ticket may carry zero, one, or several tracking URLs. When there are
108+
/// several the API joins them into [trackingLink] using any of `,`, `|`, or
109+
/// `;` as the separator (mixed separators occur in practice), so we split on
110+
/// all three.
111+
List<String> get trackingLinks => splitTrackingLinks(trackingLink);
112+
91113
factory TicketStatus.fromJson(Map<String, dynamic> json) {
92114
final rawState = json['state'] as String;
93115
return TicketStatus(
@@ -99,7 +121,9 @@ class TicketStatus {
99121
? DateTime.parse(json['last_agent_message_at'] as String)
100122
: null,
101123
paymentInvoiceStatus: json['payment_invoice_status'] as String?,
102-
trackingLink: json['tracking_link'] as String?,
124+
// Production returns "" (not null) when there is no tracking link yet;
125+
// normalize so callers can treat it like any other absent value.
126+
trackingLink: _emptyToNull(json['tracking_link']),
103127
);
104128
}
105129

@@ -182,3 +206,9 @@ int _toInt(dynamic value) {
182206
if (value is int) return value;
183207
return int.parse(value.toString());
184208
}
209+
210+
String? _emptyToNull(dynamic value) {
211+
final s = value?.toString().trim();
212+
if (s == null || s.isEmpty) return null;
213+
return s;
214+
}

0 commit comments

Comments
 (0)