Added todo instructions to import route files
This commit is contained in:
parent
1bd327ea1a
commit
66986654dd
@ -1,20 +1,19 @@
|
||||
Dr. Emily Neighbour Carter,Senior,None
|
||||
Dr. Emily Neighbour Carter,Junior,Dr. Rajiv Menon
|
||||
Dr. Rajiv Menon,Senior,None
|
||||
Dr. Izzy Patterson,Senior,None
|
||||
Dr. Hiroshi Takeda,Senior,None
|
||||
Dr. Miriam Hassan,Senior,None
|
||||
Dr. Alice Johnson,Junior,Dr. Emily Neighbour
|
||||
Dr. Tim Howitz,Junior,Dr. Rajiv Menon
|
||||
Dr. Alice Johnson,Senior,None
|
||||
Tim Howitz,Admin,None
|
||||
Dr. Natalia Petrova,Junior,Dr. Izzy Patteron
|
||||
Dr. Li Cheng,Junior,Dr. Rajiv Menon
|
||||
Dr. Javier Ortega,Junior,Dr. Izzy Patterson
|
||||
Dr. Priya Sharma,Junior,Dr. Hiroshi Takeda
|
||||
Dr. Lukeshan Thananchayan,Junior,Dr. Miriam Hassan
|
||||
Dr. Elena Fischer,Junior,Dr. Emily Neighbour
|
||||
Dr. Elena Fischer,Junior,Dr. Alice Johnson
|
||||
Dr. Mohammed Al-Farsi,Junior,Dr. Miriam Hassan
|
||||
Dr. Jane Wong,Junior,Dr. Hiroshi Takeda
|
||||
Dr. Carlos Gutierrez,Junior,Dr. Rajiv Menon
|
||||
Dr. Fiona MacLeod,Junior,Dr. Emily Neighbour
|
||||
Dr. Wei Zhao,Junior,Dr. Miriam Hassan
|
||||
Dr. Antonio Rosales,Junior,Dr. Izzy Patterson
|
||||
Dr. Kate Wilson,Junior,Dr. Hiroshi Takeda
|
||||
|
||||
|
@ -11,6 +11,8 @@ const prisma = new PrismaClient();
|
||||
|
||||
type CsvRow = {
|
||||
Type: string;
|
||||
Name: string;
|
||||
Description: string;
|
||||
WarehouseArea: string;
|
||||
EarthquakeId: string;
|
||||
Required?: string;
|
||||
@ -36,12 +38,16 @@ export async function POST() {
|
||||
|
||||
// 3. Map records to artefact input
|
||||
const artefacts = records.map((row) => ({
|
||||
name: row.Name,
|
||||
description: row.Description,
|
||||
type: row.Type,
|
||||
warehouseArea: row.WarehouseArea,
|
||||
// todo get earthquakeId where code === row.EarthquakeCode
|
||||
earthquakeId: parseInt(row.EarthquakeId, 10),
|
||||
required: stringToBool(row.Required, true), // default TRUE
|
||||
shopPrice: row.ShopPrice && row.ShopPrice !== "" ? parseFloat(row.ShopPrice) : null,
|
||||
pickedUp: stringToBool(row.PickedUp, false), // default FALSE
|
||||
// todo add random selection for creatorId
|
||||
creatorId: null,
|
||||
purchasedById: null,
|
||||
}));
|
||||
@ -49,7 +55,6 @@ export async function POST() {
|
||||
// 4. Bulk insert
|
||||
await prisma.artefact.createMany({
|
||||
data: artefacts,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@ -39,12 +39,12 @@ export async function POST() {
|
||||
longitude: parseFloat(row.Longitude),
|
||||
location: row.Location,
|
||||
depth: row.Depth, // store as received
|
||||
// todo add random selection for creatorId
|
||||
creatorId: null,
|
||||
}));
|
||||
// 4. Bulk create earthquakes in database:
|
||||
await prisma.earthquake.createMany({
|
||||
data: earthquakes,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
return NextResponse.json({ success: true, count: earthquakes.length });
|
||||
} catch (error: any) {
|
||||
|
||||
@ -45,13 +45,13 @@ export async function POST() {
|
||||
dateEstablished: row.DateEstablished ? parseInt(row.DateEstablished, 10) : null,
|
||||
functional: stringToBool(row.Functional),
|
||||
seismicSensorOnline: row.SeismicSensorOnline ? stringToBool(row.SeismicSensorOnline) : true, // default true per schema
|
||||
// todo add random selection of creatorId
|
||||
creatorId: null,
|
||||
}));
|
||||
|
||||
// 4. Bulk insert
|
||||
await prisma.observatory.createMany({
|
||||
data: observatories,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@ -50,7 +50,6 @@ export async function POST() {
|
||||
|
||||
await prisma.request.createMany({
|
||||
data: filteredRequests,
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, count: filteredRequests.length });
|
||||
|
||||
@ -35,17 +35,18 @@ export async function POST() {
|
||||
});
|
||||
|
||||
// 3. Transform each record for Prisma
|
||||
// todo add senior scientists first
|
||||
const scientists = records.map((row) => ({
|
||||
name: row.Name,
|
||||
level: normalizeLevel(row.Level),
|
||||
userId: parseInt(row.UserId, 10),
|
||||
// todo get superior id by name from db
|
||||
superiorId: row.SuperiorId && row.SuperiorId.trim() !== "" ? parseInt(row.SuperiorId, 10) : null,
|
||||
}));
|
||||
|
||||
// 4. Bulk create scientists in database
|
||||
await prisma.scientist.createMany({
|
||||
data: scientists,
|
||||
skipDuplicates: true, // in case the scientist/userid combo already exists
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, count: scientists.length });
|
||||
|
||||
@ -45,7 +45,6 @@ export async function POST() {
|
||||
// 4. Bulk create users in database
|
||||
await prisma.user.createMany({
|
||||
data: users,
|
||||
skipDuplicates: true, // because email is unique
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, count: users.length });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user