File tree 1 file changed +32
-1
lines changed
1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -128,8 +128,39 @@ class Client {
128
128
URLSession . shared. dataTask ( . promise, with: try makePostRequest ( urlString: mainURL + " /active-subscriptions " , parameters: [ : ] ) )
129
129
} . map { data, response -> [ Subscription ] in
130
130
try self . validateApiResponse ( data: data, response: response)
131
- let subscriptions = try JSONDecoder ( ) . decode ( [ Subscription ] . self, from: data)
131
+ var subscriptions = try JSONDecoder ( ) . decode ( [ Subscription ] . self, from: data)
132
132
DDLogInfo ( " API RESULT: active-subscriptions: \( subscriptions) " )
133
+ // sort subscriptions with highest tier at the top
134
+ subscriptions. sort ( by: { ( sub1: Subscription , sub2: Subscription ) -> Bool in
135
+ if ( sub1. planType == . proAnnual) {
136
+ return true
137
+ }
138
+ else if ( sub1. planType == . proMonthly) {
139
+ if ( sub2. planType == . proAnnual) {
140
+ return false
141
+ }
142
+ else {
143
+ return true
144
+ }
145
+ }
146
+ else if ( sub1. planType == . annual) {
147
+ if ( sub2. planType == . proAnnual || sub2. planType == . proMonthly) {
148
+ return false
149
+ }
150
+ else {
151
+ return true
152
+ }
153
+ }
154
+ else {
155
+ if ( sub2. planType == . proAnnual || sub2. planType == . proMonthly || sub2. planType == . annual) {
156
+ return false
157
+ }
158
+ else {
159
+ return true
160
+ }
161
+ }
162
+ } )
163
+ DDLogInfo ( " API RESULT: sorted-active-subscriptions: \( subscriptions) " )
133
164
return subscriptions
134
165
}
135
166
}
You can’t perform that action at this time.
0 commit comments