2019-08-30 00:26:07 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
|
2018-11-02 02:20:35 +08:00
|
|
|
const sortUsers = (a, b) => {
|
|
|
|
const sortByResponse = (a, b) => {
|
2019-04-15 04:23:14 +08:00
|
|
|
const DEFAULT_CHAR = '-';
|
|
|
|
const _a = a.answer.toLowerCase();
|
|
|
|
const _b = b.answer.toLowerCase();
|
|
|
|
const isDefault = (_a === DEFAULT_CHAR || _b === DEFAULT_CHAR);
|
|
|
|
|
|
|
|
if (_a < _b || isDefault) {
|
2018-11-02 02:20:35 +08:00
|
|
|
return -1;
|
2019-04-15 04:23:14 +08:00
|
|
|
} if (_a > _b) {
|
2018-11-02 02:20:35 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
const sortByName = (a, b) => {
|
2019-04-15 04:23:14 +08:00
|
|
|
const _a = a.name.toLowerCase();
|
|
|
|
const _b = b.name.toLowerCase();
|
|
|
|
|
|
|
|
if (_a < _b) {
|
2018-11-02 02:20:35 +08:00
|
|
|
return -1;
|
2019-04-15 04:23:14 +08:00
|
|
|
} if (_a > _b) {
|
2018-11-02 02:20:35 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
let sort = sortByResponse(a, b);
|
|
|
|
if (sort === 0) sort = sortByName(a, b);
|
|
|
|
return sort;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
sortUsers,
|
2019-08-30 00:26:07 +08:00
|
|
|
getUser: userId => Users.findOne({ userId }),
|
|
|
|
publishPoll: () => makeCall('publishPoll'),
|
2018-11-02 02:20:35 +08:00
|
|
|
};
|