mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Change the commit strategy so that the query runner store the commits and roll them back if their is an error.
This commit is contained in:
parent
2bd63985b2
commit
1142f7359a
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||||
import { getCustomRepository } from 'typeorm'
|
import { getConnection, getCustomRepository } from 'typeorm'
|
||||||
import CONFIG from '../../config'
|
import CONFIG from '../../config'
|
||||||
import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode'
|
import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode'
|
||||||
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
||||||
@ -324,7 +324,7 @@ export class UserResolver {
|
|||||||
const encryptedPrivkey = SecretKeyCryptographyEncrypt(keyPair[1], passwordHash[1])
|
const encryptedPrivkey = SecretKeyCryptographyEncrypt(keyPair[1], passwordHash[1])
|
||||||
|
|
||||||
// Table: login_users
|
// Table: login_users
|
||||||
const loginUser = new LoginUser()
|
let loginUser = new LoginUser()
|
||||||
loginUser.email = email
|
loginUser.email = email
|
||||||
loginUser.firstName = firstName
|
loginUser.firstName = firstName
|
||||||
loginUser.lastName = lastName
|
loginUser.lastName = lastName
|
||||||
@ -339,52 +339,66 @@ export class UserResolver {
|
|||||||
loginUser.privKey = encryptedPrivkey
|
loginUser.privKey = encryptedPrivkey
|
||||||
|
|
||||||
// TODO transaction
|
// TODO transaction
|
||||||
const loginUserRepository = getCustomRepository(LoginUserRepository)
|
const queryRunner = getConnection().createQueryRunner()
|
||||||
const { id: loginUserId } = await loginUserRepository.save(loginUser).catch((error) => {
|
// belong to debugging mysql query / typeorm line
|
||||||
// eslint-disable-next-line no-console
|
// const startTime = new Date()
|
||||||
console.log('insert user failed', error)
|
await queryRunner.connect()
|
||||||
throw new Error('insert user failed')
|
await queryRunner.startTransaction('READ UNCOMMITTED')
|
||||||
})
|
try {
|
||||||
|
const { id: loginUserId } = await queryRunner.manager.save(loginUser).catch((error) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('insert LoginUser failed', error)
|
||||||
|
throw new Error('insert user failed')
|
||||||
|
})
|
||||||
|
|
||||||
// Table: login_user_backups
|
// Table: login_user_backups
|
||||||
const loginUserBackup = new LoginUserBackup()
|
const loginUserBackup = new LoginUserBackup()
|
||||||
loginUserBackup.userId = loginUserId
|
loginUserBackup.userId = loginUserId
|
||||||
loginUserBackup.passphrase = passphrase.join(' ') + ' ' // login server saves trailing space
|
loginUserBackup.passphrase = passphrase.join(' ') + ' ' // login server saves trailing space
|
||||||
loginUserBackup.mnemonicType = 2 // ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER;
|
loginUserBackup.mnemonicType = 2 // ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER;
|
||||||
|
|
||||||
// TODO transaction
|
// TODO transaction
|
||||||
const loginUserBackupRepository = getCustomRepository(LoginUserBackupRepository)
|
await queryRunner.manager.save(loginUserBackup).catch((error) => {
|
||||||
await loginUserBackupRepository.save(loginUserBackup).catch(() => {
|
// eslint-disable-next-line no-console
|
||||||
throw new Error('insert user backup failed')
|
console.log('insert LoginUserBackup failed', error)
|
||||||
})
|
throw new Error('insert user backup failed')
|
||||||
|
})
|
||||||
|
|
||||||
// Table: state_users
|
// Table: state_users
|
||||||
const dbUser = new DbUser()
|
const dbUser = new DbUser()
|
||||||
dbUser.pubkey = keyPair[0]
|
dbUser.pubkey = keyPair[0]
|
||||||
dbUser.email = email
|
dbUser.email = email
|
||||||
dbUser.firstName = firstName
|
dbUser.firstName = firstName
|
||||||
dbUser.lastName = lastName
|
dbUser.lastName = lastName
|
||||||
dbUser.username = username
|
dbUser.username = username
|
||||||
|
|
||||||
// TDOO transaction
|
// TDOO transaction
|
||||||
await userRepository.save(dbUser).catch((er) => {
|
await queryRunner.manager.save(dbUser).catch((er) => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('Error while saving dbUser', er)
|
console.log('Error while saving dbUser', er)
|
||||||
throw new Error('error saving user')
|
throw new Error('error saving user')
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: send EMail (EMAIL_OPT_IN_REGISTER)
|
// TODO: send EMail (EMAIL_OPT_IN_REGISTER)
|
||||||
// const emailType = 2
|
// const emailType = 2
|
||||||
// auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
|
// auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
|
||||||
// auto emailOptInModel = emailOptIn->getModel();
|
// auto code = createEmailVerificationCode();
|
||||||
// if (!emailOptInModel->insertIntoDB(false)) {
|
// auto db = new model::table::EmailOptIn(code, userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
|
||||||
// emailOptInModel->sendErrorsAsEmail();
|
// auto emailOptInModel = emailOptIn->getModel();
|
||||||
// return stateError("insert emailOptIn failed");
|
// if (!emailOptInModel->insertIntoDB(false)) {
|
||||||
// }
|
// emailOptInModel->sendErrorsAsEmail();
|
||||||
// emailOptIn->setBaseUrl(user->getGroupBaseUrl() + ServerConfig::g_frontend_checkEmailPath);
|
// return stateError("insert emailOptIn failed");
|
||||||
// em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
// }
|
||||||
|
// emailOptIn->setBaseUrl(user->getGroupBaseUrl() + ServerConfig::g_frontend_checkEmailPath);
|
||||||
return 'success'
|
// em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
|
||||||
|
await queryRunner.commitTransaction()
|
||||||
|
return 'success'
|
||||||
|
} catch (e) {
|
||||||
|
await queryRunner.rollbackTransaction()
|
||||||
|
throw e
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => SendPasswordResetEmailResponse)
|
@Query(() => SendPasswordResetEmailResponse)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user