Skip to content

Commit

Permalink
feat: add key feature and use bun instead of package.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunyawat Naunnak committed Aug 13, 2024
1 parent bb467be commit d6171e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/app/users/shipping/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Home = async ({ params }: { params: { id: string } }) => {
: (student_id as Student);
const mockParcels: Parcel[] = await api.parcel.getRemain({
student_id: student?.student_id ?? STUDENT_ID,
project_id: params.id,
});

return (
Expand Down
30 changes: 21 additions & 9 deletions src/server/api/routers/parcel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export const parcelRouter = createTRPCRouter({
.input(
z.object({
student_id: z.string(),
project_id: z.string(),
}),
)
.query(async ({ ctx, input }) => {
const studentId = input.student_id; // Assuming you have the student's ID in the session.
const { student_id: studentId, project_id: projectId } = input;

// Check if the student is in the project with ID `0000000000`.
const isStudentInProject = await ctx.db.project_Student.findFirst({
Expand All @@ -53,15 +54,26 @@ export const parcelRouter = createTRPCRouter({
},
});

// Check if the student is an admin.
const isAdmin = await ctx.db.student.findFirst({
where: {
student_id: studentId,
isAdmin: true,
},
});

return await ctx.db.parcel.findMany({
where: isStudentInProject
? { available: true, type: "KEY" }
: {
available: true,
NOT: {
type: "KEY",
},
},
where:
isStudentInProject ?? isAdmin
? { available: true, type: "KEY" }
: projectId === "0000000000"
? { available: true, type: "KEY" }
: {
available: true,
NOT: {
type: "KEY",
},
},
});
}),

Expand Down

0 comments on commit d6171e0

Please sign in to comment.