diff --git a/prisma/seed.ts b/prisma/seed.ts index b4a3be830..436a664ca 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,31 +1,32 @@ import db from '../src/db'; async function seedUsers() { - const users = [ - { - id: '1', - email: 'testuser@example.com', - name: 'Test User 1', - disableDrm: false, - }, - { - id: '2', - email: 'testuser2@example.com', - name: 'Test User 2', - disableDrm: false, - }, - ]; - try { - for (const user of users) { - await db.user.upsert({ - where: { - id: user.id, - }, - create: user, - update: {}, - }); - } + await db.user.upsert({ + where: { + id: '1', + }, + create: { + id: '1', + email: 'testuser@example.com', + name: 'Test User 1', + disableDrm: false, + }, + update: {}, + }); + + await db.user.upsert({ + where: { + id: '2', + }, + create: { + id: '2', + email: 'testuser2@example.com', + name: 'Test User 2', + disableDrm: false, + }, + update: {}, + }); } catch (error) { console.error('Error seeding users:', error); throw error; @@ -45,7 +46,50 @@ async function seedCourses() { openToEveryone: false, slug: 'test-course-1', }, - // Add more courses if needed + { + id: 2, + appxCourseId: 2, + discordRoleId: '3', + title: 'test course 2', + imageUrl: + 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', + description: 'test course 2', + openToEveryone: false, + slug: 'test-course-2', + }, + { + id: 3, + appxCourseId: 2, + discordRoleId: '3', + title: 'test course 2', + imageUrl: + 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', + description: 'test course 2', + openToEveryone: false, + slug: 'test-course-2', + }, + { + id: 4, + appxCourseId: 2, + discordRoleId: '3', + title: 'test course 2', + imageUrl: + 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', + description: 'test course 2', + openToEveryone: false, + slug: 'test-course-2', + }, + { + id: 5, + appxCourseId: 2, + discordRoleId: '3', + title: 'test course 2', + imageUrl: + 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', + description: 'test course 2', + openToEveryone: false, + slug: 'test-course-2', + }, ]; try { @@ -98,8 +142,8 @@ async function seedContent() { }, ]; - await db.content.createMany({ data: contentData }); - console.log('Created content:', contentData); + const createdContent = await db.content.createMany({ data: contentData }); + console.log('Created content:', createdContent); } catch (error) { console.error('Error seeding content:', error); throw error; @@ -107,31 +151,13 @@ async function seedContent() { } async function seedCourseContent() { - const courseContentData = [ - { courseId: 1, contentId: 1 }, - // Add more course-content pairs if needed - ]; - try { - for (const data of courseContentData) { - const existingCourseContent = await db.courseContent.findUnique({ - where: { - courseId_contentId: { - courseId: data.courseId, - contentId: data.contentId, - }, - }, - }); - - if (!existingCourseContent) { - await db.courseContent.create({ - data, - }); - console.log('Created course content:', data); - } else { - console.log('Course content already exists:', data); - } - } + await db.courseContent.create({ + data: { + courseId: 1, + contentId: 1, + }, + }); } catch (error) { console.error('Error seeding course content:', error); throw error; @@ -140,24 +166,13 @@ async function seedCourseContent() { async function seedNotionMetadata() { try { - const existingMetadata = await db.notionMetadata.findUnique({ - where: { + await db.notionMetadata.create({ + data: { id: 1, + notionId: '39298af78c0f4c4ea780fd448551bad3', + contentId: 2, }, }); - - if (!existingMetadata) { - await db.notionMetadata.create({ - data: { - id: 1, - notionId: '39298af78c0f4c4ea780fd448551bad3', - contentId: 2, - }, - }); - console.log('Created Notion metadata'); - } else { - console.log('Notion metadata already exists'); - } } catch (error) { console.error('Error seeding Notion metadata:', error); throw error; @@ -166,49 +181,38 @@ async function seedNotionMetadata() { async function seedVideoMetadata() { try { - const existingMetadata = await db.videoMetadata.findUnique({ - where: { + await db.videoMetadata.create({ + data: { id: 1, + contentId: 3, + video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', + video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', + slides: + 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/slides/Loops%2C+callbacks.pdf', }, }); - - if (!existingMetadata) { - await db.videoMetadata.create({ - data: { - id: 1, - contentId: 3, - video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', - video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', - slides: - 'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/slides/Loops%2C+callbacks.pdf', - }, - }); - console.log('Created video metadata'); - } else { - console.log('Video metadata already exists'); - } } catch (error) { console.error('Error seeding video metadata:', error); throw error; @@ -216,33 +220,33 @@ async function seedVideoMetadata() { } async function seedPurchases() { - const purchases = [ - { userId: '1', courseId: 1 }, - { userId: '2', courseId: 1 }, - { userId: '1', courseId: 2 }, - { userId: '2', courseId: 2 }, - ]; - try { - for (const purchase of purchases) { - const existingPurchase = await db.userPurchases.findUnique({ - where: { - userId_courseId: { - userId: purchase.userId, - courseId: purchase.courseId, - }, - }, - }); - - if (!existingPurchase) { - await db.userPurchases.create({ data: purchase }); - console.log('Created user purchase:', purchase); - } else { - console.log('User purchase already exists:', purchase); - } - } + await db.userPurchases.create({ + data: { + userId: '1', + courseId: 1, + }, + }); + await db.userPurchases.create({ + data: { + userId: '2', + courseId: 1, + }, + }); + await db.userPurchases.create({ + data: { + userId: '1', + courseId: 2, + }, + }); + await db.userPurchases.create({ + data: { + userId: '2', + courseId: 2, + }, + }); } catch (error) { - console.error('Error while seeding purchases:', error); + console.error('Error while seeding purchases'); throw error; } }