45 lines
1.5 KiB
TypeScript

/**
* User DB Mapper
*
* Adapts @prisma/client User to domain UserAuth type
*
* NOTE: This is an infrastructure adapter - Prisma is BFF's ORM implementation detail.
* The domain provider handles the actual mapping logic.
*/
import type { User as PrismaUser } from "@prisma/client";
import type { UserAuth } from "@customer-portal/domain/customer";
import { Providers as CustomerProviders } from "@customer-portal/domain/customer";
type PrismaUserRaw = Parameters<typeof CustomerProviders.Portal.mapPrismaUserToUserAuth>[0];
/**
* Maps Prisma User entity to Domain UserAuth type
*
* This adapter converts the @prisma/client User to the domain's PrismaUserRaw type,
* then uses the domain portal provider mapper to get UserAuth.
*
* NOTE: UserAuth contains ONLY auth state. Profile data comes from WHMCS.
* For complete user profile, use UsersService.getProfile() which fetches from WHMCS.
*/
export function mapPrismaUserToDomain(user: PrismaUser): UserAuth {
// Convert @prisma/client User to domain PrismaUserRaw
const prismaUserRaw: PrismaUserRaw = {
id: user.id,
email: user.email,
passwordHash: user.passwordHash,
role: user.role,
mfaSecret: user.mfaSecret,
emailVerified: user.emailVerified,
failedLoginAttempts: user.failedLoginAttempts,
lockedUntil: user.lockedUntil,
lastLoginAt: user.lastLoginAt,
createdAt: user.createdAt,
updatedAt: user.updatedAt,
};
// Use domain provider mapper
return CustomerProviders.Portal.mapPrismaUserToUserAuth(prismaUserRaw);
}