Skip to content

Conversation

@Halo-sparcs
Copy link
Contributor

Summary

It closes #629

@Halo-sparcs Halo-sparcs linked an issue Aug 19, 2025 that may be closed by this pull request
@Halo-sparcs Halo-sparcs self-assigned this Aug 19, 2025
Copy link
Member

@kmc7468 kmc7468 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 일단 1차 리뷰 남겨드립니다... ㅎㅎㅎ

@kmc7468 kmc7468 marked this pull request as ready for review September 9, 2025 13:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a mileage feature to reward users based on their taxi-sharing activity. The feature tracks transactions tied to room participation, calculates mileage based on forecasted taxi fares, and provides APIs for viewing summaries, transaction history, and leaderboards.

Key changes:

  • Created mileage transaction system with pending/confirmed/voided statuses
  • Integrated mileage calculation into room lifecycle (create, join, abort, settlement)
  • Added scheduled task to fetch and cache taxi fare data from Naver Maps API

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/types/mongo.d.ts Export Mileage type
src/services/rooms.ts Integrate mileage transactions into room handlers
src/mileage/services/transaction.ts Core transaction CRUD logic
src/mileage/services/summary.ts User mileage summary with tier calculation
src/mileage/services/leaderboard.ts Leaderboard aggregation with ranking
src/mileage/schedules/getTaxiFare.ts Scheduled taxi fare fetching routine
src/mileage/routes/*.ts Route definitions for mileage endpoints
src/mileage/routes/docs/*.js Swagger documentation
src/mileage/modules/mongo.ts Mileage schema definition
src/mileage/modules/forecastTaxiFare.ts Taxi fare prediction logic
src/mileage/index.ts Main mileage router
src/loadenv.ts Naver Maps API configuration
src/index.ts Mount mileage router

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2 to +5
import { summaryHandler } from "../services/summary";

const router = express.Router();

Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Missing authentication middleware. The summary endpoint accesses user-specific data (req.userOid) but lacks authMiddleware protection. Add router.use(authMiddleware) to protect this route, following the pattern in other authenticated routes.

Suggested change
import { summaryHandler } from "../services/summary";
const router = express.Router();
import { summaryHandler } from "../services/summary";
import { authMiddleware } from "../middleware/auth";
const router = express.Router();
router.use(authMiddleware);

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +12
import express from "express";
import { leaderboardHandler } from "../services/leaderboard";
import { mileageZod } from "./docs/schemas/mileageSchema";
import { validateQuery } from "@/middlewares";

const router = express.Router();

router.get(
"/",
validateQuery(mileageZod.leaderboardHandler),
leaderboardHandler
);
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

[nitpick] Missing input validation. The leaderboardHandler validates limit as a positive integer in the handler itself (line 14), but the validation should occur at the middleware level using validateQuery. However, if leaderboard is meant to be public, consider documenting this design decision.

Copilot uses AI. Check for mistakes.
});

const parameter = ordinaryLeastSquares(
changedRecord.filter((record) => record != 0)
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Use strict equality (record !== 0) instead of loose equality (record != 0) for type-safe comparisons.

Suggested change
changedRecord.filter((record) => record != 0)
changedRecord.filter((record) => record !== 0)

Copilot uses AI. Check for mistakes.
await updateTransaction(updates);
}
} catch (err) {
// room 로직에 영향 없게 조용히 처리
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Silent error handling without logging. This catch block in joinHandler silently ignores errors when updating mileage transactions. Add logger.error(err) for debugging, consistent with the error handling at line 489 in abortHandler.

Suggested change
// room 로직에 영향 없게 조용히 처리
// room 로직에 영향 없게 조용히 처리
logger.error(err);

Copilot uses AI. Check for mistakes.
example: "earn",
},
amount: { type: "integer", example: 50 },
createdAt: {
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Documentation uses 'createdAt' but the actual implementation uses 'createAt'. Once the schema field is corrected to 'createdAt', this documentation will be accurate.

Copilot uses AI. Check for mistakes.

export const mileageZod = {
transactionViewHandler: z.object({
type: z.string(),
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The 'type' field lacks validation constraints. According to the documentation (mileage.js:48), valid values are ["earn", "use", "event", "attendance"], but the schema accepts any string. Add .enum() validation or document that the field is optional for filtering.

Suggested change
type: z.string(),
type: z.enum(["earn", "use", "event", "attendance"]),

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

마일리지 기능 추가

3 participants