feat: images upload
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import type { ApplicationType } from "./types";
|
||||
import type { ApplicationType, EyeColor } from "./types";
|
||||
|
||||
type CreateData = {
|
||||
surname: string;
|
||||
@@ -9,17 +9,58 @@ type CreateData = {
|
||||
applicationType: ApplicationType;
|
||||
previousCountry?: string | null;
|
||||
previousRegion?: string | null;
|
||||
birthRegion?: string | null;
|
||||
naturalizationReason?: string | null;
|
||||
address: string;
|
||||
regionId?: string | null;
|
||||
city?: string | null;
|
||||
street?: string | null;
|
||||
customAddress?: string | null;
|
||||
height: string;
|
||||
eyeColor: string;
|
||||
height: number;
|
||||
eyeColor: EyeColor;
|
||||
profileKey: string;
|
||||
signatureKey: string;
|
||||
};
|
||||
|
||||
export type ApplicationEligibility = {
|
||||
eligible: boolean;
|
||||
reason: string | null;
|
||||
};
|
||||
|
||||
export async function getApplicationEligibility(
|
||||
userId: string,
|
||||
birthDate: Date | null | undefined
|
||||
): Promise<ApplicationEligibility> {
|
||||
if (!birthDate) {
|
||||
return {
|
||||
eligible: false,
|
||||
reason:
|
||||
"Date of birth is required. Update your profile in Kotosoft ID and synchronise your account.",
|
||||
};
|
||||
}
|
||||
|
||||
const citizenship = await prisma.citizenship.findUnique({ where: { userId } });
|
||||
if (citizenship && !citizenship.revokedAt) {
|
||||
return {
|
||||
eligible: false,
|
||||
reason: "You are already a citizen of the European Federation.",
|
||||
};
|
||||
}
|
||||
|
||||
const applications = await prisma.citizenshipApplication.findMany({
|
||||
where: { userId },
|
||||
select: { status: true },
|
||||
});
|
||||
|
||||
if (applications.some((application) => application.status === "PENDING")) {
|
||||
return {
|
||||
eligible: false,
|
||||
reason: "You already have a pending application.",
|
||||
};
|
||||
}
|
||||
|
||||
return { eligible: true, reason: null };
|
||||
}
|
||||
|
||||
export async function createApplication(userId: string, data: CreateData) {
|
||||
return prisma.citizenshipApplication.create({
|
||||
data: {
|
||||
@@ -40,10 +81,26 @@ export async function getPendingApplications() {
|
||||
return prisma.citizenshipApplication.findMany({
|
||||
where: { status: "PENDING" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: { user: true },
|
||||
})
|
||||
include: {
|
||||
user: {
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
citizenships: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPendingApplicationsCount(): Promise<number> {
|
||||
return prisma.citizenshipApplication.count({ where: { status: "PENDING" } })
|
||||
}
|
||||
return prisma.citizenshipApplication.count({ where: { status: "PENDING" } });
|
||||
}
|
||||
|
||||
export async function getActiveCitizenship(userId: string) {
|
||||
const citizenship = await prisma.citizenship.findUnique({ where: { userId } });
|
||||
if (!citizenship || citizenship.revokedAt) return null;
|
||||
return citizenship;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user