Closed sebgro98 closed 5 hours ago
Related to this issue that address Prisma modelling. To interface the backend database, a model-class of Cohort must be implemented.
It should import dbClient to access the database
import dbClient from '../utils/dbClient.js'
It should be able to return all cohorts
export async function getAllCohorts() { try { const cohorts = await dbClient.cohort.findMany({ include: { users: { select: { id: true, role: true } } } }) return cohorts } catch (error) { console.error('Error getting cohorts:', error) throw error } }
It should be able to create a cohort
export async function createCohort({ name, startDate, endDate }) { startDate = new Date(startDate) endDate = new Date(endDate) try { const createdCohort = await dbClient.cohort.create({ data: { name, startDate, endDate, createdAt: new Date(), updatedAt: new Date() }, include: { users: { select: { id: true, role: true } } } }) console.log('Created cohort:', createdCohort) return createdCohort } catch (error) { console.error('Error creating cohort:', error) throw error } } }
The seeding should be addressed also, in prisma/seed.js, by updating the createCohort function:
async function createCohort() { const cohort = await prisma.cohort.create({ data: { name: 'Web Development', startDate: new Date('2014-06-01'), endDate: new Date('2014-12-01'), createdAt: new Date(), updatedAt: new Date() } }) console.info('Cohort created', cohort) return cohort }
Approved
Is the Seeding of sample data covered too?
Now it is
Related to this issue that address Prisma modelling. To interface the backend database, a model-class of Cohort must be implemented.
It should import dbClient to access the database
It should be able to return all cohorts
It should be able to create a cohort
The seeding should be addressed also, in prisma/seed.js, by updating the createCohort function: