Open mnmin opened 1 year ago
This is an excellent start. Here are some notes:
Since you'll be adding some many-to-many relationships to satisfy the above, we'll need some sample API response structures so the people working on the client side can get started and build to that spec before the backend is complete
This is a very detailed plan! Looks great! Nice job!! One thing about the event emitter is that the class CreateEventError is only used for catching the error when the database fails to create an event to record something it should create an event for. So you might want to use other error classes in that file, or create new classes if needed.
Ok, making changes to the plan
Plan Prisma schema and added sample API response structures
This all looks great, excellent work!
I do just have a question about this snippet:
const iterator = 2
for (let mod = 0; mod < iterator; mod++) {
const module = await prisma.module.create({})
for (let un = 0; un < iterator; un++) {
const unit = await prisma.unit.create({})
for (let les = 0; les < iterator; les++) {
const lesson = await prisma.lesson.create({})
const lessonPlan = await prisma.lessonPlan.create({})
console.log('module, unit, lesson, lessonPlan', module, unit, lesson, lessonPlan)
}
}
}
What is the purpose of this? Is it to seed the database?
yes, it seeds the database. I made some changes (adding exercises to the for loop).
I think it would be better if instead you split out creating each of the entities into their own function. For instance,
const createUnit = async (module) => {
return prisma.unit.create({connect: {id: module.id})
}
That way, you'll be able to seed all of the data that you wish by passing in values via the parameters, and it'll be a lot easier to maintain the seed file in the future (reading 3 nested loops can be quite confusing)
const iterator = 2
for (let curr = 1; curr <= iterator; curr++) {
const curriculum = await prisma.curriculum.create({
data: {
name: 'Javascript',
description:
'Learn the JavaScript fundamentals you will need for front-end or back-end development'
}
})
for (let mod = 1; mod <= iterator; mod++) {
const module = await prisma.module.create({
data: {
name: `Module ${mod}`,
description: `Description for Module-${mod}`,
objectives: [
`Objective 1 for module-${mod} Curriculum-${curr}`,
`Objective 2 for module-${mod} Curriculum-${curr}`,
`Objective 2 for module-${mod} Curriculum-${curr}`,
`Objective 2 for module-${mod} Curriculum-${curr}`,
`Objective 2 for module-${mod} Curriculum-${curr}`
],
curriculum: {
connect: {
id: curriculum.id
}
}
}
})
for (let un = 1; un <= iterator; un++) {
const unit = await prisma.unit.create({
data: {
name: `Unit ${un}`,
description: `Description for Unit-${un}`,
objectives: [
`Objective 1 for Unit-${un} Module-${mod} Curriculum-${curr}`,
`Objective 1 for Unit-${un} Module-${mod} Curriculum-${curr}`,
`Objective 1 for Unit-${un} Module-${mod} Curriculum-${curr}`,
`Objective 1 for Unit-${un} Module-${mod} Curriculum-${curr}`,
`Objective 1 for Unit-${un} Module-${mod} Curriculum-${curr}`
],
moduleId: module.id
}
})
this is how it's looking atm I can change it if it's too confusing. It produces the API responses that I added in the API responses section of the plan.
I think it would be better if you split up the creation of each entity into their own functions. The you can call those functions in your for loops
Ok, I'll split them
User Story
A lesson should have a day number (not a date, more like a number to represent where it is in the delivery sequence). This can't be an ID as lessons might be re-ordered
A lesson should have a list of learning objectives and a lesson plan
A lesson plan must be stored as Markdown so it can be formatted with things like headers, bullet points and code snippets
We should be able to connect exercises to a lesson
When creating a lesson, we should be able to create new exercises as part of the process
Teachers should be able to see a high-level view of all modules. Clicking a module should show its data and a list of its units. Clicking a unit should show its data and a list of its lessons. Clicking a lesson should show its data and a list of its exercises.
Tasks
SERVER SIDE
Check List
Overview
1 - Create Prisma Schema
Use Prisma Schema Documentation to create: Curriculum, Module, Unit, Lessons, Lesson Plan: https://www.prisma.io/docs/concepts/components/prisma-client/crud
2 - Create methods in the seed file
Overview In Seed.js
1 - Create a curriculum
2 - Create n seeds for each component
3 - Sample API response
3 - Create modules for routes and controllers with methods
Routers --> routers folder --> curriculum.js CURRICULUM - routers
router.post(‘/’, validateAuthentication, createCurriculum)
router.get(‘/’, validateAuthentication, getAllCurriculums)
router.put(‘/:id’, validateAuthentication, updateCurriculumById)
router.delete(‘/:id’, validateAuthentication, deleteCurriculumById)
MODULE - routers
router.post(‘/:id/module’, validateAuthentication, createModule)
router.get(‘/:id/module’, validateAuthentication, getAllModules)
router.get('/:id/module/:moduleId', validateAuthentication, getModuleById)
router.put(‘/:id/module/:moduleId’, validateAuthentication, updateModuleById)
router.delete(‘/:id/module/:moduleId’, validateAuthentication, deleteModuleById)
UNIT - routers
router.post(‘/:id/module/:moduleId/unit’, validateAuthentication, createUnit)
router.get(‘/:id/module/:moduleId/unit, validateAuthentication, getAllUnits)
router.get(‘/:id/module/:moduleId/unit/:unitId’, validateAuthentication, getUnitById)
router.put(‘/:id/module/:moduleId/unit/:unitId’, validateAuthentication, updateUnitById)
router.delete(‘/:id/module/:moduleId/unit/:unitId’, validateAuthentication, deleteUnitById)
LESSON - routers
router.post(‘/:id/module/:moduleId/unit/:unitId/lesson’, validateAuthentication, createLesson)
router.get(‘/:id/module/:moduleId/unit/:unitId/lesson', validateAuthentication, getAllLessons)
router.get(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId’, validateAuthentication, getLessonById)
router.put(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId’, validateAuthentication, updateLessonById)
router.delete(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId’, validateAuthentication, deleteLessonById)
LESSON PLAN - routers
router.post(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId/lessonPlan’, validateAuthentication, createLessonPlan)
router.get(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId/lessonPlan, validateAuthentication, getLessonPlan)
router.put(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId/lessonPlan’, validateAuthentication, updateLessonPlan)
router.delete(‘/:id/module/:moduleId/unit/:unitId/lesson/:lessonId/lessonPlan’, validateAuthentication, deleteLessonPlan)
CREATE METHODS FOR CONTROLLER Create the following methods in controllers folder --> curriculum.js
Curriculum createCurriculum() getAllCurriculums() updateCurriculumById() deleteCurriculumById()
Module createModule() getAllModules() getModuleById() updateModuleById() deleteModuleById()
Unit createUnit() getAllUnits() getUnitById() updateUnitById() deleteUnitById()
Lesson createLesson() getAllLessons() getLessonById() updateLessonById() deleteLessonById()
LessonPlan createLessonPlan() getLessonPlan() updateLessonPlan() deleteLessonPlan()
Sample API response structures:
UPDATE BY ID
4 - Add event emitters to all methods
Overview In eventEmitter --> utils.js Add event emitters only for important user actions
-Example only for batabase error createModuleCreatedEvent
Use classes in eventEmitter folder --> utils.js file to record important events.
In eventEmitter --> index.js
Add event listeners for each important user action, follow the existing naming convention for events eg: