11// Import pride merch
22// OLD Script, will not work with current codebase
3+ import { AcademicYear } from "@docsoc/eactivities" ;
34import { PrismaClient } from "@prisma/client" ;
45import { parse } from "csv-parse" ;
56import { promises as fs } from "fs" ;
67
78const prisma = new PrismaClient ( ) ;
89
10+ // from collection/lib/config.ts
11+ async function getConfigValueFor ( key : string ) {
12+ const config = await prisma . config . findFirst ( {
13+ where : {
14+ key,
15+ } ,
16+ } ) ;
17+ return config ?. value ;
18+ }
19+ const ACADEMIC_YEAR_KEY = "academicYear" ;
20+ export async function getAcademicYear ( ) : Promise < AcademicYear > {
21+ return ( await getConfigValueFor ( ACADEMIC_YEAR_KEY ) ) as string as AcademicYear ;
22+ }
23+
924async function main ( fileName : string ) {
1025 // Create pride
1126 const lanyard = await prisma . rootItem . upsert ( {
1227 where : { name : "Pride Lanyard" } ,
1328 update : { } ,
1429 create : {
1530 name : "Pride Lanyard" ,
16- variants : {
31+ academicYear : ( await getAcademicYear ( ) ) as string as AcademicYear ,
32+ Variant : {
1733 create : {
1834 variantName : "Pride Lanyard" ,
1935 } ,
2036 } ,
2137 } ,
2238 include : {
23- variants : true ,
39+ Variant : true ,
2440 } ,
2541 } ) ;
2642
@@ -30,6 +46,13 @@ async function main(fileName: string) {
3046 columns : true ,
3147 } ) ;
3248
49+ const importName = `Pride Lanyard via pride.ts @ ${ new Date ( ) . toLocaleString ( "en-GB" ) } ` ;
50+ const importItem = await prisma . orderItemImport . create ( {
51+ data : {
52+ name : importName ,
53+ } ,
54+ } ) ;
55+
3356 for await ( const record of iter ) {
3457 const email = record [ "Email" ] ;
3558 const name = record [ "Name" ] ;
@@ -59,15 +82,15 @@ async function main(fileName: string) {
5982 const lanyardOrders = await prisma . order . findFirst ( {
6083 where : {
6184 studentId : user . id ,
62- orderItems : {
85+ OrderItem : {
6386 some : {
64- variantId : lanyard . variants [ 0 ] . id ,
87+ variantId : lanyard . Variant [ 0 ] . id ,
6588 } ,
6689 } ,
6790 } ,
6891 relationLoadStrategy : "join" ,
6992 include : {
70- orderItems : true ,
93+ OrderItem : true ,
7194 } ,
7295 } ) ;
7396
@@ -80,17 +103,23 @@ async function main(fileName: string) {
80103 await prisma . order . create ( {
81104 data : {
82105 orderDate : new Date ( dateWithTime ) ,
83- student : {
106+ academicYearReference : {
107+ connect : {
108+ year : lanyard . academicYear ,
109+ } ,
110+ } ,
111+ ImperialStudent : {
84112 connect : {
85113 id : user . id ,
86114 } ,
87115 } ,
88116 orderNo : Math . floor ( Math . random ( ) * 100000 ) ,
89- orderItems : {
117+ OrderItem : {
90118 create : {
91- variantId : lanyard . variants [ 0 ] . id ,
119+ variantId : lanyard . Variant [ 0 ] . id ,
92120 quantity : 1 ,
93121 collected : false ,
122+ importId : importItem . id ,
94123 } ,
95124 } ,
96125 } ,
0 commit comments