Skip to content

Commit

Permalink
feat(seeder): seed reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Dec 2, 2024
1 parent c3a61a6 commit e49f290
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/module/order/order.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class OrderRepository {
async updateStatusToCompleted() {
await this.db
.update(orders)
.set({ status: "scheduled" })
.set({ status: "completed" })
.where(lte(orders.estimatedEndTime, new Date()));
}
}
22 changes: 22 additions & 0 deletions src/module/review/review.seeder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { container } from "@/container";
import { faker } from "@faker-js/faker";

const orderRepository = container.orderRepository;
const reviewRepository = container.reviewRepository;

export const seedReviews = async () => {
const orders = await orderRepository.getOrders({});

if (orders.length === 0) {
throw new Error("Order not found");
}

console.log(`Seeding reviews with ${orders.length} data...`);
for (let i = 0; i < orders.length; i++) {
await reviewRepository.createReview({
orderId: orders[i].id,
rating: faker.number.int({ min: 1, max: 5 }),
message: faker.lorem.sentence(),
});
}
};
2 changes: 2 additions & 0 deletions src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@/module/tutor/tutor.seeder";
import { seedTutories } from "@/module/tutories/tutories.seeder";
import { seedOrders } from "./module/order/order.seeder";
import { seedReviews } from "./module/review/review.seeder";

export const runSeeder = async () => {
await seedCategories();
Expand All @@ -15,6 +16,7 @@ export const runSeeder = async () => {
await seedTutories({ generateWithGroq: true });
await assignTutorProfilePictures();
await seedOrders();
await seedReviews();
};

runSeeder();

0 comments on commit e49f290

Please sign in to comment.