tractatus/scripts/create-economist-package.js
TheFlow 2298d36bed fix(submissions): restructure Economist package and fix article display
- Create Economist SubmissionTracking package correctly:
  * mainArticle = full blog post content
  * coverLetter = 216-word SIR— letter
  * Links to blog post via blogPostId
- Archive 'Letter to The Economist' from blog posts (it's the cover letter)
- Fix date display on article cards (use published_at)
- Target publication already displaying via blue badge

Database changes:
- Make blogPostId optional in SubmissionTracking model
- Economist package ID: 68fa85ae49d4900e7f2ecd83
- Le Monde package ID: 68fa2abd2e6acd5691932150

Next: Enhanced modal with tabs, validation, export

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 08:47:42 +13:00

76 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
require('dotenv').config();
const mongoose = require('mongoose');
const SubmissionTracking = require('../src/models/SubmissionTracking.model');
async function createPackage() {
await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/tractatus_dev');
const BlogPost = mongoose.connection.db.collection('blog_posts');
// Get the main article blog post
const mainArticle = await BlogPost.findOne({
slug: 'the-new-a-i-amoral-intelligence'
});
// Get the letter (to extract content then delete)
const letterPost = await BlogPost.findOne({
slug: 'letter-to-the-economist-amoral-intelligence'
});
if (!mainArticle) {
console.error('Main article not found');
process.exit(1);
}
console.log('Found main article:', mainArticle.title);
if (letterPost) {
console.log('Found letter post:', letterPost.title);
}
// Create submission package
const submission = new SubmissionTracking({
blogPostId: mainArticle._id,
publicationId: 'economist-letter',
publicationName: 'The Economist',
title: mainArticle.title,
wordCount: letterPost ? letterPost.content.split(/\s+/).length : 216,
contentType: 'letter',
status: 'ready',
createdBy: new mongoose.Types.ObjectId('000000000000000000000000'),
lastUpdatedBy: new mongoose.Types.ObjectId('000000000000000000000000')
});
// Store main article
await submission.setDocumentVersion('mainArticle', 'en', mainArticle.content, {
translatedBy: 'manual',
approved: true
});
// Store cover letter (the "SIR—" letter)
if (letterPost) {
await submission.setDocumentVersion('coverLetter', 'en', letterPost.content, {
translatedBy: 'manual',
approved: true
});
}
await submission.save();
console.log('\n✅ Economist package created!');
console.log('Submission ID:', submission._id);
console.log('Linked to blog post:', mainArticle._id);
// Remove letter from blog posts
if (letterPost) {
await BlogPost.updateOne(
{ _id: letterPost._id },
{ $set: { status: 'archived' } }
);
console.log('✅ Letter post archived');
}
await mongoose.connection.close();
}
createPackage().catch(console.error);