misc_pterodactyl-panel/resources/scripts/api/server/users/getServerSubusers.ts
2019-11-03 12:20:11 -08:00

21 lines
966 B
TypeScript

import http, { FractalResponseData } from '@/api/http';
import { Subuser } from '@/state/server/subusers';
export const rawDataToServerSubuser = (data: FractalResponseData): Subuser => ({
uuid: data.attributes.uuid,
username: data.attributes.username,
email: data.attributes.email,
image: data.attributes.image,
twoFactorEnabled: data.attributes['2fa_enabled'],
createdAt: new Date(data.attributes.created_at),
permissions: data.attributes.relationships!.permissions.attributes.permissions,
can: permission => data.attributes.relationships!.permissions.attributes.permissions.indexOf(permission) >= 0,
});
export default (uuid: string): Promise<Subuser[]> => {
return new Promise((resolve, reject) => {
http.get(`/api/client/servers/${uuid}/users`, { params: { include: [ 'permissions' ] } })
.then(({ data }) => resolve((data.data || []).map(rawDataToServerSubuser)))
.catch(reject);
});
};