link-stack/apps/link/app/_actions/users.ts

66 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2024-05-09 07:42:44 +02:00
"use server";
import { executeREST } from "app/_lib/zammad";
export const getAgentsAction = async () => {
2024-08-14 10:51:12 +02:00
try {
const users = await executeREST({
path: "/api/v1/users",
});
const agents =
users?.filter((user: any) => user.role_ids.includes(2)) ?? [];
const formattedAgents = agents
.map((agent: any) => ({
label: `${agent.firstname} ${agent.lastname}`,
value: `gid://zammad/User/${agent.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
2024-08-14 10:51:12 +02:00
return formattedAgents;
} catch (e) {
2024-08-14 13:03:50 +02:00
console.error(e.message);
2024-08-14 10:51:12 +02:00
return [];
}
};
export const getCustomersAction = async () => {
2024-08-14 10:51:12 +02:00
try {
const users = await executeREST({
path: "/api/v1/users",
});
const customers =
users?.filter((user: any) => user.role_ids.includes(3)) ?? [];
const formattedCustomers = customers
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
2024-08-14 10:51:12 +02:00
return formattedCustomers;
} catch (e) {
2024-08-14 13:03:50 +02:00
console.error(e.message);
2024-08-14 10:51:12 +02:00
return [];
}
};
export const getUsersAction = async () => {
2024-08-14 10:51:12 +02:00
try {
const users = await executeREST({
path: "/api/v1/users",
});
console.log({ users });
const formattedUsers = users
.map((customer: any) => ({
label: customer.login,
value: `gid://zammad/User/${customer.id}`,
}))
.sort((a: any, b: any) => a.label.localeCompare(b.label));
2024-08-14 10:51:12 +02:00
return formattedUsers;
} catch (e) {
2024-08-14 13:03:50 +02:00
console.error(e.message);
2024-08-14 10:51:12 +02:00
return [];
}
};