mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
change seeding now with UserContacts entry
This commit is contained in:
parent
f5ee1614f8
commit
852c4e6499
@ -371,7 +371,7 @@ export class UserResolver {
|
|||||||
logger.debug('login credentials valid...')
|
logger.debug('login credentials valid...')
|
||||||
|
|
||||||
const user = new User(dbUser, await getUserCreation(dbUser.id))
|
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
|
// Elopage Status & Stored PublisherId
|
||||||
user.hasElopage = await this.hasElopage({ ...context, user: dbUser })
|
user.hasElopage = await this.hasElopage({ ...context, user: dbUser })
|
||||||
@ -389,7 +389,7 @@ export class UserResolver {
|
|||||||
const ev = new EventLogin()
|
const ev = new EventLogin()
|
||||||
ev.userId = user.id
|
ev.userId = user.id
|
||||||
eventProtocol.writeEvent(new Event().setEventLogin(ev))
|
eventProtocol.writeEvent(new Event().setEventLogin(ev))
|
||||||
logger.info('successful Login:' + user)
|
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,14 +665,14 @@ export class UserResolver {
|
|||||||
`email was sent more than ${printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME)} ago`,
|
`email was sent more than ${printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME)} ago`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
logger.debug('optInCode is valid...')
|
logger.debug('EmailVerificationCode is valid...')
|
||||||
|
|
||||||
// load user
|
// load user
|
||||||
const user = await DbUser.findOneOrFail({ id: userContact.userId }).catch(() => {
|
const user = await DbUser.findOneOrFail({ id: userContact.userId }).catch(() => {
|
||||||
logger.error('Could not find corresponding Login User')
|
logger.error('Could not find corresponding Login User')
|
||||||
throw new 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
|
// Generate Passphrase if needed
|
||||||
if (!user.passphrase) {
|
if (!user.passphrase) {
|
||||||
@ -713,12 +713,17 @@ export class UserResolver {
|
|||||||
logger.error('error saving user: ' + error)
|
logger.error('error saving user: ' + error)
|
||||||
throw new 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()
|
await queryRunner.commitTransaction()
|
||||||
logger.info('User data written successfully...')
|
logger.info('User and UserContact data written successfully...')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
logger.error('Error on writing User data:' + e)
|
logger.error('Error on writing User and UserContact data:' + e)
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
@ -896,7 +901,7 @@ async function findUserByEmail(email: string): Promise<DbUser> {
|
|||||||
throw new Error('No user with this credentials')
|
throw new Error('No user with this credentials')
|
||||||
})
|
})
|
||||||
const userId = dbUserContact.userId
|
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`)
|
logger.error(`User with emailContact=${email} connected per userId=${userId} does not exist`)
|
||||||
throw new Error('No user with this credentials')
|
throw new Error('No user with this credentials')
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||||
import { User } from '@entity/User'
|
import { User } from '@entity/User'
|
||||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
|
||||||
import { UserInterface } from '@/seeds/users/UserInterface'
|
import { UserInterface } from '@/seeds/users/UserInterface'
|
||||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||||
|
import { UserContact } from '@entity/UserContact'
|
||||||
|
|
||||||
export const userFactory = async (
|
export const userFactory = async (
|
||||||
client: ApolloServerTestClient,
|
client: ApolloServerTestClient,
|
||||||
@ -15,17 +15,23 @@ export const userFactory = async (
|
|||||||
createUser: { id },
|
createUser: { id },
|
||||||
},
|
},
|
||||||
} = await mutate({ mutation: createUser, variables: user })
|
} = 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) {
|
if (user.emailChecked) {
|
||||||
const optin = await LoginEmailOptIn.findOneOrFail({ userId: id })
|
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: setPassword,
|
mutation: setPassword,
|
||||||
variables: { password: 'Aa12345_', code: optin.verificationCode },
|
variables: { password: 'Aa12345_', code: emailContact.emailVerificationCode },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user from database
|
// get last changes of user from database
|
||||||
const dbUser = await User.findOneOrFail({ id })
|
dbUser = await User.findOneOrFail({ id })
|
||||||
|
|
||||||
if (user.createdAt || user.deletedAt || user.isAdmin) {
|
if (user.createdAt || user.deletedAt || user.isAdmin) {
|
||||||
if (user.createdAt) dbUser.createdAt = user.createdAt
|
if (user.createdAt) dbUser.createdAt = user.createdAt
|
||||||
@ -34,5 +40,8 @@ export const userFactory = async (
|
|||||||
await dbUser.save()
|
await dbUser.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last changes of user from database
|
||||||
|
dbUser = await User.findOneOrFail({ id }, { withDeleted: true })
|
||||||
|
|
||||||
return dbUser
|
return dbUser
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import createServer from '../server/createServer'
|
import createServer from '../server/createServer'
|
||||||
import { createTestClient } from 'apollo-server-testing'
|
import { createTestClient } from 'apollo-server-testing'
|
||||||
|
|
||||||
@ -50,11 +51,14 @@ const run = async () => {
|
|||||||
const seedClient = createTestClient(server.apollo)
|
const seedClient = createTestClient(server.apollo)
|
||||||
const { con } = server
|
const { con } = server
|
||||||
await cleanDB()
|
await cleanDB()
|
||||||
|
logger.info('##seed## clean database successful...')
|
||||||
|
|
||||||
// seed the standard users
|
// seed the standard users
|
||||||
for (let i = 0; i < users.length; i++) {
|
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
|
// seed 100 random users
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
@ -64,7 +68,9 @@ const run = async () => {
|
|||||||
email: internet.email(),
|
email: internet.email(),
|
||||||
language: datatype.boolean() ? 'en' : 'de',
|
language: datatype.boolean() ? 'en' : 'de',
|
||||||
})
|
})
|
||||||
|
logger.info(`##seed## seed ${i}. random user`)
|
||||||
}
|
}
|
||||||
|
logger.info('##seed## seeding all random users successful...')
|
||||||
|
|
||||||
// create GDD
|
// create GDD
|
||||||
for (let i = 0; i < creations.length; i++) {
|
for (let i = 0; i < creations.length; i++) {
|
||||||
@ -73,16 +79,19 @@ const run = async () => {
|
|||||||
// eslint-disable-next-line no-empty
|
// 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)
|
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
|
// create Transaction Links
|
||||||
for (let i = 0; i < transactionLinks.length; i++) {
|
for (let i = 0; i < transactionLinks.length; i++) {
|
||||||
await transactionLinkFactory(seedClient, transactionLinks[i])
|
await transactionLinkFactory(seedClient, transactionLinks[i])
|
||||||
}
|
}
|
||||||
|
logger.info('##seed## seeding all transactionLinks successful...')
|
||||||
|
|
||||||
// create Contribution Links
|
// create Contribution Links
|
||||||
for (let i = 0; i < contributionLinks.length; i++) {
|
for (let i = 0; i < contributionLinks.length; i++) {
|
||||||
await contributionLinkFactory(seedClient, contributionLinks[i])
|
await contributionLinkFactory(seedClient, contributionLinks[i])
|
||||||
}
|
}
|
||||||
|
logger.info('##seed## seeding all contributionLinks successful...')
|
||||||
|
|
||||||
await con.close()
|
await con.close()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user