diff --git a/app/[locale]/academics/curricula/page.tsx b/app/[locale]/academics/curricula/page.tsx
index 6fc2805c..156fbb52 100644
--- a/app/[locale]/academics/curricula/page.tsx
+++ b/app/[locale]/academics/curricula/page.tsx
@@ -27,9 +27,12 @@ export default async function Curricula({
}) {
const text = (await getTranslations(locale)).Curricula;
- const page = isNaN(Number(searchParams.page ?? '1'))
- ? 1
- : Math.max(Number(searchParams.page ?? '1'), 1);
+ const page = Number(searchParams.page?? '1')
+ // console.log(page);
+
+ const pagesCount = await db.select({count:count()}).from(courses);
+ const totalPages = Math.ceil(pagesCount[0].count/10);
+ // console.log(totalPages);
return (
<>
@@ -64,7 +67,7 @@ export default async function Curricula({
>
@@ -72,21 +75,43 @@ export default async function Curricula({
}
const Courses = async ({ page }: { page: number }) => {
- const courses = await db.query.courses.findMany({
- columns: { code: true, title: true },
- with: {
- coursesToMajors: {
- columns: {
- lectureCredits: true,
- practicalCredits: true,
- tutorialCredits: true,
- },
- with: { major: { columns: { name: true } } },
- },
- },
- limit: 10,
- offset: (page - 1) * 10,
- });
+ // fetch call for original db
+ // const courses = await db.query.courses.findMany({
+ // columns: { code: true, title: true },
+ // with: {
+ // coursesToMajors: {
+ // columns: {
+ // lectureCredits: true,
+ // practicalCredits: true,
+ // tutorialCredits: true,
+ // },
+ // with: { major: { columns: { name: true } } },
+ // },
+ // },
+ // limit: 10,
+ // offset: (page - 1) * 10,
+ // });
+
+ // just for my setup db -- To be reversed later
+ interface Course {
+ code: string;
+ title: string;
+ coursesToMajors: {
+ lectureCredits: number;
+ practicalCredits: number;
+ tutorialCredits: number;
+ major: {
+ name: string;
+ };
+ }[];
+ }
+
+ // call for my setup db
+ const courses: Course[] = await db.query.courses.findMany({
+ limit:10,
+ offset:(page-1)*10,
+ })
+
return courses.map(({ code, coursesToMajors, title }) =>
coursesToMajors.map(
diff --git a/app/[locale]/institute/administration/(committees)/committee.tsx b/app/[locale]/institute/administration/(committees)/committee.tsx
index 62f846a4..4f55ac8d 100644
--- a/app/[locale]/institute/administration/(committees)/committee.tsx
+++ b/app/[locale]/institute/administration/(committees)/committee.tsx
@@ -34,6 +34,9 @@ export default async function Committee({
? 1
: Math.max(Number(searchParams.meetingPage ?? '1'), 1);
+ const pagesCount = await db.select({count:count()}).from(committeeMeetings).where(sql`committee_type = ${type}`);
+ const totalPages = Math.ceil(pagesCount[0].count/10);
+
return (
{type !== 'senate' && (
@@ -83,10 +86,7 @@ export default async function Committee({
);
diff --git a/components/pagination/pagination.tsx b/components/pagination/pagination.tsx
index 55bfe0f6..8b73a0cd 100644
--- a/components/pagination/pagination.tsx
+++ b/components/pagination/pagination.tsx
@@ -13,47 +13,44 @@ import {
export const PaginationWithLogic = async ({
className,
currentPage,
- query,
- ...props
+ totalPages,
}: React.ComponentProps<'nav'> & {
currentPage: number;
- query: Promise<{ count: number }[]>;
+ totalPages : number;
}) => {
- const rows = await query;
- const noOfPages = Math.ceil(Number(rows[0].count) / 10);
return (
-
+
1
- {noOfPages > 1 && (currentPage < 4 || noOfPages < 6) && (
+ {totalPages > 1 && (currentPage < 4 || totalPages < 6) && (
2
)}
- {noOfPages > 2 && (currentPage < 4 || noOfPages < 6) && (
+ {totalPages > 2 && (currentPage < 4 || totalPages < 6) && (
3
@@ -61,12 +58,12 @@ export const PaginationWithLogic = async ({
)}
- {noOfPages > 5 && }
- {currentPage > 3 && currentPage < noOfPages - 2 && (
+ {totalPages > 5 && }
+ {currentPage > 3 && currentPage < totalPages - 2 && (
<>
{currentPage}
@@ -76,41 +73,41 @@ export const PaginationWithLogic = async ({
>
)}
- {noOfPages > 5 && currentPage > noOfPages - 3 && (
+ {totalPages > 5 && currentPage > totalPages - 3 && (
- {noOfPages - 2}
+ {totalPages - 2}
)}
- {noOfPages > 4 && (currentPage > noOfPages - 3 || noOfPages < 6) && (
+ {totalPages > 4 && (currentPage > totalPages - 3 || totalPages < 6) && (
- {noOfPages - 1}
+ {totalPages - 1}
)}
- {noOfPages > 3 && (
+ {totalPages > 3 && (
- {noOfPages}
+ {totalPages}
)}
= noOfPages}
- href={{ query: { meetingPage: currentPage + 1 } }}
+ disabled={currentPage >= totalPages}
+ href={{ query: { page: currentPage + 1 } }}
/>
diff --git a/server/db/schema/courses.schema.ts b/server/db/schema/courses.schema.ts
index b9ef5cba..35322f47 100644
--- a/server/db/schema/courses.schema.ts
+++ b/server/db/schema/courses.schema.ts
@@ -1,63 +1,86 @@
-import { relations, sql } from 'drizzle-orm';
+// import { relations, sql } from 'drizzle-orm';
+// correct all these commented codes after the review
import {
- char,
- integer,
+ // char,
+ // integer,
pgTable,
- smallint,
- smallserial,
- text,
+ // smallint,
+ // smallserial,
+ // text,
varchar,
+ serial,
+ jsonb
} from 'drizzle-orm/pg-core';
-import { courseLogs, coursesToMajors, departments, faculty } from '.';
+// import { courseLogs, coursesToMajors, departments, faculty } from '.';
-export const courses = pgTable('courses', {
- id: smallserial('id').primaryKey(),
- code: varchar('code', { length: 7 }).unique().notNull(),
- title: varchar('title', { length: 128 }).notNull(),
- coordinatorId: integer('coordinator_id')
- .references(() => faculty.id)
- .notNull(),
- departmentId: smallint('department_id')
- .references(() => departments.id)
- .notNull(),
- prerequisites: varchar('prerequisites', { length: 7 })
- .array()
- .default(sql`'{}'`)
- .notNull(),
- nature: char('nature', { length: 3 }).notNull(),
- objectives: text('objectives')
- .array()
- .default(sql`'{}'`)
- .notNull(),
- content: text('content').notNull(),
- outcomes: text('outcomes')
- .array()
- .default(sql`'{}'`)
- .notNull(),
- essentialReading: text('essential_reading')
- .array()
- .default(sql`'{}'`)
- .notNull(),
- supplementaryReading: text('supplementary_reading')
- .array()
- .default(sql`'{}'`)
- .notNull(),
- similarCourses: varchar('similar_courses', { length: 7 })
- .array()
- .default(sql`'{}'`)
- .notNull(),
+// Define the Courses table with embedded coursesToMajors array
+export const courses = pgTable("courses", {
+ id: serial("id").primaryKey(),
+ code: varchar("code", { length: 255 }).notNull().unique(),
+ title: varchar("title", { length: 255 }).notNull(),
+ coursesToMajors: jsonb("courses_to_majors")
+ .notNull()
+ .$type<{
+ courseId: number;
+ majorId: number;
+ semester: number;
+ lectureCredits: number;
+ tutorialCredits: number;
+ practicalCredits: number;
+ major: { id: number; name: string };
+ }[]>(), // Storing as an array of JSON
});
-export const coursesRelations = relations(courses, ({ many, one }) => ({
- coordinator: one(faculty, {
- fields: [courses.coordinatorId],
- references: [faculty.id],
- }),
- courseLogs: many(courseLogs),
- coursesToMajors: many(coursesToMajors),
- department: one(departments, {
- fields: [courses.departmentId],
- references: [departments.id],
- }),
-}));
+// Will use this old schema and relations after review
+
+// export const courses = pgTable('courses', {
+// id: smallserial('id').primaryKey(),
+// code: varchar('code', { length: 7 }).unique().notNull(),
+// title: varchar('title', { length: 128 }).notNull(),
+// coordinatorId: integer('coordinator_id')
+// .references(() => faculty.id)
+// .notNull(),
+// departmentId: smallint('department_id')
+// .references(() => departments.id)
+// .notNull(),
+// prerequisites: varchar('prerequisites', { length: 7 })
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// nature: char('nature', { length: 3 }).notNull(),
+// objectives: text('objectives')
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// content: text('content').notNull(),
+// outcomes: text('outcomes')
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// essentialReading: text('essential_reading')
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// supplementaryReading: text('supplementary_reading')
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// similarCourses: varchar('similar_courses', { length: 7 })
+// .array()
+// .default(sql`'{}'`)
+// .notNull(),
+// });
+
+// export const coursesRelations = relations(courses, ({ many, one }) => ({
+// coordinator: one(faculty, {
+// fields: [courses.coordinatorId],
+// references: [faculty.id],
+// }),
+// courseLogs: many(courseLogs),
+// coursesToMajors: many(coursesToMajors),
+// department: one(departments, {
+// fields: [courses.departmentId],
+// references: [departments.id],
+// }),
+// }));