32 lines
872 B
TypeScript

/**
* Portal Provider - Mapper
*
* Maps Prisma user data to UserAuth domain type using schema validation
*/
import { userAuthSchema } from "../../schema";
import type { PrismaUserRaw } from "./types";
import type { UserAuth } from "../../schema";
/**
* Maps raw Prisma user data to UserAuth domain type
*
* Uses schema validation for runtime type safety
*
* @param raw - Raw Prisma user data from portal database
* @returns Validated UserAuth with only authentication state
*/
export function mapPrismaUserToUserAuth(raw: PrismaUserRaw): UserAuth {
return userAuthSchema.parse({
id: raw.id,
email: raw.email,
role: raw.role,
mfaEnabled: !!raw.mfaSecret,
emailVerified: raw.emailVerified,
lastLoginAt: raw.lastLoginAt?.toISOString(),
createdAt: raw.createdAt.toISOString(),
updatedAt: raw.updatedAt.toISOString(),
});
}