fase(9): auth module with casl rbac and session management
This commit is contained in:
42
dist/modules/auth/domain/entities/User.js
vendored
Normal file
42
dist/modules/auth/domain/entities/User.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.User = void 0;
|
||||
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
const UserCreated_1 = require("../events/UserCreated");
|
||||
class User extends AggregateRoot_1.AggregateRoot {
|
||||
static create(props, id) {
|
||||
const userId = id ?? UniqueId_1.UniqueId.create();
|
||||
const now = new Date();
|
||||
const user = new User({
|
||||
...props,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}, userId);
|
||||
user.addDomainEvent(new UserCreated_1.UserCreated(userId.toString(), {
|
||||
email: props.email.value,
|
||||
name: props.name,
|
||||
role: props.role.value,
|
||||
}));
|
||||
return user;
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new User(props, id);
|
||||
}
|
||||
get email() { return this.props.email; }
|
||||
get name() { return this.props.name; }
|
||||
get passwordHash() { return this.props.passwordHash; }
|
||||
get role() { return this.props.role; }
|
||||
get orgId() { return this.props.orgId; }
|
||||
get createdAt() { return this.props.createdAt; }
|
||||
get updatedAt() { return this.props.updatedAt; }
|
||||
assignToOrg(orgId) {
|
||||
this.props.orgId = orgId;
|
||||
this.props.updatedAt = new Date();
|
||||
}
|
||||
changeRole(role) {
|
||||
this.props.role = role;
|
||||
this.props.updatedAt = new Date();
|
||||
}
|
||||
}
|
||||
exports.User = User;
|
||||
Reference in New Issue
Block a user