[offers][fix] update seed script to integrate with city

pull/501/head
Stuart Long Chay Boon 3 years ago
parent 60f225eb0f
commit f82568b04e

@ -115,213 +115,232 @@ const seedSalaries = async () => {
companyIdMappings[company.name] = company.id; companyIdMappings[company.name] = company.id;
}); });
//seed here // get countryId of Singapore
return await Promise.all( const singapore = (await prisma.city.findFirst({
data.map(async (data: ExcelData) => { where: {
name: "Singapore"
}
}))
// console.log(singapore)
// break;
// seed here
if (data.Income && typeof data.Income === 'number') { if (singapore) {
// Generate random name until unique return await Promise.all(
let uniqueName: string = await generateRandomName(); data.map(async (data: ExcelData) => {
if (data.TC && typeof data.TC === 'number') {
// Generate random name until unique
let uniqueName: string = await generateRandomName();
const jobTitle = getJobTitle(data.Role); const jobTitle = getJobTitle(data.Role);
const yoe = getYoe(data.Type); const yoe = getYoe(data.Type);
const level = getLevel(data.Type); const level = getLevel(data.Type);
// check if we have company id // check if we have company id
if (companyIdMappings[data.Company]) { if (companyIdMappings[data.Company]) {
const token = crypto const token = crypto
.createHash('sha256') .createHash('sha256')
.update( .update(
xlSerialToJsDate(data.Timestamp).toString() + xlSerialToJsDate(data.Timestamp).toString() +
generateRandomStringForToken(), generateRandomStringForToken(),
) )
.digest('hex'); .digest('hex');
if (data.Type.toUpperCase() === 'INTERNSHIP') { if (data.Type.toUpperCase() === 'INTERNSHIP') {
// create profile // create profile
const dataAdded = await prisma.offersProfile.create({ const dataAdded = await prisma.offersProfile.create({
data: { data: {
profileName: uniqueName, profileName: uniqueName,
createdAt: xlSerialToJsDate(data.Timestamp), createdAt: xlSerialToJsDate(data.Timestamp),
editToken: token, editToken: token,
background: { background: {
create: { create: {
totalYoe: yoe, totalYoe: yoe,
},
}, },
}, offers: {
offers: { create: {
create: { comments: data.Comments ?? '',
comments: data.Comments ?? '', company: {
company: { connect: {
connect: { id: companyIdMappings[data.Company],
id: companyIdMappings[data.Company], },
}, },
}, jobType: 'INTERN',
jobType: 'INTERN', location: {
location: 'Singapore, Singapore', // TODO: DEFAULT AS SG connect: {
monthYearReceived: xlSerialToJsDate(data.Timestamp), id: singapore.id
negotiationStrategy: '', }
offersIntern: { }, // TODO: DEFAULT AS SG
create: { monthYearReceived: xlSerialToJsDate(data.Timestamp),
internshipCycle: 'Summer', negotiationStrategy: '',
monthlySalary: { offersIntern: {
create: { create: {
baseCurrency: baseCurrencyString, internshipCycle: 'Summer',
baseValue: await convert( monthlySalary: {
data.Income create: {
? typeof data.Income === 'number' baseCurrency: baseCurrencyString,
? data.Income baseValue: await convert(
: 0 data.Income
: 0, ? typeof data.Income === 'number'
'SGD', // assume sgd ? data.Income
baseCurrencyString, : 0
), : 0,
currency: 'SGD', // assume sgd 'SGD', // assume sgd
value: data.Income baseCurrencyString,
? typeof data.Income === 'number' ),
? data.Income currency: 'SGD', // assume sgd
: 0 value: data.Income
: 0, ? typeof data.Income === 'number'
? data.Income
: 0
: 0,
},
}, },
startYear: xlSerialToJsDate(
data.Timestamp,
).getFullYear(),
title: jobTitle,
}, },
startYear: xlSerialToJsDate(
data.Timestamp,
).getFullYear(),
title: jobTitle,
}, },
}, },
}, },
}, },
}, });
});
console.log('Profile created:', dataAdded.id); console.log('Profile created:', dataAdded.id);
createdProfileIds.push(dataAdded.id); createdProfileIds.push(dataAdded.id);
} else { } else {
// assume rest full time // assume rest full time
const dataAdded = await prisma.offersProfile.create({ const dataAdded = await prisma.offersProfile.create({
data: { data: {
profileName: uniqueName, profileName: uniqueName,
createdAt: xlSerialToJsDate(data.Timestamp), createdAt: xlSerialToJsDate(data.Timestamp),
editToken: token, editToken: token,
background: { background: {
create: { create: {
totalYoe: yoe, totalYoe: yoe,
},
}, },
}, offers: {
offers: { create: {
create: { comments: data.Comments ?? '',
comments: data.Comments ?? '', company: {
company: { connect: {
connect: { id: companyIdMappings[data.Company],
id: companyIdMappings[data.Company], },
}, },
}, jobType: 'FULLTIME',
jobType: 'FULLTIME', location: {
location: 'Singapore, Singapore', // TODO: DEFAULT AS SG connect: {
monthYearReceived: xlSerialToJsDate(data.Timestamp), id: singapore.id
negotiationStrategy: '', }
offersFullTime: { }, // TODO: DEFAULT AS SG
create: { monthYearReceived: xlSerialToJsDate(data.Timestamp),
baseSalary: { negotiationStrategy: '',
create: { offersFullTime: {
baseCurrency: baseCurrencyString, create: {
baseValue: await convert( baseSalary: {
data.Income create: {
? typeof data.Income === 'number' baseCurrency: baseCurrencyString,
? data.Income baseValue: await convert(
: 0 data.Income
: 0, ? typeof data.Income === 'number'
'SGD', // assume sgd ? data.Income
baseCurrencyString, : 0
), : 0,
currency: 'SGD', // assume sgd 'SGD', // assume sgd
value: data.Income baseCurrencyString,
? typeof data.Income === 'number' ),
? data.Income currency: 'SGD', // assume sgd
: 0 value: data.Income
: 0, ? typeof data.Income === 'number'
? data.Income
: 0
: 0,
},
}, },
}, bonus: {
bonus: { create: {
create: { baseCurrency: baseCurrencyString,
baseCurrency: baseCurrencyString, baseValue: await convert(
baseValue: await convert( data.Bonus
data.Bonus ? typeof data.Bonus === 'number'
? data.Bonus
: 0
: 0,
'SGD',
baseCurrencyString,
),
currency: 'SGD',
value: data.Bonus
? typeof data.Bonus === 'number' ? typeof data.Bonus === 'number'
? data.Bonus ? data.Bonus
: 0 : 0
: 0, : 0,
'SGD', },
baseCurrencyString,
),
currency: 'SGD',
value: data.Bonus
? typeof data.Bonus === 'number'
? data.Bonus
: 0
: 0,
}, },
}, level: level,
level: level, stocks: {
stocks: { create: {
create: { baseCurrency: baseCurrencyString,
baseCurrency: baseCurrencyString, baseValue: await convert(
baseValue: await convert( data.Stocks
data.Stocks ? typeof data.Stocks === 'number'
? data.Stocks
: 0
: 0,
'SGD',
baseCurrencyString,
),
currency: 'SGD',
value: data.Stocks
? typeof data.Stocks === 'number' ? typeof data.Stocks === 'number'
? data.Stocks ? data.Stocks
: 0 : 0
: 0, : 0,
'SGD', },
baseCurrencyString,
),
currency: 'SGD',
value: data.Stocks
? typeof data.Stocks === 'number'
? data.Stocks
: 0
: 0,
}, },
}, title: jobTitle,
title: jobTitle, totalCompensation: {
totalCompensation: { create: {
create: { baseCurrency: baseCurrencyString,
baseCurrency: baseCurrencyString, baseValue: await convert(
baseValue: await convert( data.TC
data.TC ? typeof data.TC === 'number'
? data.TC
: 0
: 0,
'SGD',
baseCurrencyString,
),
currency: 'SGD',
value: data.TC
? typeof data.TC === 'number' ? typeof data.TC === 'number'
? data.TC ? data.TC
: 0 : 0
: 0, : 0,
'SGD', },
baseCurrencyString,
),
currency: 'SGD',
value: data.TC
? typeof data.TC === 'number'
? data.TC
: 0
: 0,
}, },
}, },
}, },
}, },
}, },
}, },
}, });
}); console.log('Profile created:', dataAdded.id);
console.log('Profile created:', dataAdded.id); createdProfileIds.push(dataAdded.id);
createdProfileIds.push(dataAdded.id); }
} else {
console.log('Invalid Company: ' + data.Company);
} }
} else { } else {
console.log('Invalid Company: ' + data.Company); console.log('Invalid TC not a number: ' + data.TC);
} }
} else { }),
console.log('Invalid TC not a number: ' + data.TC); );
} }
}),
);
}; };
const generateAllAnalysis = async () => { const generateAllAnalysis = async () => {

Loading…
Cancel
Save