-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitialImportResources.js
More file actions
40 lines (34 loc) · 1.14 KB
/
initialImportResources.js
File metadata and controls
40 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'fs';
import path from 'path';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function importResources() {
const filePath = path.join(process.cwd(), 'public', 'gcse_log_json.json');
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
console.log('Clearing existing resources...');
await prisma.rating.deleteMany({});
await prisma.resource.deleteMany({});
for (const item of data) {
await prisma.resource.create({
data: {
resourceId: String(item["Resource ID"]),
type: item["Resource Type"],
title: item["Resource Title"],
level: item["Study Level"],
subject: item["Subject"],
examBoard: item["Exam Board"],
link: item["Link"],
author: item["Resource Author"],
description: item["Resource Description"],
averageRating: item["Average Rating"] || 0,
},
});
console.log(`Imported resource ID ${item["Resource ID"]}`);
}
await prisma.$disconnect();
console.log('All resources imported successfully.');
}
importResources().catch((e) => {
console.error(e);
prisma.$disconnect();
});