[offers][fix] integrate random name generator to profile seeding

pull/501/head
Stuart Long Chay Boon 3 years ago
parent 221137bd87
commit 5f0e5b3d54

@ -4,6 +4,7 @@ import crypto from 'crypto';
import { baseCurrencyString } from '../src/utils/offers/currency';
import { convert } from '../src/utils/offers/currency/currencyExchange';
import { generateAnalysis } from '../src/utils/offers/analysisGeneration';
import generateRandomName from '../src/utils/offers/randomNameGenerator';
const prisma = new PrismaClient();
@ -68,11 +69,15 @@ const seedSalaries = async () => {
.createHash('sha256')
.update(xlSerialToJsDate(data.Timestamp).toString())
.digest('hex');
// Generate random name until unique
let uniqueName: string = await generateRandomName();
if (data.Type.toUpperCase() === 'INTERNSHIP') {
// create profile
const dataAdded = await prisma.offersProfile.create({
data: {
profileName: crypto.randomUUID().substring(0, 10),
profileName: uniqueName,
createdAt: xlSerialToJsDate(data.Timestamp),
editToken: token,
background: {

@ -0,0 +1,33 @@
import type { Config } from 'unique-names-generator';
import { adjectives, animals,colors, uniqueNamesGenerator } from 'unique-names-generator';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient()
const customConfig: Config = {
dictionaries: [adjectives, colors, animals],
length: 3,
separator: '-',
};
export default async function generateRandomName(): Promise<string> {
let uniqueName: string = uniqueNamesGenerator(customConfig);
let sameNameProfiles = await prisma.offersProfile.findMany({
where: {
profileName: uniqueName
}
})
while (sameNameProfiles.length !== 0) {
uniqueName = uniqueNamesGenerator(customConfig);
sameNameProfiles = await prisma.offersProfile.findMany({
where: {
profileName: uniqueName
}
})
}
return uniqueName
}
Loading…
Cancel
Save