import { prisma } from "@/lib/prisma"; import type { EyeColor } from "@/lib/citizenship/types"; import { getImageUrl } from "../image"; export type IdentityCardData = { documentNumber: string; issuingCountry: "EUR"; nationality: "EUR"; surname: string; givenNames: string; sex: "M" | "F"; birthDate: Date; address: string; height: number; eyeColor: EyeColor; issueDate: Date; expiryDate: Date; authority: string; profileUrl: string; signatureUrl: string; }; export async function getIdentityCardData(userId: string): Promise { const document = await prisma.identityDocument.findFirst({ where: { citizenship: { userId, revokedAt: null, }, }, orderBy: { issuedAt: "desc" }, select: { documentNumber: true, address: true, issuedAt: true, expiresAt: true, region: { select: { name: true }, }, citizenship: { select: { application: { select: { surname: true, givenNames: true, sex: true, birthDate: true, height: true, eyeColor: true, profileKey: true, signatureKey: true, }, }, }, }, }, }); if (!document) return null; const application = document.citizenship.application; return { documentNumber: document.documentNumber, issuingCountry: "EUR", nationality: "EUR", surname: application.surname, givenNames: application.givenNames, sex: application.sex === "MALE" ? "M" : "F", birthDate: application.birthDate, address: document.address, height: application.height, eyeColor: application.eyeColor as EyeColor, issueDate: document.issuedAt, expiryDate: document.expiresAt, authority: document.region?.name ?? "European Federation", profileUrl: await getImageUrl(application.profileKey), signatureUrl: await getImageUrl(application.signatureKey), }; }