From ec5458bf7ef14476bdc1dc0bfcee3dc354457bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 11 Apr 2024 09:57:43 +0200 Subject: [PATCH] sort users (by lastname) --- api/src/stores/user.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/api/src/stores/user.ts b/api/src/stores/user.ts index abe5283..c0e06c3 100644 --- a/api/src/stores/user.ts +++ b/api/src/stores/user.ts @@ -31,7 +31,18 @@ export const useUserStore = defineStore({ getters: { users(state) { - return state._users.filter((u) => !u.deleted); + const u = state._users.filter((u) => !u.deleted); + u.sort((a, b) => { + const a_lastname = a.lastname.toLowerCase(); + const b_lastname = b.lastname.toLowerCase(); + const a_firstname = a.firstname.toLowerCase(); + const b_firstname = b.firstname.toLowerCase(); + if (a_lastname === b_lastname) { + return a_firstname < b_firstname ? -1 : 1; + } + return a_lastname < b_lastname ? -1 : 1; + }); + return u; }, },