From 2279d59fb7814af04ecfefe274b62e995e71f41f Mon Sep 17 00:00:00 2001 From: helloanil Date: Thu, 17 Feb 2022 19:43:34 +0100 Subject: [PATCH 01/14] Add Tp Data Seeding with bug :) Co-authored-by: Lorenzo --- apps/api/scripts/link-roles-to-users.js | 53 ++++--- apps/api/scripts/seed-database.js | 188 ++++++++++++++++++++---- 2 files changed, 197 insertions(+), 44 deletions(-) diff --git a/apps/api/scripts/link-roles-to-users.js b/apps/api/scripts/link-roles-to-users.js index 26b3efb0d..8e69c1e89 100644 --- a/apps/api/scripts/link-roles-to-users.js +++ b/apps/api/scripts/link-roles-to-users.js @@ -1,25 +1,19 @@ const { bindNodeCallback, from } = require('rxjs') -const { - switchMap, - concatMap, - map, - tap, - count -} = require('rxjs/operators') +const { switchMap, concatMap, map, tap, count } = require('rxjs/operators') const app = require('../server/server') const { Role, RedUser, RoleMapping } = app.models const roleFindOne = bindNodeCallback(Role.findOne.bind(Role)) const userFind = bindNodeCallback(RedUser.find.bind(RedUser)) -const rolePrincipalCreate = role => +const rolePrincipalCreate = (role) => bindNodeCallback(role.principals.create.bind(role)) -let menteeRole, mentorRole, adminRole +let menteeRole, mentorRole, adminRole, companyRole, jobseekerRole roleFindOne({ where: { name: 'mentee' } }) .pipe( - map(menteeRole => ({ menteeRole })), + map((menteeRole) => ({ menteeRole })), switchMap( () => roleFindOne({ where: { name: 'mentor' } }), (data, mentorRole) => ({ ...data, mentorRole }) @@ -28,33 +22,54 @@ roleFindOne({ where: { name: 'mentee' } }) () => roleFindOne({ where: { name: 'admin' } }), (data, adminRole) => ({ ...data, adminRole }) ), + switchMap( + () => roleFindOne({ where: { name: 'company' } }), + (data, companyRole) => ({ ...data, companyRole }) + ), + switchMap( + () => roleFindOne({ where: { name: 'jobseeker' } }), + (data, jobseekerRole) => ({ ...data, jobseekerRole }) + ), tap( ({ mentorRole: _mentorRole, menteeRole: _menteeRole, - adminRole: _adminRole + adminRole: _adminRole, + companyRole: _companyRole, + jobseekerRole: _jobseekerRole, }) => { menteeRole = _menteeRole mentorRole = _mentorRole adminRole = _adminRole + companyRole = _companyRole + jobseekerRole = _jobseekerRole } ), switchMap(() => userFind({ include: 'redProfile' })), - switchMap(users => from(users)), - concatMap(user => { - let role - const userType = user.toJSON().redProfile.userType - const accountEmail = user.toJSON().email - if (accountEmail === 'cloud-accounts@redi-school.org') { + switchMap((users) => from(users)), + concatMap((user) => { + let role, userType + const userJSON = user.toJSON() + + if (userJSON.redProfile) userType = userJSON.redProfile.userType + else if (userJSON.tpCompanyProfile) userType = 'tpCompany' + else if (userJSON.tpJobseekerProfile) userType = 'tpJobseeker' + + if (userJSON.email === 'cloud-accounts@redi-school.org') { role = adminRole } else if (userType === 'mentor') { role = mentorRole - } else { + } else if (userType === 'mentee') { role = menteeRole + } else if (userType === 'tpCompany') { + role = tpCompanyRole + } else if (userType === 'tpJobseeker') { + role = tpJobseekerRole } + return rolePrincipalCreate(role)({ principalType: RoleMapping.USER, - principalId: user.toJSON().id + principalId: user.toJSON().id, }) }), count() diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index c33f99a5f..df576556c 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -22,20 +22,24 @@ const { AccessToken, Role, RoleMapping, + TpCompanyProfile, + TpJobListing, + TpJobseekerProfile, } = app.models -const personsRaw = require('./random-names.json') -const persons = [] -personsRaw.forEach((person) => { - for (let i = 1; i <= 5; i++) { - persons.push({ - name: `${person.name}${i}`, - surname: `${person.surname}${i}`, - gender: person.gender, - region: person.region, - }) - } -}) +const persons = require('./random-names.json') + +// const persons = [] +// personsRaw.forEach((person) => { +// for (let i = 1; i <= 5; i++) { +// persons.push({ +// name: `${person.name}${i}`, +// surname: `${person.surname}${i}`, +// gender: person.gender, +// region: person.region, +// }) +// } +// }) const categories = [ { @@ -174,14 +178,6 @@ const categories = [ const Languages = ['German', 'Arabic', 'Farsi', 'Tigrinya'] -const genders = [ - { id: 'male', label: 'Male' }, - { id: 'female', label: 'Female' }, - { id: 'other', label: 'Other' }, -] - -const menteeCountCapacityOptions = [1, 2, 3, 4] - const educationLevels = [ { id: 'middleSchool', label: 'Middle School' }, { id: 'highSchool', label: 'High School' }, @@ -236,11 +232,11 @@ const pickRandomUserType = () => { } const users = fp.compose( - fp.take(1000), + fp.take(5), fp.map(({ name, surname, gender }) => { const rediLocation = Math.random() > 0.5 ? 'berlin' : Math.random() > 0.5 ? 'munich' : 'nrw' - const email = randomString() + '@' + randomString() + '.com' + const email = `${name.toLowerCase()}@${surname.toLowerCase()}.com` const password = email return { redUser: { @@ -295,6 +291,57 @@ const users = fp.compose( }) )(persons) +const possibleTpStates = [ + 'drafting-profile', + 'submitted-for-review', + 'profile-approved', +] + +const tpCompanyUsers = fp.compose( + fp.take(5), + fp.map(({ name, surname }) => { + const email = `${randomString()}@${randomString()}.com` + const password = email + return { + redUser: { + email, + password, + }, + tpCompanyProfile: { + firstName: name, + lastName: surname, + contactEmail: `${name.toLowerCase()}@${surname.toLowerCase()}.com`, + companyName: `${surname} ACME Company`, + state: + possibleTpStates[Math.floor(Math.random() * possibleTpStates.length)], + howDidHearAboutRediKey: 'redi-team-member', + }, + } + }) +)(persons) + +const tpJobseekerUsers = fp.compose( + fp.takeRight(5), + fp.map(({ name, surname }) => { + const email = `${randomString()}@${randomString()}.com` + const password = email + return { + redUser: { + email, + password, + }, + tpJobseekerProfile: { + firstName: name, + lastName: surname, + contactEmail: `${name.toLowerCase()}@${surname.toLowerCase()}.com`, + state: + possibleTpStates[Math.floor(Math.random() * possibleTpStates.length)], + currentlyEnrolledInCourse: 'react', + }, + } + }) +)(persons) + const accessTokenDestroyAll = Rx.bindNodeCallback( AccessToken.destroyAll.bind(AccessToken) ) @@ -313,6 +360,15 @@ const redMatchDestroyAll = Rx.bindNodeCallback( const redMentoringSessionDestroyAll = Rx.bindNodeCallback( RedMentoringSession.destroyAll.bind(RedMentoringSession) ) +const tpCompanyProfileDestroyAll = Rx.bindNodeCallback( + TpCompanyProfile.destroyAll.bind(TpCompanyProfile) +) +const tpJobseekerProfileDestroyAll = Rx.bindNodeCallback( + TpJobseekerProfile.destroyAll.bind(TpJobseekerProfile) +) +const tpJobListingDestroyAll = Rx.bindNodeCallback( + TpJobListing.destroyAll.bind(TpJobListing) +) const redMatchCreate = (redMatch) => Rx.bindNodeCallback(RedMatch.create.bind(RedMatch))(redMatch) @@ -323,6 +379,19 @@ const redProfileCreateOnRedUser = (redUserInst) => (redProfile) => redProfile ) +const tpJobListingCreate = (tpJobListing) => + Rx.bindNodeCallback(tpJobListing.create.bind(TpJobListing))(tpJobListing) + +const tpCompanyProfileCreateOnRedUser = (redUserInst) => (tpCompanyProfile) => + Rx.bindNodeCallback(redUserInst.tpCompanyProfile.create.bind(redUserInst))( + tpCompanyProfile + ) +const tpJobseekerProfileCreateOnRedUser = + (redUserInst) => (tpJobseekerProfile) => + Rx.bindNodeCallback( + redUserInst.tpJobseekerProfile.create.bind(redUserInst) + )(tpJobseekerProfile) + const ericMenteeRedUser = { password: 'career+testmentee@redi-school.org', email: 'career+testmentee@redi-school.org', @@ -446,6 +515,31 @@ const ericAdminRedProfile = { username: 'cloud-accounts@redi-school.org', } +const testTpCompanyRedUser = { + email: 'john+doe@test-company.org', + password: 'john+doe@test-company.org', +} +const testTpCompanyProfile = { + firstName: 'John', + lastName: 'Doe', + contactEmail: 'john+doe@test-company.org', + companyName: 'Test Company', + state: 'drafting-profile', + howDidHearAboutRediKey: 'redi-team-member', +} + +const testTpJobseekerRedUser = { + email: 'jane+doe@test-jobseeker.com', + password: 'jane+doe@test-jobseeker.com', +} +const testTpJobseekerProfile = { + firstName: 'Test', + lastName: 'Jobseeker', + contactEmail: 'jane+doe@test-jobseeker.com', + state: 'drafting-profile', + currentlyEnrolledInCourse: 'react', +} + Rx.of({}) .pipe( switchMap(accessTokenDestroyAll), @@ -454,6 +548,9 @@ Rx.of({}) switchMap(redMatchDestroyAll), switchMap(redUserDestroyAll), switchMap(redProfileDestroyAll), + switchMap(tpCompanyProfileDestroyAll), + switchMap(tpJobseekerProfileDestroyAll), + switchMap(tpJobListingDestroyAll), tap(() => console.log('destroyed')), delay(10000), // switchMap(redMentoringSessionDestroyAll), @@ -466,12 +563,20 @@ Rx.of({}) redProfileCreateOnRedUser(redUser)(ericMenteeRedProfile) ), switchMap(() => redUserCreate(ericMentorRedUser)), - tap(console.log), switchMap((redUser) => redProfileCreateOnRedUser(redUser)(ericMentorRedProfile) ), - switchMapTo(users), + switchMap(() => redUserCreate(testTpCompanyRedUser)), + switchMap((redUser) => + tpCompanyProfileCreateOnRedUser(redUser)(testTpCompanyProfile) + ), + switchMap(() => redUserCreate(testTpJobseekerRedUser)), + switchMap((redUser) => + tpJobseekerProfileCreateOnRedUser(redUser)(testTpJobseekerProfile) + ), + switchMapTo(users), // switchMap(() => users) concatMap( + // users.map( (userData) => {} ) (userData) => redUserCreate(userData.redUser), (userData, redUserInst) => ({ ...userData, redUserInst }) ), @@ -527,7 +632,40 @@ Rx.of({}) } return Rx.from(matchesFlat) }), - concatMap(redMatchCreate) + concatMap(redMatchCreate), + // seed talent pool db + switchMapTo(tpJobseekerUsers), + tap(console.log), + concatMap( + (userData) => redUserCreate(userData.redUser), + (userData, redUserInst) => ({ ...userData, redUserInst }) + ), + concatMap( + (userData) => + tpJobseekerProfileCreateOnRedUser(userData.redUserInst)( + userData.tpJobseekerProfile + ), + (userData, tpJobseekerProfileInst) => ({ + ...userData, + tpJobseekerProfileInst, + }) + ), + switchMapTo(tpCompanyUsers), + tap(console.log), + concatMap( + (userData) => redUserCreate(userData.redUser), + (userData, redUserInst) => ({ ...userData, redUserInst }) + ), + concatMap( + (userData) => + tpCompanyProfileCreateOnRedUser(userData.redUserInst)( + userData.tpCompanyProfile + ), + (userData, tpCompanyProfileInst) => ({ + ...userData, + tpCompanyProfileInst, + }) + ) ) .subscribe( () => console.log('next'), From 379ad784cd3f1bfa93e4fe1a5eedde1750fac5d8 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 09:18:13 +0100 Subject: [PATCH 02/14] [chore] log entry location/mentor/ee --- apps/api/scripts/seed-database.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index df576556c..11979a3ba 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -605,17 +605,14 @@ Rx.of({}) const menteesInLocation = mentees.filter( (data) => data.redProfile.rediLocation === location ) - console.log('******************************') - console.log('location', location) - console.log(mentorsInLocation.length) - console.log(menteesInLocation.length) - console.log('******************************') + console.log( + `Location: ${location}, #mentors: ${mentorsInLocation.length}, #mentees: ${menteesInLocation.length}` + ) const matches = mentorsInLocation.map((mentor) => { return _.sampleSize( menteesInLocation, Math.floor(Math.random() * 10) ).map((mentee) => { - console.log(location) return { rediLocation: '' + location + '', applicationText: randomString(), From 125ac118bd0f02666fefe4f1cda14d3289791d14 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 09:19:25 +0100 Subject: [PATCH 03/14] [chore] log each pipe section --- apps/api/scripts/seed-database.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index 11979a3ba..fedfcd62b 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -542,6 +542,8 @@ const testTpJobseekerProfile = { Rx.of({}) .pipe( + tap(() => console.log('******** Start Seed DB ***********************')), + tap(() => console.log('------ Destroy -------------------------------')), switchMap(accessTokenDestroyAll), switchMap(roleDestroyAll), switchMap(roleMappingDestroyAll), @@ -551,9 +553,10 @@ Rx.of({}) switchMap(tpCompanyProfileDestroyAll), switchMap(tpJobseekerProfileDestroyAll), switchMap(tpJobListingDestroyAll), - tap(() => console.log('destroyed')), + tap(() => console.log('--- DONE Destroy -----------------------------')), delay(10000), // switchMap(redMentoringSessionDestroyAll), + tap(() => console.log('------ Create Test Users ---------------------')), switchMap(() => redUserCreate(ericAdminUser)), switchMap((redUser) => redProfileCreateOnRedUser(redUser)(ericAdminRedProfile) @@ -574,6 +577,8 @@ Rx.of({}) switchMap((redUser) => tpJobseekerProfileCreateOnRedUser(redUser)(testTpJobseekerProfile) ), + tap(() => console.log('--- DONE Create Test Users -------------------')), + tap(() => console.log('------ Create All Users ----------------------')), switchMapTo(users), // switchMap(() => users) concatMap( // users.map( (userData) => {} ) @@ -586,6 +591,8 @@ Rx.of({}) (userData, redProfileInst) => ({ ...userData, redProfileInst }) ), toArray(), + tap(() => console.log('--- DONE Create All Users --------------------')), + tap(() => console.log('------ Create Match Mentor-Mentee Pairs ------')), // Pick X mentor-mentee pairs, create match switchMap((data) => { const mentors = data.filter( @@ -630,7 +637,10 @@ Rx.of({}) return Rx.from(matchesFlat) }), concatMap(redMatchCreate), + tap(() => console.log('--- DONE Create Match Mentor-Mentee Pairs ----')), + tap(() => console.log('------ Seed Talent Pool DB -------------------')), // seed talent pool db + tap(() => console.log('------ tpJobseekerUsers ----------------------')), switchMapTo(tpJobseekerUsers), tap(console.log), concatMap( @@ -663,12 +673,13 @@ Rx.of({}) tpCompanyProfileInst, }) ) + tap(() => console.log('--- DONE Seed Talent Pool DB -----------------')) ) .subscribe( () => console.log('next'), console.log, () => { - console.log('done') + console.log('***** DONE Seed DB ***************************') process.exit() } ) From c0478bd35d8bd11a8b5c376821886bc93b10605f Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 09:20:12 +0100 Subject: [PATCH 04/14] [chore] roles log pipe sections --- apps/api/scripts/create-roles.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/api/scripts/create-roles.js b/apps/api/scripts/create-roles.js index f2eb9482d..e7f09240e 100644 --- a/apps/api/scripts/create-roles.js +++ b/apps/api/scripts/create-roles.js @@ -1,5 +1,5 @@ const { bindNodeCallback, from } = require('rxjs') -const { concatMap } = require('rxjs/operators') +const { concatMap, tap } = require('rxjs/operators') const app = require('../server/server') const { Role } = app.models @@ -8,6 +8,13 @@ const roleCreate = bindNodeCallback(Role.create.bind(Role)) const roles = ['admin', 'mentee', 'mentor', 'jobseeker', 'company'] +console.log('****** Create Roles **************************') from(roles) - .pipe(concatMap((role) => roleCreate({ name: role }))) - .subscribe(console.log, null, () => process.exit()) + .pipe( + tap((role) => console.log(`role ${role}`)), + concatMap((role) => roleCreate({ name: role })) + ) + .subscribe(console.log, null, () => { + console.log('*** DONE Create Roles ************************') + process.exit() + }) From b3c379bd02baef9818b4b0ff02ef25e95e1b5467 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 11:08:08 +0100 Subject: [PATCH 05/14] [fix] create-roles on second db seed run For some reason the roles are not deleted if destroyAll is in seed-db --- apps/api/scripts/create-roles.js | 24 ++++++++++++++++++------ apps/api/scripts/seed-database.js | 2 -- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/api/scripts/create-roles.js b/apps/api/scripts/create-roles.js index e7f09240e..9b1d5bdd7 100644 --- a/apps/api/scripts/create-roles.js +++ b/apps/api/scripts/create-roles.js @@ -1,20 +1,32 @@ const { bindNodeCallback, from } = require('rxjs') -const { concatMap, tap } = require('rxjs/operators') +const Rx = require('rxjs') +const { concatMap, switchMap, switchMapTo, tap } = require('rxjs/operators') const app = require('../server/server') const { Role } = app.models +const roleDestroyAll = Rx.bindNodeCallback(Role.destroyAll.bind(Role)) const roleCreate = bindNodeCallback(Role.create.bind(Role)) +const roleListAll = bindNodeCallback(Role.find.bind(Role)) const roles = ['admin', 'mentee', 'mentor', 'jobseeker', 'company'] -console.log('****** Create Roles **************************') -from(roles) +Rx.of({}) .pipe( - tap((role) => console.log(`role ${role}`)), - concatMap((role) => roleCreate({ name: role })) + tap(() => console.log('********** Create Roles **********************')), + tap(() => console.log('-------- Destroy Old List roles --------------')), + switchMap(roleDestroyAll), + tap(() => console.log('-------- List roles after destroy ------------')), + switchMap(roleListAll), + tap(console.log), + tap(() => console.log('--- DONE Destroy List Roles ------------------')), + tap(() => console.log('-------- Create New Roles --------------------')), + switchMapTo(roles), + // tap((role) => console.log(`role ${role}`)), + concatMap((role) => roleCreate({ name: role })), + tap(() => console.log('--- DONE Create New Roles --------------------')) ) .subscribe(console.log, null, () => { - console.log('*** DONE Create Roles ************************') + console.log('*** DONE Create Roles **********************') process.exit() }) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index fedfcd62b..fa1f1ff4b 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -345,7 +345,6 @@ const tpJobseekerUsers = fp.compose( const accessTokenDestroyAll = Rx.bindNodeCallback( AccessToken.destroyAll.bind(AccessToken) ) -const roleDestroyAll = Rx.bindNodeCallback(Role.destroyAll.bind(Role)) const roleMappingDestroyAll = Rx.bindNodeCallback( RoleMapping.destroyAll.bind(RoleMapping) ) @@ -545,7 +544,6 @@ Rx.of({}) tap(() => console.log('******** Start Seed DB ***********************')), tap(() => console.log('------ Destroy -------------------------------')), switchMap(accessTokenDestroyAll), - switchMap(roleDestroyAll), switchMap(roleMappingDestroyAll), switchMap(redMatchDestroyAll), switchMap(redUserDestroyAll), From 5a7abc25175105d20a4e2331c82c6c51f183d34c Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 11:10:41 +0100 Subject: [PATCH 06/14] [chore] remove log entry create roles --- apps/api/scripts/create-roles.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/api/scripts/create-roles.js b/apps/api/scripts/create-roles.js index 9b1d5bdd7..da90d1747 100644 --- a/apps/api/scripts/create-roles.js +++ b/apps/api/scripts/create-roles.js @@ -23,8 +23,7 @@ Rx.of({}) tap(() => console.log('-------- Create New Roles --------------------')), switchMapTo(roles), // tap((role) => console.log(`role ${role}`)), - concatMap((role) => roleCreate({ name: role })), - tap(() => console.log('--- DONE Create New Roles --------------------')) + concatMap((role) => roleCreate({ name: role })) ) .subscribe(console.log, null, () => { console.log('*** DONE Create Roles **********************') From c51a220d91ba8edec8a07088fe5af5511ac4f5e8 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 11:12:19 +0100 Subject: [PATCH 07/14] [fix] typo with userType / role tpCompany<>companyRole tpJobseeker<>jobseekerRole --- apps/api/scripts/link-roles-to-users.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/scripts/link-roles-to-users.js b/apps/api/scripts/link-roles-to-users.js index 8e69c1e89..f8fdfe2e4 100644 --- a/apps/api/scripts/link-roles-to-users.js +++ b/apps/api/scripts/link-roles-to-users.js @@ -62,9 +62,9 @@ roleFindOne({ where: { name: 'mentee' } }) } else if (userType === 'mentee') { role = menteeRole } else if (userType === 'tpCompany') { - role = tpCompanyRole + role = companyRole } else if (userType === 'tpJobseeker') { - role = tpJobseekerRole + role = jobseekerRole } return rolePrincipalCreate(role)({ From 184d7296d32d9a947faf948c960fa27cc0d2b359 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 11:56:54 +0100 Subject: [PATCH 08/14] [fix] role undef when userType not standard --- apps/api/scripts/link-roles-to-users.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/api/scripts/link-roles-to-users.js b/apps/api/scripts/link-roles-to-users.js index f8fdfe2e4..d9b0996ba 100644 --- a/apps/api/scripts/link-roles-to-users.js +++ b/apps/api/scripts/link-roles-to-users.js @@ -65,6 +65,9 @@ roleFindOne({ where: { name: 'mentee' } }) role = companyRole } else if (userType === 'tpJobseeker') { role = jobseekerRole + } else { + // e.g. public-sign-up-mentee-pending-review + role = menteeRole } return rolePrincipalCreate(role)({ From 83757402899c4ee3d341dbfa8c804c0ec0e4ac90 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 12:02:22 +0100 Subject: [PATCH 09/14] [fix] missing comma --- apps/api/scripts/seed-database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index fa1f1ff4b..64c8db585 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -670,7 +670,7 @@ Rx.of({}) ...userData, tpCompanyProfileInst, }) - ) + ), tap(() => console.log('--- DONE Seed Talent Pool DB -----------------')) ) .subscribe( From 894a50be03e7cc9137685fbf0543eb628e700608 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 12:03:09 +0100 Subject: [PATCH 10/14] [chore] add log entry for tpJobseekerUsers --- apps/api/scripts/seed-database.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index 64c8db585..ae6c4489b 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -655,6 +655,7 @@ Rx.of({}) tpJobseekerProfileInst, }) ), + tap(() => console.log('--- tpJobseekerUsers -------------------------')), switchMapTo(tpCompanyUsers), tap(console.log), concatMap( From bb740d94336ab69296db6ab7abca44131e72bfb1 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 22:28:09 +0100 Subject: [PATCH 11/14] [fix] break the pipe for each map --- apps/api/scripts/seed-database.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index ae6c4489b..75f33647e 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -635,6 +635,7 @@ Rx.of({}) return Rx.from(matchesFlat) }), concatMap(redMatchCreate), + toArray(), // tap(() => console.log('--- DONE Create Match Mentor-Mentee Pairs ----')), tap(() => console.log('------ Seed Talent Pool DB -------------------')), // seed talent pool db @@ -655,7 +656,8 @@ Rx.of({}) tpJobseekerProfileInst, }) ), - tap(() => console.log('--- tpJobseekerUsers -------------------------')), + toArray(), // + tap(() => console.log('--- tpCompanyUsers -------------------------')), switchMapTo(tpCompanyUsers), tap(console.log), concatMap( @@ -672,6 +674,7 @@ Rx.of({}) tpCompanyProfileInst, }) ), + toArray(), // tap(() => console.log('--- DONE Seed Talent Pool DB -----------------')) ) .subscribe( From 75ecc00768b50509147d4d65dd81827fafe950a2 Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 22:28:35 +0100 Subject: [PATCH 12/14] [chore] remove unused Role --- apps/api/scripts/seed-database.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index 75f33647e..85863522c 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -20,7 +20,6 @@ const { RedMatch, RedMentoringSession, AccessToken, - Role, RoleMapping, TpCompanyProfile, TpJobListing, From d6342b8c6e0d879efdbc490c4ba414efa525f18d Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 22:43:06 +0100 Subject: [PATCH 13/14] [impl] better fake data for company/jobseeker --- apps/api/scripts/seed-database.js | 70 ++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index 85863522c..4a1c01dda 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -219,6 +219,14 @@ const randomString = (charset = 'abcdefghijklmnopqrstuvwxyz', length = 10) => { return str } +const randomEmail = (name, surname) => { + return `${name.toLowerCase()}.${surname.toLowerCase()}_${randomString()}@${surname.toLowerCase()}.com` +} + +const pickRandomCourseId = () => { + return courses[Math.floor(Math.random() * courses.length)].id +} + const pickRandomUserType = () => { const possibleUserTypes = [ 'mentor', @@ -231,7 +239,7 @@ const pickRandomUserType = () => { } const users = fp.compose( - fp.take(5), + fp.take(25), fp.map(({ name, surname, gender }) => { const rediLocation = Math.random() > 0.5 ? 'berlin' : Math.random() > 0.5 ? 'munich' : 'nrw' @@ -283,23 +291,49 @@ const users = fp.compose( mentee_highestEducationLevel: educationLevels[Math.floor(Math.random() * educationLevels.length)] .id, - mentee_currentlyEnrolledInCourse: - courses[Math.floor(Math.random() * courses.length)].id, + mentee_currentlyEnrolledInCourse: pickRandomCourseId(), }, } }) )(persons) -const possibleTpStates = [ - 'drafting-profile', - 'submitted-for-review', - 'profile-approved', -] +const pickRandomPossibleTpStates = () => { + const possibleTpStates = [ + 'drafting-profile', + 'submitted-for-review', + 'profile-approved', + ] + const randomIndex = Math.floor(Math.random() * possibleTpStates.length) + return possibleTpStates[randomIndex] +} + +const pickRandomHowDidHearAboutRedi = () => { + const possibleHowDidHearAboutRedi = [ + 'redi-team-member', + 'redi-student-alumni', + 'redi-website', + 'collegue', + 'already-volunteer-at-redi', + 'internet-search', + 'social-media', + 'other', + ] + const randomIndex = Math.floor( + Math.random() * possibleHowDidHearAboutRedi.length + ) + return possibleHowDidHearAboutRedi[randomIndex] +} + +const pickRandomCompanyType = () => { + const possibleCompanyType = ['GbR', 'UG', 'AG', 'GbR', 'GmbH'] + const randomIndex = Math.floor(Math.random() * possibleCompanyType.length) + return possibleCompanyType[randomIndex] +} const tpCompanyUsers = fp.compose( fp.take(5), fp.map(({ name, surname }) => { - const email = `${randomString()}@${randomString()}.com` + const email = randomEmail(name, surname) const password = email return { redUser: { @@ -309,11 +343,10 @@ const tpCompanyUsers = fp.compose( tpCompanyProfile: { firstName: name, lastName: surname, - contactEmail: `${name.toLowerCase()}@${surname.toLowerCase()}.com`, - companyName: `${surname} ACME Company`, - state: - possibleTpStates[Math.floor(Math.random() * possibleTpStates.length)], - howDidHearAboutRediKey: 'redi-team-member', + contactEmail: email, + companyName: `${surname} ${pickRandomCompanyType()}`, + state: pickRandomPossibleTpStates(), + howDidHearAboutRediKey: pickRandomHowDidHearAboutRedi(), }, } }) @@ -322,7 +355,7 @@ const tpCompanyUsers = fp.compose( const tpJobseekerUsers = fp.compose( fp.takeRight(5), fp.map(({ name, surname }) => { - const email = `${randomString()}@${randomString()}.com` + const email = randomEmail(name, surname) const password = email return { redUser: { @@ -332,10 +365,9 @@ const tpJobseekerUsers = fp.compose( tpJobseekerProfile: { firstName: name, lastName: surname, - contactEmail: `${name.toLowerCase()}@${surname.toLowerCase()}.com`, - state: - possibleTpStates[Math.floor(Math.random() * possibleTpStates.length)], - currentlyEnrolledInCourse: 'react', + contactEmail: email, + state: pickRandomPossibleTpStates(), + currentlyEnrolledInCourse: pickRandomCourseId(), }, } }) From bd3fb9d6fd8fd3a642179361786dfad43189a9cd Mon Sep 17 00:00:00 2001 From: lorenzo Date: Sat, 19 Feb 2022 22:43:38 +0100 Subject: [PATCH 14/14] [chore] remove log entries --- apps/api/scripts/seed-database.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/scripts/seed-database.js b/apps/api/scripts/seed-database.js index 4a1c01dda..39e84e8cc 100644 --- a/apps/api/scripts/seed-database.js +++ b/apps/api/scripts/seed-database.js @@ -672,7 +672,7 @@ Rx.of({}) // seed talent pool db tap(() => console.log('------ tpJobseekerUsers ----------------------')), switchMapTo(tpJobseekerUsers), - tap(console.log), + // tap(console.log), concatMap( (userData) => redUserCreate(userData.redUser), (userData, redUserInst) => ({ ...userData, redUserInst }) @@ -690,7 +690,7 @@ Rx.of({}) toArray(), // tap(() => console.log('--- tpCompanyUsers -------------------------')), switchMapTo(tpCompanyUsers), - tap(console.log), + // tap(console.log), concatMap( (userData) => redUserCreate(userData.redUser), (userData, redUserInst) => ({ ...userData, redUserInst })