2021-10-10 18:32:07 +00:00
|
|
|
import { Model, UUID } from '@/api/admin/index';
|
|
|
|
import { Server } from '@/api/admin/server';
|
2021-10-10 20:13:10 +00:00
|
|
|
import http, { QueryBuilderParams, withQueryBuilderParams } from '@/api/http';
|
2021-10-10 18:32:07 +00:00
|
|
|
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);
|
|
|
|
};
|
2021-10-10 20:13:10 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
};
|