Skip to content
Merged
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
27 changes: 8 additions & 19 deletions server/src/module/opensource/opensource.routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from "express";
import { Router } from "express";
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

Remove the BOM (Byte Order Mark) character from the import statement.

The first line contains an invisible BOM character (U+FEFF) before the import keyword, which can cause module parsing failures and unexpected syntax errors in Node.js ES modules.

🧹 Proposed fix to remove BOM
-import { Router } from "express";
+import { Router } from "express";

Note: Most editors display BOM invisibly. To fix: delete the entire first line and retype it, or use a tool like dos2unix or your editor's "Remove BOM" feature.

📝 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
import { Router } from "express";
import { Router } from "express";
🤖 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` at line 1, Remove the
invisible BOM (U+FEFF) at the start of the file that precedes the import; open
the file containing the import of Router (opensource.routes.ts) and delete and
retype the first line "import { Router } from \"express\";" (or use your
editor's "Remove BOM" feature / dos2unix) so the BOM is gone and the module
parses correctly.

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

// ─── 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) ─────────────────────
// NOTE: these must be registered BEFORE /:id to avoid route conflicts

opensourceRouter.post("/requests", authMiddleware, requireRole("STUDENT"), (req, res, next) =>
Expand Down Expand Up @@ -81,6 +63,13 @@ opensourceRouter.get("/analytics/trend", authMiddleware, requireRole("STUDENT"),
controller.getStudentContributionTrend(req, res, next),
);

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),
);
// ─── Admin: Manage Repo Requests ───────────────────────────────

opensourceRouter.get("/requests/all", authMiddleware, requireRole("ADMIN"), (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