Public
Edited
Jan 21, 2024
Insert cell
md`# Course Sections`
Insert cell
`mutation CreateCourse {
${serialize("createCourse", {
id: "tn-carry",
title: "TN Carry",
description:"Tennessee Handgun Carry",
urlSlug: "tn-carry",
sections: _.map(rawData, objectMapper)
})}
}`
Insert cell
function serialize(name, input){
return ` ${name}(input: ${Serializer(input).replace(/\'/g, "\"")} ){ id }`;
}
Insert cell
function objectMapper(input, i){
return cleanEmptyProps({
id: input.urlSlug,
index: parseInt(input.index, 10),
title: input.title,
description: input.description,
sectionType: input.sectionType,
videoDurationInSeconds: parseInt(input.videoDurationInSeconds, 10),
quizId: input.quizId ? `tn-carry#${input.quizId}` : "",
videoId: input.videoId
}, "quizId", "videoId");
}
Insert cell
function cleanEmptyProps(obj, ...propNames){
for(const name of propNames){
if(obj[name] === ""){
delete obj[name];
}
}
return obj;
}
Insert cell
Insert cell
md`# Appendix`
Insert cell
d3 = require("d3@5")
Insert cell
_ = require("lodash");
Insert cell
sac = import('https://cdn.pika.dev/serialize-as-code@%5E1.3.1');
Insert cell
Serializer = sac.Serializer.create(o => {
if(o === "MULTIPLE_CHOICE") return "MULTIPLE_CHOICE";
if(o === "QUIZ") return "QUIZ";
if(o === "VIDEO") return "VIDEO";
});
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more