Add support for returning transforming activity logs on the front-end

This commit is contained in:
DaneEveritt 2022-05-29 20:34:48 -04:00
parent e15985ea39
commit a5521ecb79
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
9 changed files with 162 additions and 6 deletions

View file

@ -1,7 +1,9 @@
import { SSHKey } from '@definitions/user/models';
import * as Models from '@definitions/user/models';
import { FractalResponseData } from '@/api/http';
import { transform } from '@definitions/helpers';
export default class Transformers {
static toSSHKey (data: Record<any, any>): SSHKey {
static toSSHKey (data: Record<any, any>): Models.SSHKey {
return {
name: data.name,
publicKey: data.public_key,
@ -9,6 +11,37 @@ export default class Transformers {
createdAt: new Date(data.created_at),
};
}
static toUser ({ attributes }: FractalResponseData): Models.User {
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),
can (permission): boolean {
return this.permissions.includes(permission);
},
};
}
static toActivityLog ({ attributes }: FractalResponseData): Models.ActivityLog {
const { actor } = attributes.relationships || {};
return {
batch: attributes.batch,
event: attributes.event,
ip: attributes.ip,
description: attributes.description,
properties: attributes.properties,
timestamp: new Date(attributes.timestamp),
relationships: {
actor: transform(actor as FractalResponseData, this.toUser, null),
},
};
}
}
export class MetaTransformers {