diff --git a/apps/portal/package.json b/apps/portal/package.json index fb8b60b9..cdec2c9c 100644 --- a/apps/portal/package.json +++ b/apps/portal/package.json @@ -11,6 +11,7 @@ "postinstall": "prisma generate", "seed": "ts-node prisma/seed.ts", "seed-salaries": "ts-node prisma/seed-salaries.ts", + "seed-analysis": "ts-node prisma/seed-analysis.ts", "seed-questions": "ts-node prisma/seed-questions.ts" }, "dependencies": { diff --git a/apps/portal/prisma/seed-analysis.ts b/apps/portal/prisma/seed-analysis.ts new file mode 100644 index 00000000..929443dc --- /dev/null +++ b/apps/portal/prisma/seed-analysis.ts @@ -0,0 +1,37 @@ +import { PrismaClient } from '@prisma/client'; +import { generateAnalysis } from '../src/utils/offers/analysis/analysisGeneration'; + +const prisma = new PrismaClient(); + +const seedAnalysis = async () => { + console.log('Busy crunching analysis.....'); + + const profilesWithoutAnalysis = await prisma.offersProfile.findMany({ + where: { + analysis: { + is: null, + }, + }, + }); + + for (const profile of profilesWithoutAnalysis) { + await generateAnalysis({ + ctx: { prisma, session: null }, + input: { profileId: profile.id }, + }); + console.log('Analysis generated for profile with id:', profile.id); + } +}; + +Promise.all([seedAnalysis()]) + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + console.log('Analysis stopping!'); + await prisma.$disconnect(); + process.exit(1); + }); + +export {}; diff --git a/apps/portal/prisma/seed-salaries.ts b/apps/portal/prisma/seed-salaries.ts index 369ea51d..5988c77d 100644 --- a/apps/portal/prisma/seed-salaries.ts +++ b/apps/portal/prisma/seed-salaries.ts @@ -3,7 +3,6 @@ import { PrismaClient } from '@prisma/client'; 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/analysis/analysisGeneration'; import { generateRandomName, @@ -344,26 +343,9 @@ const seedSalaries = async () => { } }; -const generateAllAnalysis = async () => { - return await Promise.all( - createdProfileIds.map(async (profileId) => { - await generateAnalysis({ - ctx: { prisma, session: null }, - input: { profileId }, - }); - console.log('Analysis generated for profile with id:', profileId); - }), - ); -}; - Promise.all([seedSalaries()]) .then(() => { console.log(createdProfileIds.length + ' profiles created'); - console.log('Busy crunching analysis.....'); - }) - .then(() => generateAllAnalysis()) - .then((_data) => { - console.log('Seeding from salaries sheet complete'); }) .then(async () => { await prisma.$disconnect();