49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { prisma } from "@/lib/prisma";
|
|
import type { ApplicationType } from "./types";
|
|
|
|
type CreateData = {
|
|
surname: string;
|
|
givenNames: string;
|
|
sex: "MALE" | "FEMALE";
|
|
birthDate: Date;
|
|
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;
|
|
};
|
|
|
|
export async function createApplication(userId: string, data: CreateData) {
|
|
return prisma.citizenshipApplication.create({
|
|
data: {
|
|
userId,
|
|
...data,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getUserApplications(userId: string) {
|
|
return prisma.citizenshipApplication.findMany({
|
|
where: { userId },
|
|
orderBy: { createdAt: "asc" },
|
|
});
|
|
}
|
|
|
|
export async function getPendingApplications() {
|
|
return prisma.citizenshipApplication.findMany({
|
|
where: { status: "PENDING" },
|
|
orderBy: { createdAt: "desc" },
|
|
include: { user: true },
|
|
})
|
|
}
|
|
|
|
export async function getPendingApplicationsCount(): Promise<number> {
|
|
return prisma.citizenshipApplication.count({ where: { status: "PENDING" } })
|
|
} |