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