feat: citizenship built

This commit is contained in:
Ivan Rezchikov
2026-07-03 15:03:35 +03:00
parent c60ab9e8f9
commit 2eb0de5357
46 changed files with 1150 additions and 257 deletions
+76
View File
@@ -0,0 +1,76 @@
import { prisma } from "@/lib/prisma";
export type IdentityCardData = {
documentNumber: string;
issuingCountry: "EUR";
nationality: "EUR";
surname: string;
givenNames: string;
sex: "M" | "F";
birthDate: Date;
address: string;
height: string;
eyeColor: string;
issueDate: Date;
expiryDate: Date;
authority: string;
origin: string | null;
};
export async function getIdentityCardData(userId: string): Promise<IdentityCardData | null> {
const doc = await prisma.identityDocument.findFirst({
where: {
citizenship: { userId },
},
select: {
documentNumber: true,
issuedAt: true,
expiresAt: true,
regionId: true,
city: true,
street: true,
customAddress: true,
region: {
select: { name: true },
},
citizenship: {
select: {
application: {
select: {
surname: true,
givenNames: true,
sex: true,
birthDate: true,
address: true,
height: true,
eyeColor: true,
},
},
},
},
},
});
if (!doc) return null;
const app = doc.citizenship.application;
return {
documentNumber: doc.documentNumber,
issuingCountry: "EUR",
nationality: "EUR",
surname: app.surname,
givenNames: app.givenNames,
sex: app.sex === "MALE" ? "M" : "F",
birthDate: app.birthDate,
address: app.address,
height: app.height,
eyeColor: app.eyeColor,
issueDate: doc.issuedAt,
expiryDate: doc.expiresAt,
authority: doc.region?.name ?? "European Federation",
origin: doc.regionId && doc.city
? `${doc.city}, ${doc.regionId}, EU`
: doc.customAddress ?? null,
};
}