Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions server/src/module/opensource/opensource.routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<<<<<<< HEAD
import { Router } from "express";
=======
import { Router } from "express";
import { prisma } from "../../database/db.js";
>>>>>>> upstream/main
Comment on lines +1 to +6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Unresolved merge conflict markers break compilation.

The file contains unresolved Git conflict markers. Additionally, the HEAD side has a BOM (Byte Order Mark) character () before the import statement which should be removed.

The prisma import from upstream/main is required for the /requests/mine route (line 57).

🔧 Proposed resolution
-<<<<<<< HEAD
-import { Router } from "express";
-=======
 import { Router } from "express";
 import { prisma } from "../../database/db.js";
->>>>>>> upstream/main
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<<<<<<< HEAD
import { Router } from "express";
=======
import { Router } from "express";
import { prisma } from "../../database/db.js";
>>>>>>> upstream/main
import { Router } from "express";
import { prisma } from "../../database/db.js";
🧰 Tools
🪛 Biome (2.4.16)

[error] 1-1: Expected a statement but instead found '<<<<<<< HEAD'.

(parse)


[error] 3-3: Expected a statement but instead found '======='.

(parse)


[error] 6-6: Expected a statement but instead found '>>>>>>> upstream/main'.

(parse)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/module/opensource/opensource.routes.ts` around lines 1 - 6, Remove
the unresolved Git conflict markers (<<<<<<<, =======, >>>>>>>) and the BOM
character before the first import, and restore the upstream import of prisma so
the route handler that queries the database (the /requests/mine route which uses
prisma) compiles; specifically, keep a single clean import block including:
import { Router } from "express" and import { prisma } from
"../../database/db.js", then verify the route handler referencing prisma (in the
/requests/mine handler) uses that imported prisma instance.

import { OpensourceController } from "./opensource.controller.js";
import { authMiddleware } from "../../middleware/auth.middleware.js";
import { requireRole } from "../../middleware/role.middleware.js";
Expand All @@ -21,6 +25,8 @@ opensourceRouter.get("/languages", (req, res, next) => controller.getLanguages(r
// Get GSoC organizations
opensourceRouter.get("/gsoc/orgs", (req, res, next) => controller.getGsocOrgs(req, res, next));

<<<<<<< HEAD
=======
// ─── Student Progress Tracking ─────────────────────────────────
// NOTE: must be before /:id to avoid route conflicts

Expand All @@ -39,6 +45,7 @@ opensourceRouter.patch(
);

// ─── Repo Requests (Student-authenticated) ─────────────────────
>>>>>>> upstream/main
Comment on lines 28 to +48
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Unresolved merge conflict in Student Progress Tracking section.

Resolve this conflict by accepting the upstream/main side which adds the new /first-pr/progress routes. These routes are correctly placed before /:id to avoid route conflicts, per coding guidelines.

🔧 Proposed resolution
-<<<<<<< HEAD
-=======
 // ─── Student Progress Tracking ─────────────────────────────────
 // NOTE: must be before /:id to avoid route conflicts

 opensourceRouter.get(
   "/first-pr/progress",
   authMiddleware,
   requireRole("STUDENT"),
   (req, res, next) => controller.getFirstPrProgress(req, res, next),
 );

 opensourceRouter.patch(
   "/first-pr/progress",
   authMiddleware,
   requireRole("STUDENT"),
   (req, res, next) => controller.patchFirstPrProgress(req, res, next),
 );

 // ─── Repo Requests (Student-authenticated) ─────────────────────
->>>>>>> upstream/main

Based on learnings: /requests/* routes must appear BEFORE /:id to avoid route conflicts.

🧰 Tools
🪛 Biome (2.4.16)

[error] 28-38: Expected a statement but instead found '<<<<<<< HEAD

// ─── Student Progress Tracking ─────────────────────────────────
// NOTE: must be before /:id to avoid route conflicts

opensourceRouter.get(
"/first-pr/progress",
authMiddleware,
requireRole("STUDENT"),
(req, res, next) => controller.getFirstPrProgress(req, res, next),
)'.

(parse)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/src/module/opensource/opensource.routes.ts` around lines 28 - 48,
There is an unresolved merge conflict around the Student Progress Tracking
routes; accept the upstream/main changes by removing the conflict markers and
keeping the added routes: ensure opensourceRouter.get("/first-pr/progress",
authMiddleware, requireRole("STUDENT", ...)) calling
controller.getFirstPrProgress and opensourceRouter.patch("/first-pr/progress",
authMiddleware, requireRole("STUDENT", ...)) calling
controller.patchFirstPrProgress remain in the file and are placed before any
"/:id" or "/requests/*" routes to avoid route conflicts; remove the leftover
<<<<<<<, =======, and >>>>>>> markers so the file compiles cleanly.

// NOTE: these must be registered BEFORE /:id to avoid route conflicts

opensourceRouter.post("/requests", authMiddleware, requireRole("STUDENT"), (req, res, next) =>
Expand Down
30 changes: 17 additions & 13 deletions server/src/module/opensource/opensource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,25 @@ export class OpensourceService {
if (language) where["language"] = { equals: language, mode: "insensitive" };
if (difficulty) where["difficulty"] = difficulty;
if (domain) where["domain"] = domain;
const trimmedSearch = search?.trim();
if (trimmedSearch) {
// Prisma's scalar-list filters can't do case-insensitive substring match
// on array elements, so resolve tag matches via a raw ILIKE-on-unnest
// subquery and merge the matching ids into the OR clause.
const trimmedSearch = search?.trim();

if (trimmedSearch) {
// Prisma's scalar-list filters can't do case-insensitive substring match
// on array elements, so resolve tag matches via a raw ILIKE-on-unnest
// subquery and merge the matching ids into the OR clause.
const tagMatches = await prisma.$queryRaw<Array<{ id: number }>>`
SELECT id FROM "opensourceRepo"
WHERE EXISTS (
SELECT 1 FROM unnest(tags) AS t WHERE t ILIKE ${`%${trimmedSearch}%`}
)
`;

const tagMatchIds = tagMatches.map((r) => r.id);
where["OR"] = [
{ name: { contains: trimmedSearch, mode: "insensitive" } },
{ owner: { contains: trimmedSearch, mode: "insensitive" } },
{ description: { contains: search, mode: "insensitive" } },
{ language: { contains: search, mode: "insensitive" } },
where["OR"] = [
{ name: { contains: trimmedSearch, mode: "insensitive" } },
{ owner: { contains: trimmedSearch, mode: "insensitive" } },
{ description: { contains: trimmedSearch, mode: "insensitive" } },
{ language: { contains: trimmedSearch, mode: "insensitive" } },
...(tagMatchIds.length > 0 ? [{ id: { in: tagMatchIds } }] : []),
];
}
Expand Down Expand Up @@ -162,10 +164,12 @@ export class OpensourceService {
const skip = (page - 1) * limit;
const where: any = {};

if (search) {
const trimmedSearch = search?.trim();

if (trimmedSearch) {
where.OR = [
{ name: { contains: search, mode: "insensitive" } },
{ description: { contains: search, mode: "insensitive" } },
{ name: { contains: trimmedSearch, mode: "insensitive" } },
{ description: { contains: trimmedSearch, mode: "insensitive" } },
];
}
if (category) {
Expand Down
Loading