Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/api/definitions/user/transformers.ts
7461 views
1
import * as Models from '@definitions/user/models';
2
import { FractalResponseData } from '@/api/http';
3
import { transform } from '@definitions/helpers';
4
5
export default class Transformers {
6
static toSSHKey = (data: Record<any, any>): Models.SSHKey => {
7
return {
8
name: data.name,
9
publicKey: data.public_key,
10
fingerprint: data.fingerprint,
11
createdAt: new Date(data.created_at),
12
};
13
};
14
15
static toUser = ({ attributes }: FractalResponseData): Models.User => {
16
return {
17
uuid: attributes.uuid,
18
username: attributes.username,
19
email: attributes.email,
20
image: attributes.image,
21
twoFactorEnabled: attributes['2fa_enabled'],
22
permissions: attributes.permissions || [],
23
createdAt: new Date(attributes.created_at),
24
can(permission): boolean {
25
return this.permissions.includes(permission);
26
},
27
};
28
};
29
30
static toActivityLog = ({ attributes }: FractalResponseData): Models.ActivityLog => {
31
const { actor } = attributes.relationships || {};
32
33
return {
34
id: attributes.id,
35
batch: attributes.batch,
36
event: attributes.event,
37
ip: attributes.ip,
38
isApi: attributes.is_api,
39
description: attributes.description,
40
properties: attributes.properties,
41
hasAdditionalMetadata: attributes.has_additional_metadata ?? false,
42
timestamp: new Date(attributes.timestamp),
43
relationships: {
44
actor: transform(actor as FractalResponseData, this.toUser, null),
45
},
46
};
47
};
48
}
49
50
export class MetaTransformers {}
51
52