feat: citizenship built
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user