Skip to content

Commit 3128b56

Browse files
committed
add join
1 parent 5b3deec commit 3128b56

File tree

6 files changed

+13
-2
lines changed

6 files changed

+13
-2
lines changed

server/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
generator client {
33
provider = "prisma-client-js"
44
binaryTargets = ["native", "debian-openssl-3.0.x"]
5-
previewFeatures = ["typedSql"]
5+
previewFeatures = ["typedSql","relationJoins"]
66
}
77

88
datasource db {

server/src/database/courses.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { prisma } from "./client";
55
export async function getCourseByCourseId(courseId: string): Promise<Course> {
66
return (
77
(await prisma.course.findUnique({
8+
relationLoadStrategy: "join",
89
where: {
910
id: courseId,
1011
},
@@ -20,6 +21,7 @@ export async function getCourseByCourseId(courseId: string): Promise<Course> {
2021
*/
2122
export async function getCoursesByUserId(userId: UserID): Promise<Course[]> {
2223
return await prisma.course.findMany({
24+
relationLoadStrategy: "join",
2325
where: {
2426
enrollments: {
2527
some: {
@@ -43,6 +45,7 @@ export async function getCourseByDayPeriodAndUserId(
4345
): Promise<Course | null> {
4446
// TODO: findUnique で取れるような制約を掛ける
4547
return await prisma.course.findFirst({
48+
relationLoadStrategy: "join",
4649
where: {
4750
enrollments: {
4851
some: {
@@ -70,6 +73,7 @@ export async function getCoursesByDayAndPeriod(
7073
period: number,
7174
): Promise<Course[]> {
7275
return await prisma.course.findMany({
76+
relationLoadStrategy: "join",
7377
where: {
7478
slots: {
7579
some: {

server/src/database/requests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export async function getPendingRequestsToUser(
103103
userId: UserID,
104104
): Promise<UserWithCoursesAndSubjects[]> {
105105
const found = await prisma.user.findMany({
106+
relationLoadStrategy: "join",
106107
where: {
107108
sendingUsers: {
108109
some: {
@@ -146,6 +147,7 @@ export async function getPendingRequestsFromUser(
146147
userId: UserID,
147148
): Promise<UserWithCoursesAndSubjects[]> {
148149
const found = await prisma.user.findMany({
150+
relationLoadStrategy: "join",
149151
where: {
150152
receivingUsers: {
151153
some: {
@@ -190,6 +192,7 @@ export async function getMatchedUser(
190192
userId: UserID,
191193
): Promise<UserWithCoursesAndSubjects[]> {
192194
const found = await prisma.user.findMany({
195+
relationLoadStrategy: "join",
193196
where: {
194197
OR: [
195198
{

server/src/database/users.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function createUser(partialUser: Omit<User, "id">): Promise<User> {
2323
// ユーザーの取得
2424
export async function getUser(guid: GUID): Promise<UserWithCoursesAndSubjects> {
2525
const user = await prisma.user.findUnique({
26+
relationLoadStrategy: "join",
2627
where: {
2728
guid: guid,
2829
},
@@ -75,6 +76,7 @@ export async function getUserByID(
7576
id: UserID,
7677
): Promise<UserWithCoursesAndSubjects> {
7778
const user = await prisma.user.findUnique({
79+
relationLoadStrategy: "join",
7880
where: {
7981
id,
8082
},
@@ -140,6 +142,7 @@ export async function getAllUsers(): Promise<
140142
(User & { courses: Course[]; interestSubjects: InterestSubject[] })[]
141143
> {
142144
const users = await prisma.user.findMany({
145+
relationLoadStrategy: "join",
143146
include: {
144147
enrollments: {
145148
include: {

server/src/firebase/auth/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type DecodedIdToken = admin.DecodedIdToken;
1111
// THROWS: if idToken is not present in request cookie, or when the token is not valid.
1212
export async function getGUID(c: Context): Promise<GUID> {
1313
const idToken = c.req.header("Authorization");
14-
if (typeof idToken !== "string") error("token not found in query", 401);
14+
if (typeof idToken !== "string") error("token not found in header", 401);
1515
return await getGUIDFromToken(idToken);
1616
}
1717

server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if (corsOptions.origin.length > 1) {
3131
const app = new Hono()
3232
.onError((err, c) => {
3333
if (err instanceof HTTPException) {
34+
console.error(err);
3435
c.status(err.status);
3536
return c.json({ error: err });
3637
}

0 commit comments

Comments
 (0)