Supernova
Supernova
Explore posts from servers
PPrisma
Created by Supernova on 3/4/2025 in #help-and-questions
help contructing a filter query
here's the related schemas
model User {
id Int @id @default(autoincrement())
email String @unique
password String
role Role
profile_completed Boolean @default(false)

teacher Teacher?
student Student?
subjects Subject[]
languages Language[]
educations Education[]

@@map("users")
}
model Language {
id Int @id @default(autoincrement())
name String
users User[]

@@map("languages")
}

model Education {
id Int @id @default(autoincrement())
name String
users User[]

@@map("education_levels")
}

model Subject {
id Int @id @default(autoincrement())
name String

users User[]

@@map("subjects")
}
model User {
id Int @id @default(autoincrement())
email String @unique
password String
role Role
profile_completed Boolean @default(false)

teacher Teacher?
student Student?
subjects Subject[]
languages Language[]
educations Education[]

@@map("users")
}
model Language {
id Int @id @default(autoincrement())
name String
users User[]

@@map("languages")
}

model Education {
id Int @id @default(autoincrement())
name String
users User[]

@@map("education_levels")
}

model Subject {
id Int @id @default(autoincrement())
name String

users User[]

@@map("subjects")
}
6 replies
PPrisma
Created by Supernova on 3/4/2025 in #help-and-questions
help contructing a filter query
No description
6 replies
PPrisma
Created by Supernova on 3/4/2025 in #help-and-questions
help contructing a filter query
here's my server action for now:
export async function getTeachersSubjects(
subject: string,
page: number,
queries: {
subject?: string | string[];
language?: string | string[];
studentLevel?: string | string[];
educationLevel?: string | string[];
},
): Promise<Teacher[]> {
const teachers = await prisma.user.findMany({
where: {
role: Role.TEACHER,
subjects: {
some: { name: subject },
},
},
select: {
teacher: true,
educations: true,
languages: true,
subjects: true,
},
take: PERPAGE,
skip: (page - 1) * PERPAGE,
});


return JSON.parse(
JSON.stringify(
teachers.map((user) => ({
...toCamelCase(user.teacher),
educations: user.educations,
languages: user.languages,
subjects: user.subjects,
})),
),
);
}
export async function getTeachersSubjects(
subject: string,
page: number,
queries: {
subject?: string | string[];
language?: string | string[];
studentLevel?: string | string[];
educationLevel?: string | string[];
},
): Promise<Teacher[]> {
const teachers = await prisma.user.findMany({
where: {
role: Role.TEACHER,
subjects: {
some: { name: subject },
},
},
select: {
teacher: true,
educations: true,
languages: true,
subjects: true,
},
take: PERPAGE,
skip: (page - 1) * PERPAGE,
});


return JSON.parse(
JSON.stringify(
teachers.map((user) => ({
...toCamelCase(user.teacher),
educations: user.educations,
languages: user.languages,
subjects: user.subjects,
})),
),
);
}
6 replies
DTDrizzle Team
Created by kajl_pl on 7/25/2024 in #help
Internal error: TypeError: Cannot read properties of undefined (reading 'referencedTable')`
m curious to see your project
3 replies