mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
The custom generator output to src/generated/prisma caused persistent Turbopack module resolution failures in CI. Switch to the standard @prisma/client import path which all bundlers resolve correctly. - Remove custom output from prisma schema generator - Update all imports from ../generated/prisma to @prisma/client - Add postinstall script to auto-run prisma generate after npm ci - Remove generated files from git (no longer needed in source tree) - Simplify CI workflow (remove verify step and --webpack workaround) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { prisma } from "@/lib/prisma";
|
|
import { Prisma } from "@prisma/client";
|
|
import type { DataTableSearchParams } from "@/types/table.types";
|
|
|
|
export async function getLocations(userId: string, params: DataTableSearchParams) {
|
|
const page = Number(params.page) || 1;
|
|
const perPage = Number(params.perPage) || 20;
|
|
const skip = (page - 1) * perPage;
|
|
|
|
const where: Prisma.LocationWhereInput = {
|
|
userId,
|
|
archived: params.archived === "true" ? undefined : false,
|
|
...(params.search && {
|
|
OR: [
|
|
{ name: { contains: params.search, mode: "insensitive" as Prisma.QueryMode } },
|
|
{ description: { contains: params.search, mode: "insensitive" as Prisma.QueryMode } },
|
|
],
|
|
}),
|
|
};
|
|
|
|
const sortField = params.sort || "createdAt";
|
|
const sortOrder = params.order || "desc";
|
|
|
|
const [data, totalCount] = await Promise.all([
|
|
prisma.location.findMany({
|
|
where,
|
|
orderBy: { [sortField]: sortOrder },
|
|
skip,
|
|
take: perPage,
|
|
include: {
|
|
_count: { select: { filaments: true, resins: true, paints: true } },
|
|
},
|
|
}),
|
|
prisma.location.count({ where }),
|
|
]);
|
|
|
|
return {
|
|
data,
|
|
pageCount: Math.ceil(totalCount / perPage),
|
|
totalCount,
|
|
};
|
|
}
|
|
|
|
export async function getLocationById(id: string, userId: string) {
|
|
return prisma.location.findFirst({
|
|
where: { id, userId },
|
|
include: {
|
|
_count: { select: { filaments: true, resins: true, paints: true } },
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getLocationOptions(userId: string) {
|
|
return prisma.location.findMany({
|
|
where: { userId, archived: false },
|
|
select: { id: true, name: true },
|
|
orderBy: { name: "asc" },
|
|
});
|
|
}
|