change seeding now with UserContacts entry

This commit is contained in:
Claus-Peter Hübner 2022-08-31 01:12:12 +02:00
parent f5ee1614f8
commit 852c4e6499
3 changed files with 36 additions and 13 deletions

View File

@ -371,7 +371,7 @@ export class UserResolver {
logger.debug('login credentials valid...')
const user = new User(dbUser, await getUserCreation(dbUser.id))
logger.debug('user=' + user)
logger.debug(`user= ${JSON.stringify(user, null, 2)}`)
// Elopage Status & Stored PublisherId
user.hasElopage = await this.hasElopage({ ...context, user: dbUser })
@ -389,7 +389,7 @@ export class UserResolver {
const ev = new EventLogin()
ev.userId = user.id
eventProtocol.writeEvent(new Event().setEventLogin(ev))
logger.info('successful Login:' + user)
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
return user
}
@ -665,14 +665,14 @@ export class UserResolver {
`email was sent more than ${printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME)} ago`,
)
}
logger.debug('optInCode is valid...')
logger.debug('EmailVerificationCode is valid...')
// load user
const user = await DbUser.findOneOrFail({ id: userContact.userId }).catch(() => {
logger.error('Could not find corresponding Login User')
throw new Error('Could not find corresponding Login User')
})
logger.debug('user with optInCode found...')
logger.debug('user with EmailVerificationCode found...')
// Generate Passphrase if needed
if (!user.passphrase) {
@ -713,12 +713,17 @@ export class UserResolver {
logger.error('error saving user: ' + error)
throw new Error('error saving user: ' + error)
})
// Save userContact
await queryRunner.manager.save(userContact).catch((error) => {
logger.error('error saving userContact: ' + error)
throw new Error('error saving userContact: ' + error)
})
await queryRunner.commitTransaction()
logger.info('User data written successfully...')
logger.info('User and UserContact data written successfully...')
} catch (e) {
await queryRunner.rollbackTransaction()
logger.error('Error on writing User data:' + e)
logger.error('Error on writing User and UserContact data:' + e)
throw e
} finally {
await queryRunner.release()
@ -896,7 +901,7 @@ async function findUserByEmail(email: string): Promise<DbUser> {
throw new Error('No user with this credentials')
})
const userId = dbUserContact.userId
const dbUser = await DbUser.findOneOrFail(userId).catch(() => {
const dbUser = await DbUser.findOneOrFail({ id: userId }, { withDeleted: true }).catch(() => {
logger.error(`User with emailContact=${email} connected per userId=${userId} does not exist`)
throw new Error('No user with this credentials')
})

View File

@ -1,8 +1,8 @@
import { createUser, setPassword } from '@/seeds/graphql/mutations'
import { User } from '@entity/User'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { UserInterface } from '@/seeds/users/UserInterface'
import { ApolloServerTestClient } from 'apollo-server-testing'
import { UserContact } from '@entity/UserContact'
export const userFactory = async (
client: ApolloServerTestClient,
@ -15,17 +15,23 @@ export const userFactory = async (
createUser: { id },
},
} = await mutate({ mutation: createUser, variables: user })
// console.log('creatUser:', { id }, { user })
// get user from database
let dbUser = await User.findOneOrFail({ id })
// console.log('dbUser:', dbUser)
const emailContact = await UserContact.findOneOrFail({ userId: id })
// console.log('emailContact:', emailContact)
if (user.emailChecked) {
const optin = await LoginEmailOptIn.findOneOrFail({ userId: id })
await mutate({
mutation: setPassword,
variables: { password: 'Aa12345_', code: optin.verificationCode },
variables: { password: 'Aa12345_', code: emailContact.emailVerificationCode },
})
}
// get user from database
const dbUser = await User.findOneOrFail({ id })
// get last changes of user from database
dbUser = await User.findOneOrFail({ id })
if (user.createdAt || user.deletedAt || user.isAdmin) {
if (user.createdAt) dbUser.createdAt = user.createdAt
@ -34,5 +40,8 @@ export const userFactory = async (
await dbUser.save()
}
// get last changes of user from database
dbUser = await User.findOneOrFail({ id }, { withDeleted: true })
return dbUser
}

View File

@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { backendLogger as logger } from '@/server/logger'
import createServer from '../server/createServer'
import { createTestClient } from 'apollo-server-testing'
@ -50,11 +51,14 @@ const run = async () => {
const seedClient = createTestClient(server.apollo)
const { con } = server
await cleanDB()
logger.info('##seed## clean database successful...')
// seed the standard users
for (let i = 0; i < users.length; i++) {
await userFactory(seedClient, users[i])
const dbUser = await userFactory(seedClient, users[i])
logger.info(`##seed## seed standard users[ ${i} ]= ${JSON.stringify(dbUser, null, 2)}`)
}
logger.info('##seed## seeding all standard users successful...')
// seed 100 random users
for (let i = 0; i < 100; i++) {
@ -64,7 +68,9 @@ const run = async () => {
email: internet.email(),
language: datatype.boolean() ? 'en' : 'de',
})
logger.info(`##seed## seed ${i}. random user`)
}
logger.info('##seed## seeding all random users successful...')
// create GDD
for (let i = 0; i < creations.length; i++) {
@ -73,16 +79,19 @@ const run = async () => {
// eslint-disable-next-line no-empty
while (new Date().getTime() < now + 1000) {} // we have to wait a little! quick fix for account sum problem of bob@baumeister.de, (see https://github.com/gradido/gradido/issues/1886)
}
logger.info('##seed## seeding all creations successful...')
// create Transaction Links
for (let i = 0; i < transactionLinks.length; i++) {
await transactionLinkFactory(seedClient, transactionLinks[i])
}
logger.info('##seed## seeding all transactionLinks successful...')
// create Contribution Links
for (let i = 0; i < contributionLinks.length; i++) {
await contributionLinkFactory(seedClient, contributionLinks[i])
}
logger.info('##seed## seeding all contributionLinks successful...')
await con.close()
}