66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('--- Inspecting and Cleaning FAQs ---');
|
|
|
|
const totalBefore = await prisma.fAQ.count();
|
|
console.log(`Total FAQs before: ${totalBefore}`);
|
|
|
|
const activeCount = await prisma.fAQ.count({ where: { isActive: true } });
|
|
const inactiveCount = await prisma.fAQ.count({ where: { isActive: false } });
|
|
console.log(`Active FAQs: ${activeCount}, Inactive FAQs: ${inactiveCount}`);
|
|
|
|
// Fetch sample of active and inactive
|
|
const sampleActive = await prisma.fAQ.findMany({
|
|
where: { isActive: true },
|
|
select: { id: true, question: true, order: true },
|
|
take: 5,
|
|
});
|
|
console.log('Sample Active FAQs:', JSON.stringify(sampleActive, null, 2));
|
|
|
|
// Find tasks that contain content development phrases
|
|
const tasksToDelete = await prisma.fAQ.findMany({
|
|
where: {
|
|
OR: [
|
|
{ question: { contains: 'راهنمای' } },
|
|
{ question: { contains: 'اینفوگرافیک' } },
|
|
{ question: { contains: 'نگارش' } },
|
|
{ question: { contains: 'تدوین' } },
|
|
{ question: { contains: 'تولید' } },
|
|
{ question: { contains: 'مقاله' } },
|
|
],
|
|
},
|
|
select: { id: true, question: true, isActive: true },
|
|
});
|
|
|
|
console.log(`Found ${tasksToDelete.length} content tasks inside FAQs table.`);
|
|
|
|
if (tasksToDelete.length > 0) {
|
|
const ids = tasksToDelete.map(t => t.id);
|
|
const deleteResult = await prisma.fAQ.deleteMany({
|
|
where: { id: { in: ids } },
|
|
});
|
|
console.log(`Successfully deleted ${deleteResult.count} misplaced content tasks from faqs.`);
|
|
}
|
|
|
|
const totalAfter = await prisma.fAQ.count();
|
|
console.log(`Total FAQs remaining: ${totalAfter}`);
|
|
|
|
const remaining = await prisma.fAQ.findMany({
|
|
select: { id: true, question: true, isActive: true, order: true },
|
|
take: 10,
|
|
});
|
|
console.log('Remaining FAQs:', JSON.stringify(remaining, null, 2));
|
|
}
|
|
|
|
main()
|
|
.catch(e => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|