Skip to content

Commit

Permalink
feat(reviews): get unreviewed and not dismissed order to show
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Dec 8, 2024
1 parent 021bfb2 commit 6146ae8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/module/order/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,17 @@ export const declineOrder: Controller<DeclineOrderSchema> = async (
.json({ status: "error", message: "Failed to decline order" });
}
};

export const getUnreviewedOrders: Controller = async (req, res) => {
try {
const orders = await orderService.getUnreviewedOrders(req.learner.id);

res.json({ status: "success", data: orders });
} catch (error) {
logger.error(`Failed to get unreviewed orders: ${error}`);

res
.status(500)
.json({ status: "error", message: "Failed to get unreviewed orders" });
}
};
8 changes: 7 additions & 1 deletion src/module/order/order.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
tutories as tutoriesTable,
tutors,
} from "@/db/schema";
import { and, eq, desc, inArray, lte } from "drizzle-orm";
import { and, eq, desc, inArray, lte, isNotNull } from "drizzle-orm";

export class OrderRepository {
constructor(private readonly db: typeof dbType) {}
Expand All @@ -29,12 +29,14 @@ export class OrderRepository {
tutoriesId,
orderId,
status,
unreviewed,
}: {
learnerId?: string;
tutorId?: string;
tutoriesId?: string;
orderId?: string;
status?: "pending" | "scheduled" | "completed";
unreviewed?: boolean;
}) {
await this.updateStatusToCompleted();

Expand All @@ -56,6 +58,10 @@ export class OrderRepository {
conditions.push(eq(orders.id, orderId));
}

if (typeof unreviewed === "boolean" && unreviewed) {
conditions.push(isNotNull(orders.reviewDismissedAt));
}

if (tutorId) {
const tutories = await this.db
.select({ id: tutoriesTable.id })
Expand Down
7 changes: 7 additions & 0 deletions src/module/order/order.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ orderRouter.post(
orderController.declineOrder,
);

orderRouter.get(
"/unreviewed",
// #swagger.tags = ['orders']
verifyLearner,
orderController.getUnreviewedOrders,
);

export default orderRouter;
12 changes: 12 additions & 0 deletions src/module/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ export class OrderService {
throw new Error(`Failed to decline order: ${error}`);
}
}

async getUnreviewedOrders(learnerId: string) {
try {
return this.orderRepository.getOrders({
learnerId,
status: "completed",
unreviewed: true,
});
} catch (error) {
throw new Error(`Failed to get unreviewed orders: ${error}`);
}
}
}

0 comments on commit 6146ae8

Please sign in to comment.