Skip to content

Commit

Permalink
seeded some image url and fixed include
Browse files Browse the repository at this point in the history
  • Loading branch information
Muzea001 committed Nov 1, 2024
1 parent 224b82c commit bf42bc4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
24 changes: 24 additions & 0 deletions prisma/seed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcrypt'
import crypto from 'crypto'
const prisma = new PrismaClient()

async function seed() {
Expand All @@ -25,6 +26,29 @@ async function seed() {
'STUDENT',
'Testpassword1!'
)

function generateRandomBase64String() {
return crypto
.randomBytes(12)
.toString('base64')
.replace(/[^a-zA-Z0-9]/g, '')
}
const student2 = await createUser(
'[email protected]',
cohort.id,
'John',
'Doe',
'Hello, this is me',
'[email protected]',
'JohnDoe',
'123-456-7890', // mobile
'Software Engineering', // specialism
new Date('2023-01-01'), // startDate
new Date('2023-12-31'),
generateRandomBase64String(),
'STUDENT',
'Testpassword1!'
)
const teacher = await createUser(
'[email protected]',
null,
Expand Down
21 changes: 18 additions & 3 deletions src/domain/cohort.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export default class Cohort {
cohort.startDate,
cohort.endDate,
cohort.students
? cohort.students.map((student) => User.fromDb(student))
? cohort.students.map((student) =>
User.fromDb({
...student,
profileImage: student.profile
? student.profile.profileImage
: null
})
)
: []
)
}
Expand Down Expand Up @@ -74,7 +81,11 @@ export default class Cohort {
static async getAllCohorts() {
const cohorts = await dbClient.cohort.findMany({
include: {
students: true
students: {
include: {
profile: true
}
}
}
})
return cohorts.map((cohort) => Cohort.fromDb(cohort))
Expand All @@ -84,7 +95,11 @@ export default class Cohort {
const cohort = await dbClient.cohort.findUnique({
where: { id },
include: {
students: true
students: {
include: {
profile: true
}
}
}
})
return cohort ? Cohort.fromDb(cohort) : null
Expand Down

0 comments on commit bf42bc4

Please sign in to comment.