|
1 | | -import { SSHKey } from '@definitions/user/models'; |
| 1 | +import * as Models from '@definitions/user/models'; |
| 2 | +import { FractalResponseData } from '@/api/http'; |
| 3 | +import { transform } from '@definitions/helpers'; |
2 | 4 |
|
3 | 5 | export default class Transformers { |
4 | | - static toSSHKey (data: Record<any, any>): SSHKey { |
| 6 | + static toSSHKey (data: Record<any, any>): Models.SSHKey { |
5 | 7 | return { |
6 | 8 | name: data.name, |
7 | 9 | publicKey: data.public_key, |
8 | 10 | fingerprint: data.fingerprint, |
9 | 11 | createdAt: new Date(data.created_at), |
10 | 12 | }; |
11 | 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 | + batch: attributes.batch, |
| 35 | + event: attributes.event, |
| 36 | + ip: attributes.ip, |
| 37 | + description: attributes.description, |
| 38 | + properties: attributes.properties, |
| 39 | + timestamp: new Date(attributes.timestamp), |
| 40 | + relationships: { |
| 41 | + actor: transform(actor as FractalResponseData, this.toUser, null), |
| 42 | + }, |
| 43 | + }; |
| 44 | + } |
12 | 45 | } |
13 | 46 |
|
14 | 47 | export class MetaTransformers { |
|
0 commit comments