mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-04-08 13:29:17 +08:00
[offers][fix] Extract seed analysis out and make it sequential
This commit is contained in:
@@ -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": {
|
||||
|
||||
37
apps/portal/prisma/seed-analysis.ts
Normal file
37
apps/portal/prisma/seed-analysis.ts
Normal file
@@ -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 {};
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user