gitscope
← marzneshin / v0.6.4 / dashboard/src/modules/users/domain/user-traffic-sorting-fn.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/users/domain/user-traffic-sorting-fn.ts · TypeScript
Blame Raw
 1import { UserType } from "@marzneshin/modules/users";
 2
 3export const userTrafficSortingFn = (userA: UserType, userB: UserType) => {
 4    if (userA.data_limit && userB.data_limit) {
 5        const rowAUsedTraffic = (userA.used_traffic / userA.data_limit) * 100
 6        const rowBUsedTraffic = (userB.used_traffic / userB.data_limit) * 100
 7        return (
 8            rowAUsedTraffic > rowBUsedTraffic
 9            && rowAUsedTraffic !== rowBUsedTraffic
10        ) ? 1 : -1
11    }
12    return 0
13}