feat: images upload
This commit is contained in:
+31
-27
@@ -1,4 +1,6 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import type { EyeColor } from "@/lib/citizenship/types";
|
||||
import { getImageUrl } from "../image";
|
||||
|
||||
export type IdentityCardData = {
|
||||
documentNumber: string;
|
||||
@@ -9,27 +11,29 @@ export type IdentityCardData = {
|
||||
sex: "M" | "F";
|
||||
birthDate: Date;
|
||||
address: string;
|
||||
height: string;
|
||||
eyeColor: string;
|
||||
height: number;
|
||||
eyeColor: EyeColor;
|
||||
issueDate: Date;
|
||||
expiryDate: Date;
|
||||
authority: string;
|
||||
origin: string | null;
|
||||
profileUrl: string;
|
||||
signatureUrl: string;
|
||||
};
|
||||
|
||||
export async function getIdentityCardData(userId: string): Promise<IdentityCardData | null> {
|
||||
const doc = await prisma.identityDocument.findFirst({
|
||||
const document = await prisma.identityDocument.findFirst({
|
||||
where: {
|
||||
citizenship: { userId },
|
||||
citizenship: {
|
||||
userId,
|
||||
revokedAt: null,
|
||||
},
|
||||
},
|
||||
orderBy: { issuedAt: "desc" },
|
||||
select: {
|
||||
documentNumber: true,
|
||||
address: true,
|
||||
issuedAt: true,
|
||||
expiresAt: true,
|
||||
regionId: true,
|
||||
city: true,
|
||||
street: true,
|
||||
customAddress: true,
|
||||
region: {
|
||||
select: { name: true },
|
||||
},
|
||||
@@ -41,9 +45,10 @@ export async function getIdentityCardData(userId: string): Promise<IdentityCardD
|
||||
givenNames: true,
|
||||
sex: true,
|
||||
birthDate: true,
|
||||
address: true,
|
||||
height: true,
|
||||
eyeColor: true,
|
||||
profileKey: true,
|
||||
signatureKey: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -51,26 +56,25 @@ export async function getIdentityCardData(userId: string): Promise<IdentityCardD
|
||||
},
|
||||
});
|
||||
|
||||
if (!doc) return null;
|
||||
if (!document) return null;
|
||||
|
||||
const app = doc.citizenship.application;
|
||||
const application = document.citizenship.application;
|
||||
|
||||
return {
|
||||
documentNumber: doc.documentNumber,
|
||||
documentNumber: document.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,
|
||||
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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user