barsa 1b944f57aa Update Configuration Files and Refactor Code Structure
- Adjusted .prettierrc to ensure consistent formatting with a newline at the end of the file.
- Reformatted eslint.config.mjs for improved readability by aligning array elements.
- Updated pnpm-lock.yaml to use single quotes for consistency across dependencies.
- Simplified worktree setup in .cursor/worktrees.json for cleaner configuration.
- Enhanced documentation in .cursor/plans to clarify architecture refactoring.
- Refactored various service files for improved readability and maintainability, including rate-limiting and auth services.
- Updated imports and exports across multiple files for consistency and clarity.
- Improved error handling and logging in service methods to enhance debugging capabilities.
- Streamlined utility functions for better performance and maintainability across the domain packages.
2025-12-25 17:30:02 +09:00

31 lines
877 B
TypeScript

/**
* Portal Provider - Mapper
*
* Maps Prisma user data to UserAuth domain type using schema validation
*/
import { userAuthSchema } from "../../schema.js";
import type { PrismaUserRaw } from "./types.js";
import type { UserAuth } from "../../schema.js";
/**
* 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(),
});
}