100 lines
3.4 KiB
TypeScript
100 lines
3.4 KiB
TypeScript
import { Logger } from "@nestjs/common";
|
|
import { DataSource } from "typeorm";
|
|
|
|
import { BlogCommentReply } from "../../src/modules/blogs/entities/blog-comment-reply.entity";
|
|
import { BlogComment } from "../../src/modules/blogs/entities/blog-comment.entity";
|
|
import { User } from "../../src/modules/users/entities/user.entity";
|
|
|
|
const blogCommentReplies = [
|
|
{
|
|
content: "ممنون از نظر شما. خوشحالم که مقاله مفید بوده.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "بله، این روش در اکثر شرایط قابل استفاده است. فقط در موارد خاص نیاز به تنظیمات اضافی دارد.",
|
|
isOfficialReply: false,
|
|
},
|
|
{
|
|
content: "من هم همین تجربه را داشتم. واقعاً روش موثری است.",
|
|
isOfficialReply: false,
|
|
},
|
|
{
|
|
content: "در مقاله بعدی حتماً این بخش را بیشتر توضیح خواهم داد.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "خواهش میکنم. هدف ما کمک به کاربران است.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "پیشنهاد خوبی است. در نسخه بعدی مقاله حتماً مثالهای بیشتری اضافه میکنم.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "متأسفم که این احساس را داشتید. سعی میکنم مطالب جدیدتری ارائه دهم.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "بله، حتماً. منابع علمی در انتهای مقاله آمده است.",
|
|
isOfficialReply: true,
|
|
},
|
|
{
|
|
content: "من هم همین سوال را داشتم. ممنون که پرسیدید.",
|
|
isOfficialReply: false,
|
|
},
|
|
{
|
|
content: "این روش را من هم امتحان کردم و نتیجه گرفتم.",
|
|
isOfficialReply: false,
|
|
},
|
|
{
|
|
content: "بله، کاملاً درست میگویید. این روش نیاز به تمرین دارد.",
|
|
isOfficialReply: false,
|
|
},
|
|
{
|
|
content: "من هم همین تجربه را داشتم. واقعاً عالی کار میکند.",
|
|
isOfficialReply: false,
|
|
},
|
|
];
|
|
|
|
export const seedBlogCommentReplies = async (dataSource: DataSource, logger: Logger) => {
|
|
try {
|
|
const replyRepo = dataSource.getRepository(BlogCommentReply);
|
|
const commentRepo = dataSource.getRepository(BlogComment);
|
|
const userRepo = dataSource.getRepository(User);
|
|
|
|
// Get existing comments and users
|
|
const comments = await commentRepo.find({ take: 10 });
|
|
const users = await userRepo.find({ take: 10 });
|
|
|
|
if (comments.length === 0) {
|
|
logger.warn("No blog comments found. Please seed blog comments first.");
|
|
return;
|
|
}
|
|
|
|
if (users.length === 0) {
|
|
logger.warn("No users found. Please seed users first.");
|
|
return;
|
|
}
|
|
|
|
for (const replyData of blogCommentReplies) {
|
|
// Randomly select comment and user
|
|
const randomComment = comments[Math.floor(Math.random() * comments.length)];
|
|
const randomUser = users[Math.floor(Math.random() * users.length)];
|
|
|
|
const reply = replyRepo.create({
|
|
...replyData,
|
|
comment: randomComment,
|
|
author: randomUser,
|
|
});
|
|
|
|
await replyRepo.save(reply);
|
|
logger.log(`Blog comment reply created successfully`);
|
|
}
|
|
|
|
logger.log("Blog comment replies seeding completed");
|
|
} catch (error) {
|
|
logger.error("Error in seeding blog comment replies", error);
|
|
process.exit(1);
|
|
}
|
|
};
|