113 lines
3.4 KiB
JavaScript
113 lines
3.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.UserData = exports.User = void 0;
|
|
class User {
|
|
id;
|
|
name;
|
|
email;
|
|
password;
|
|
metadata;
|
|
constructor(id, name, email, password, metadata) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.email = email;
|
|
this.password = password;
|
|
this.metadata = metadata;
|
|
}
|
|
static create(data) {
|
|
return new User(crypto.randomUUID(), data.name, data.email, data.password, data.metadata);
|
|
}
|
|
delete() {
|
|
// Business Rule
|
|
}
|
|
changeEmail(email) {
|
|
this.email = email;
|
|
}
|
|
changeName(name) {
|
|
this.name = name;
|
|
}
|
|
changePassword(newPassword) {
|
|
this.password = newPassword;
|
|
}
|
|
static restore(data) {
|
|
return new User(data.id, data.name, data.email, data.password, data.metadata);
|
|
}
|
|
}
|
|
exports.User = User;
|
|
class UserData {
|
|
id;
|
|
authentikId;
|
|
username;
|
|
email;
|
|
name;
|
|
roles;
|
|
permissions;
|
|
isActive;
|
|
deletedAt;
|
|
lastSeenAt;
|
|
lastSyncedAt;
|
|
syncStatus;
|
|
storageQuota;
|
|
storageUsed;
|
|
constructor(id, authentikId, username, email, name, roles, permissions, isActive, deletedAt, lastSeenAt, lastSyncedAt, syncStatus, storageQuota, storageUsed) {
|
|
this.id = id;
|
|
this.authentikId = authentikId;
|
|
this.username = username;
|
|
this.email = email;
|
|
this.name = name;
|
|
this.roles = roles;
|
|
this.permissions = permissions;
|
|
this.isActive = isActive;
|
|
this.deletedAt = deletedAt;
|
|
this.lastSeenAt = lastSeenAt;
|
|
this.lastSyncedAt = lastSyncedAt;
|
|
this.syncStatus = syncStatus;
|
|
this.storageQuota = storageQuota;
|
|
this.storageUsed = storageUsed;
|
|
}
|
|
static create(data) {
|
|
return new UserData(crypto.randomUUID(), data.authentikId ?? null, data.username, data.email ?? '', data.name ?? data.username, [], [], true, null, null, null, null, data.storageQuota ?? null, data.storageUsed ?? null);
|
|
}
|
|
static restore(props) {
|
|
return new UserData(props.id, props.authentikId ?? null, props.username, props.email, props.name ?? props.username, props.roles || [], props.permissions || [], props.isActive ?? true, props.deletedAt ?? null, props.lastSeenAt ?? null, props.lastSyncedAt ?? null, props.syncStatus ?? null, props.storageQuota ?? null, props.storageUsed ?? null);
|
|
}
|
|
assignRole(role) {
|
|
if (this.roles.some(r => r.id && r.id === role.id))
|
|
return;
|
|
this.roles.push(role);
|
|
}
|
|
removeRole(roleId) {
|
|
const idx = this.roles.findIndex(r => r.id === roleId);
|
|
if (idx === -1)
|
|
return;
|
|
this.roles.splice(idx, 1);
|
|
}
|
|
assignPermission(permission) {
|
|
if (this.permissions.some(p => p.id && p.id === permission.id))
|
|
return;
|
|
this.permissions.push(permission);
|
|
}
|
|
removePermission(permissionId) {
|
|
const idx = this.permissions.findIndex(p => p.id === permissionId);
|
|
if (idx === -1)
|
|
return;
|
|
this.permissions.splice(idx, 1);
|
|
}
|
|
changeEmail(email) {
|
|
this.email = email;
|
|
}
|
|
changeUsername(username) {
|
|
this.username = username;
|
|
}
|
|
touchLastSeen() {
|
|
this.lastSeenAt = new Date();
|
|
}
|
|
setStorageQuota(q) {
|
|
this.storageQuota = q;
|
|
}
|
|
setStorageUsed(u) {
|
|
this.storageUsed = u;
|
|
}
|
|
}
|
|
exports.UserData = UserData;
|
|
//# sourceMappingURL=user.entity.js.map
|