misc_pterodactyl-panel/resources/scripts/api/admin/user.ts
2021-10-10 13:13:10 -07:00

44 lines
1.2 KiB
TypeScript

import { Model, UUID } from '@/api/admin/index';
import { Server } from '@/api/admin/server';
import http, { QueryBuilderParams, withQueryBuilderParams } from '@/api/http';
import { AdminTransformers } from '@/api/admin/transformers';
export interface User extends Model {
id: number;
uuid: UUID;
externalId: string;
username: string;
email: string;
language: string;
adminRoleId: number | null;
roleName: string;
isRootAdmin: boolean;
isUsingTwoFactor: boolean;
avatarUrl: string;
createdAt: Date;
updatedAt: Date;
relationships: {
role: UserRole | null;
servers?: Server[];
};
}
export interface UserRole extends Model {
id: string;
name: string;
description: string;
}
export const getUser = async (id: string | number): Promise<User> => {
const { data } = await http.get(`/api/application/users/${id}`);
return AdminTransformers.toUser(data.data);
};
export const searchUserAccounts = async (params: QueryBuilderParams<'username' | 'email'>): Promise<User[]> => {
const { data } = await http.get('/api/application/users', {
params: withQueryBuilderParams(params),
});
return data.data.map(AdminTransformers.toUser);
};