690327:0024 Fixing Refactor ADR-019 Naming convention uuid #11
This commit is contained in:
@@ -17,7 +17,7 @@ import { Organization } from '../../organization/entities/organization.entity';
|
||||
import { UserAssignment } from './user-assignment.entity';
|
||||
import { UserPreference } from './user-preference.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { Exclude, Expose } from 'class-transformer';
|
||||
|
||||
@Entity('users')
|
||||
export class User extends UuidBaseEntity {
|
||||
@@ -57,12 +57,19 @@ export class User extends UuidBaseEntity {
|
||||
|
||||
// Relation กับ Organization (สังกัดหลัก)
|
||||
@Column({ name: 'primary_organization_id', nullable: true })
|
||||
@Exclude() // INT ID - never expose, use primaryOrganizationPublicId instead (ADR-019)
|
||||
primaryOrganizationId?: number;
|
||||
|
||||
@ManyToOne(() => Organization, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'primary_organization_id' })
|
||||
organization?: Organization;
|
||||
|
||||
// ADR-019: Expose UUID instead of INT ID
|
||||
@Expose({ name: 'primaryOrganizationId' })
|
||||
get primaryOrganizationPublicId(): string | undefined {
|
||||
return this.organization?.publicId;
|
||||
}
|
||||
|
||||
// Relation กับ Assignments (RBAC)
|
||||
@OneToMany(() => UserAssignment, (assignment) => assignment.user)
|
||||
assignments?: UserAssignment[];
|
||||
|
||||
@@ -84,6 +84,7 @@ export class UserService {
|
||||
.leftJoinAndSelect('user.preference', 'preference') // Optional
|
||||
.leftJoinAndSelect('user.assignments', 'assignments')
|
||||
.leftJoinAndSelect('assignments.role', 'role')
|
||||
.leftJoinAndSelect('user.organization', 'organization') // [FIX] Required for primaryOrganizationPublicId getter (ADR-019)
|
||||
.select([
|
||||
'user.user_id',
|
||||
'user.publicId',
|
||||
@@ -92,13 +93,13 @@ export class UserService {
|
||||
'user.firstName',
|
||||
'user.lastName',
|
||||
'user.lineId',
|
||||
'user.primaryOrganizationId',
|
||||
'user.isActive',
|
||||
'user.createdAt',
|
||||
'user.updatedAt',
|
||||
'assignments.id',
|
||||
'role.roleId',
|
||||
'role.roleName',
|
||||
'organization.publicId', // [FIX] Expose org UUID for getter (ADR-019)
|
||||
]);
|
||||
|
||||
// Apply Filters
|
||||
@@ -146,6 +147,7 @@ export class UserService {
|
||||
'assignments',
|
||||
'assignments.role',
|
||||
'assignments.role.permissions', // [FIX] Required for RBAC AbilityFactory
|
||||
'organization', // [FIX] Required for primaryOrganizationPublicId getter (ADR-019)
|
||||
],
|
||||
});
|
||||
|
||||
@@ -164,6 +166,7 @@ export class UserService {
|
||||
'assignments',
|
||||
'assignments.role',
|
||||
'assignments.role.permissions',
|
||||
'organization', // [FIX] Required for primaryOrganizationPublicId getter (ADR-019)
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user