mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into 2392-refactor-more-emails-to-translatables
This commit is contained in:
commit
486777cb35
@ -42,7 +42,9 @@ export class Transaction {
|
||||
this.creationDate = transaction.creationDate
|
||||
this.linkedUser = linkedUser
|
||||
this.linkedTransactionId = transaction.linkedTransactionId
|
||||
this.transactionLinkId = transaction.transactionLinkId
|
||||
this.linkId = transaction.contribution
|
||||
? transaction.contribution.contributionLinkId
|
||||
: transaction.transactionLinkId
|
||||
}
|
||||
|
||||
@Field(() => Number)
|
||||
@ -81,7 +83,7 @@ export class Transaction {
|
||||
@Field(() => Number, { nullable: true })
|
||||
linkedTransactionId?: number | null
|
||||
|
||||
// Links to the TransactionLink when transaction was created by a link
|
||||
// Links to the TransactionLink/ContributionLink when transaction was created by a link
|
||||
@Field(() => Number, { nullable: true })
|
||||
transactionLinkId?: number | null
|
||||
linkId?: number | null
|
||||
}
|
||||
|
||||
@ -368,6 +368,19 @@ describe('AdminResolver', () => {
|
||||
expect(new Date(result.data.deleteUser)).toEqual(expect.any(Date))
|
||||
})
|
||||
|
||||
it('has deleted_at set in users and user contacts', async () => {
|
||||
await expect(
|
||||
User.findOneOrFail({
|
||||
where: { id: user.id },
|
||||
withDeleted: true,
|
||||
relations: ['emailContact'],
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
deletedAt: expect.any(Date),
|
||||
emailContact: expect.objectContaining({ deletedAt: expect.any(Date) }),
|
||||
})
|
||||
})
|
||||
|
||||
describe('delete deleted user', () => {
|
||||
it('throws an error', async () => {
|
||||
jest.clearAllMocks()
|
||||
@ -491,6 +504,15 @@ describe('AdminResolver', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('has deleted_at set to null in users and user contacts', async () => {
|
||||
await expect(
|
||||
User.findOneOrFail({ where: { id: user.id }, relations: ['emailContact'] }),
|
||||
).resolves.toMatchObject({
|
||||
deletedAt: null,
|
||||
emailContact: expect.objectContaining({ deletedAt: null }),
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -203,7 +203,7 @@ export class AdminResolver {
|
||||
@Arg('userId', () => Int) userId: number,
|
||||
@Ctx() context: Context,
|
||||
): Promise<Date | null> {
|
||||
const user = await dbUser.findOne({ id: userId })
|
||||
const user = await dbUser.findOne({ where: { id: userId }, relations: ['emailContact'] })
|
||||
// user exists ?
|
||||
if (!user) {
|
||||
logger.error(`Could not find user with userId: ${userId}`)
|
||||
@ -217,6 +217,7 @@ export class AdminResolver {
|
||||
}
|
||||
// soft-delete user
|
||||
await user.softRemove()
|
||||
await user.emailContact.softRemove()
|
||||
const newUser = await dbUser.findOne({ id: userId }, { withDeleted: true })
|
||||
return newUser ? newUser.deletedAt : null
|
||||
}
|
||||
@ -224,7 +225,10 @@ export class AdminResolver {
|
||||
@Authorized([RIGHTS.UNDELETE_USER])
|
||||
@Mutation(() => Date, { nullable: true })
|
||||
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
|
||||
const user = await dbUser.findOne({ id: userId }, { withDeleted: true })
|
||||
const user = await dbUser.findOne(
|
||||
{ id: userId },
|
||||
{ withDeleted: true, relations: ['emailContact'] },
|
||||
)
|
||||
if (!user) {
|
||||
logger.error(`Could not find user with userId: ${userId}`)
|
||||
throw new Error(`Could not find user with userId: ${userId}`)
|
||||
@ -234,6 +238,7 @@ export class AdminResolver {
|
||||
throw new Error('User is not deleted')
|
||||
}
|
||||
await user.recover()
|
||||
await user.emailContact.recover()
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@ -204,7 +204,7 @@ export class TransactionResolver {
|
||||
// find current balance
|
||||
const lastTransaction = await dbTransaction.findOne(
|
||||
{ userId: user.id },
|
||||
{ order: { balanceDate: 'DESC' } },
|
||||
{ order: { balanceDate: 'DESC' }, relations: ['contribution'] },
|
||||
)
|
||||
logger.debug(`lastTransaction=${lastTransaction}`)
|
||||
|
||||
@ -326,7 +326,6 @@ export class TransactionResolver {
|
||||
|
||||
// validate recipient user
|
||||
const recipientUser = await findUserByEmail(email)
|
||||
|
||||
if (recipientUser.deletedAt) {
|
||||
logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`)
|
||||
throw new Error('The recipient account was deleted')
|
||||
|
||||
@ -12,29 +12,24 @@ export class TransactionRepository extends Repository<Transaction> {
|
||||
order: Order,
|
||||
onlyCreation?: boolean,
|
||||
): Promise<[Transaction[], number]> {
|
||||
if (onlyCreation) {
|
||||
return this.createQueryBuilder('userTransaction')
|
||||
.where('userTransaction.userId = :userId', { userId })
|
||||
.andWhere('userTransaction.typeId = :typeId', {
|
||||
typeId: TransactionTypeId.CREATION,
|
||||
})
|
||||
.orderBy('userTransaction.balanceDate', order)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.getManyAndCount()
|
||||
}
|
||||
return this.createQueryBuilder('userTransaction')
|
||||
const query = this.createQueryBuilder('userTransaction')
|
||||
.leftJoinAndSelect(
|
||||
'userTransaction.contribution',
|
||||
'contribution',
|
||||
'userTransaction.id = contribution.transactionId',
|
||||
)
|
||||
.where('userTransaction.userId = :userId', { userId })
|
||||
|
||||
if (onlyCreation) {
|
||||
query.andWhere('userTransaction.typeId = :typeId', {
|
||||
typeId: TransactionTypeId.CREATION,
|
||||
})
|
||||
}
|
||||
|
||||
return query
|
||||
.orderBy('userTransaction.balanceDate', order)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.getManyAndCount()
|
||||
}
|
||||
|
||||
findLastForUser(userId: number): Promise<Transaction | undefined> {
|
||||
return this.createQueryBuilder('userTransaction')
|
||||
.where('userTransaction.userId = :userId', { userId })
|
||||
.orderBy('userTransaction.balanceDate', 'DESC')
|
||||
.getOne()
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ const virtualLinkTransaction = (
|
||||
decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR),
|
||||
memo: '',
|
||||
creationDate: null,
|
||||
contribution: null,
|
||||
...defaultModelFunctions,
|
||||
}
|
||||
return new Transaction(linkDbTransaction, user)
|
||||
@ -78,6 +79,7 @@ const virtualDecayTransaction = (
|
||||
decayStart: decay.start,
|
||||
memo: '',
|
||||
creationDate: null,
|
||||
contribution: null,
|
||||
...defaultModelFunctions,
|
||||
}
|
||||
return new Transaction(decayDbTransaction, user)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm'
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
import { Contribution } from '../Contribution'
|
||||
|
||||
@Entity('transactions')
|
||||
export class Transaction extends BaseEntity {
|
||||
@ -91,4 +92,8 @@ export class Transaction extends BaseEntity {
|
||||
default: null,
|
||||
})
|
||||
transactionLinkId?: number | null
|
||||
|
||||
@OneToOne(() => Contribution, (contribution) => contribution.transaction)
|
||||
@JoinColumn({ name: 'id', referencedColumnName: 'transactionId' })
|
||||
contribution?: Contribution | null
|
||||
}
|
||||
|
||||
@ -8,10 +8,12 @@ import {
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
} from 'typeorm'
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
import { User } from '../User'
|
||||
import { ContributionMessage } from '../ContributionMessage'
|
||||
import { Transaction } from '../Transaction'
|
||||
|
||||
@Entity('contributions')
|
||||
export class Contribution extends BaseEntity {
|
||||
@ -92,4 +94,8 @@ export class Contribution extends BaseEntity {
|
||||
@OneToMany(() => ContributionMessage, (message) => message.contribution)
|
||||
@JoinColumn({ name: 'contribution_id' })
|
||||
messages?: ContributionMessage[]
|
||||
|
||||
@OneToOne(() => Transaction, (transaction) => transaction.contribution)
|
||||
@JoinColumn({ name: 'transaction_id' })
|
||||
transaction?: Transaction | null
|
||||
}
|
||||
|
||||
@ -10,21 +10,21 @@
|
||||
</b-col>
|
||||
<b-col cols="7">
|
||||
<div class="gdd-transaction-list-item-name">
|
||||
<div v-if="linkedUser && linkedUser.email">
|
||||
<span v-if="linkedUser && linkedUser.email">
|
||||
<b-link @click.stop="tunnelEmail">
|
||||
{{ itemText }}
|
||||
</b-link>
|
||||
<span v-if="transactionLinkId">
|
||||
{{ $t('via_link') }}
|
||||
<b-icon
|
||||
icon="link45deg"
|
||||
variant="muted"
|
||||
class="m-mb-1"
|
||||
:title="$t('gdd_per_link.redeemed-title')"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
<span v-else>{{ itemText }}</span>
|
||||
<span v-if="linkId">
|
||||
{{ $t('via_link') }}
|
||||
<b-icon
|
||||
icon="link45deg"
|
||||
variant="muted"
|
||||
class="m-mb-1"
|
||||
:title="$t('gdd_per_link.redeemed-title')"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</b-col>
|
||||
</b-row>
|
||||
@ -46,7 +46,7 @@ export default {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
transactionLinkId: {
|
||||
linkId: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: null,
|
||||
|
||||
@ -12,7 +12,12 @@
|
||||
|
||||
<b-col cols="11">
|
||||
<!-- Amount / Name || Text -->
|
||||
<amount-and-name-row :amount="amount" :linkedUser="linkedUser" v-on="$listeners" />
|
||||
<amount-and-name-row
|
||||
:amount="amount"
|
||||
:linkedUser="linkedUser"
|
||||
v-on="$listeners"
|
||||
:linkId="linkId"
|
||||
/>
|
||||
|
||||
<!-- Nachricht Memo -->
|
||||
<memo-row :memo="memo" />
|
||||
@ -77,6 +82,10 @@ export default {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
linkId: {
|
||||
type: Number,
|
||||
required: false,
|
||||
},
|
||||
previousBookedBalance: {
|
||||
type: String,
|
||||
required: true,
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
v-on="$listeners"
|
||||
:amount="amount"
|
||||
:linkedUser="linkedUser"
|
||||
:transactionLinkId="transactionLinkId"
|
||||
:linkId="linkId"
|
||||
/>
|
||||
|
||||
<!-- Nachricht Memo -->
|
||||
@ -82,7 +82,7 @@ export default {
|
||||
typeId: {
|
||||
type: String,
|
||||
},
|
||||
transactionLinkId: {
|
||||
linkId: {
|
||||
type: Number,
|
||||
required: false,
|
||||
},
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
v-on="$listeners"
|
||||
:amount="amount"
|
||||
:linkedUser="linkedUser"
|
||||
:transactionLinkId="transactionLinkId"
|
||||
:linkId="linkId"
|
||||
/>
|
||||
|
||||
<!-- Memo -->
|
||||
@ -83,7 +83,7 @@ export default {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
transactionLinkId: {
|
||||
linkId: {
|
||||
type: Number,
|
||||
required: false,
|
||||
},
|
||||
|
||||
@ -45,7 +45,7 @@ export const transactionsQuery = gql`
|
||||
end
|
||||
duration
|
||||
}
|
||||
transactionLinkId
|
||||
linkId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user