-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Windows 10 Professional
MongoDB.Atlas
Node v8.10.0
All dependencies for Windows have been installed. When I synced Github in Ch. 6 the introduction page md was synced to MongoDB but none of the other demo-book info synced. Now in Ch. 8 the stripe buy button requires the chapter-1.md to test the integration and I'm hung up on rendering anything other than the introduction page. I've signed back in as the Admin and resynced but the alert tells me nothing has changed in the document. I've narrowed down this issue and know of a solution that could be implemented. It is a bit DRY, similar to the pattern shown here, https://www.khanacademy.org/computer-programming/spin-off-of-project-magic-8-ball/6639567377956864. Outside of explicitly stating each path, is there any other implementation other than :
static async syncContent({ book, data }) {
const {
title,
excerpt = '',
isFree = false,
seoTitle = '',
seoDescription = '',
} = data.attributes;
const { body, path } = data;
const chapter = await this.findOne({
bookId: book.id,
githubFilePath: path,
});
let order;
if (path === 'introduction.md') {
order = 1;
} else {
order = parseInt(path.match(/[0-9]+/), 10) + 1;
}
const content = body;
const htmlContent = markdownToHtml(content);
const htmlExcerpt = markdownToHtml(excerpt);
const sections = getSections(content);
if (!chapter) {
const slug = await generateSlug(this, title, { bookId: book._id });
return this.create({
bookId: book._id,
githubFilePath: path,
title,
slug,
isFree,
content,
htmlContent,
sections,
excerpt,
htmlExcerpt,
order,
seoTitle,
seoDescription,
createdAt: new Date(),
});
}
const modifier = {
content,
htmlContent,
sections,
excerpt,
htmlExcerpt,
isFree,
order,
seoTitle,
seoDescription,
};
if (title !== chapter.title) {
modifier.title = title;
modifier.slug = await generateSlug(this, title, {
bookId: chapter.bookId,
});
}
return this.updateOne({ _id: chapter._id }, { $set: modifier });
}
}
in the Mongoose Chapter model you might suggest to sync data between MongoDB and Github?