Uecko_ERP/apps/server/src/contexts/auth/domain/entities/tab-context.ts

63 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-02-04 14:58:33 +00:00
import { DomainEntity, Result, UniqueID } from "@common/domain";
export interface ITabContextProps {
tabId: UniqueID;
userId: UniqueID;
2025-02-04 18:25:10 +00:00
companyId: UniqueID;
branchId: UniqueID;
2025-02-04 14:58:33 +00:00
}
export interface ITabContext {
tabId: UniqueID;
userId: UniqueID;
2025-02-04 18:25:10 +00:00
companyId: UniqueID;
branchId: UniqueID;
2025-02-04 14:58:33 +00:00
2025-02-04 18:25:10 +00:00
hasCompanyAssigned(): boolean;
hasBranchAssigned(): boolean;
2025-02-04 14:58:33 +00:00
toPersistenceData(): any;
}
export class TabContext extends DomainEntity<ITabContextProps> implements ITabContext {
static create(props: ITabContextProps, id?: UniqueID): Result<TabContext, Error> {
return Result.ok(new this(props, id));
}
get tabId(): UniqueID {
return this._props.tabId;
}
get userId(): UniqueID {
return this._props.userId;
}
2025-02-04 18:25:10 +00:00
get companyId(): UniqueID {
return this._props.companyId;
2025-02-04 14:58:33 +00:00
}
2025-02-04 18:25:10 +00:00
get branchId(): UniqueID {
return this._props.branchId;
2025-02-04 14:58:33 +00:00
}
hasCompanyAssigned(): boolean {
2025-02-04 18:25:10 +00:00
return this._props.companyId.isDefined();
2025-02-04 14:58:33 +00:00
}
hasBranchAssigned(): boolean {
2025-02-04 18:25:10 +00:00
return this._props.branchId.isDefined();
2025-02-04 14:58:33 +00:00
}
/**
* 🔹 Devuelve una representación lista para persistencia
*/
toPersistenceData(): any {
return {
id: this._id.toString(),
user_id: this.userId.toString(),
2025-02-04 18:25:10 +00:00
company_id: this.companyId.toString(),
branchId: this.branchId.toString(),
2025-02-04 14:58:33 +00:00
};
}
}