2022-05-30 00:34:48 +00:00
|
|
|
import * as Models from '@definitions/user/models';
|
|
|
|
import { FractalResponseData } from '@/api/http';
|
|
|
|
import { transform } from '@definitions/helpers';
|
2022-05-14 21:31:53 +00:00
|
|
|
|
2022-05-07 20:52:58 +00:00
|
|
|
export default class Transformers {
|
2022-06-05 22:35:53 +00:00
|
|
|
static toSSHKey = (data: Record<any, any>): Models.SSHKey => {
|
2022-05-14 21:31:53 +00:00
|
|
|
return {
|
|
|
|
name: data.name,
|
|
|
|
publicKey: data.public_key,
|
|
|
|
fingerprint: data.fingerprint,
|
|
|
|
createdAt: new Date(data.created_at),
|
|
|
|
};
|
2022-06-26 19:13:52 +00:00
|
|
|
};
|
2022-05-30 00:34:48 +00:00
|
|
|
|
2022-06-05 22:35:53 +00:00
|
|
|
static toUser = ({ attributes }: FractalResponseData): Models.User => {
|
2022-05-30 00:34:48 +00:00
|
|
|
return {
|
|
|
|
uuid: attributes.uuid,
|
|
|
|
username: attributes.username,
|
|
|
|
email: attributes.email,
|
|
|
|
image: attributes.image,
|
|
|
|
twoFactorEnabled: attributes['2fa_enabled'],
|
|
|
|
permissions: attributes.permissions || [],
|
|
|
|
createdAt: new Date(attributes.created_at),
|
2022-06-26 19:13:52 +00:00
|
|
|
can(permission): boolean {
|
2022-05-30 00:34:48 +00:00
|
|
|
return this.permissions.includes(permission);
|
|
|
|
},
|
|
|
|
};
|
2022-06-26 19:13:52 +00:00
|
|
|
};
|
2022-05-30 00:34:48 +00:00
|
|
|
|
2022-06-05 22:35:53 +00:00
|
|
|
static toActivityLog = ({ attributes }: FractalResponseData): Models.ActivityLog => {
|
2022-05-30 00:34:48 +00:00
|
|
|
const { actor } = attributes.relationships || {};
|
|
|
|
|
|
|
|
return {
|
2022-07-10 18:53:29 +00:00
|
|
|
id: attributes.id,
|
2022-05-30 00:34:48 +00:00
|
|
|
batch: attributes.batch,
|
|
|
|
event: attributes.event,
|
|
|
|
ip: attributes.ip,
|
2022-06-18 16:52:26 +00:00
|
|
|
isApi: attributes.is_api,
|
2022-05-30 00:34:48 +00:00
|
|
|
description: attributes.description,
|
|
|
|
properties: attributes.properties,
|
2022-06-12 19:30:49 +00:00
|
|
|
hasAdditionalMetadata: attributes.has_additional_metadata ?? false,
|
2022-05-30 00:34:48 +00:00
|
|
|
timestamp: new Date(attributes.timestamp),
|
|
|
|
relationships: {
|
|
|
|
actor: transform(actor as FractalResponseData, this.toUser, null),
|
|
|
|
},
|
|
|
|
};
|
2022-06-26 19:13:52 +00:00
|
|
|
};
|
2022-05-07 20:52:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
export class MetaTransformers {}
|