Merge branch 'master' into fix_optin_code_regeneration

This commit is contained in:
Ulf Gebhardt 2021-12-20 12:36:48 +01:00 committed by GitHub
commit ce973d1e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 199 additions and 101 deletions

View File

@ -212,95 +212,80 @@ export class AdminResolver {
async function getUserCreations(id: number): Promise<number[]> { async function getUserCreations(id: number): Promise<number[]> {
const dateNextMonth = moment().add(1, 'month').format('YYYY-MM') + '-01' const dateNextMonth = moment().add(1, 'month').format('YYYY-MM') + '-01'
const dateMonth = moment().format('YYYY-MM') + '-01'
const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + '-01'
const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01' const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01'
const beforeLastMonthNumber = moment().subtract(2, 'month').format('M')
const lastMonthNumber = moment().subtract(1, 'month').format('M')
const currentMonthNumber = moment().format('M')
const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) const transactionCreationRepository = getCustomRepository(TransactionCreationRepository)
const createdAmountBeforeLastMonth = await transactionCreationRepository const createdAmountsQuery = await transactionCreationRepository
.createQueryBuilder('transaction_creations') .createQueryBuilder('transaction_creations')
.select('SUM(transaction_creations.amount)', 'sum') .select('MONTH(transaction_creations.target_date)', 'target_month')
.addSelect('SUM(transaction_creations.amount)', 'sum')
.where('transaction_creations.state_user_id = :id', { id }) .where('transaction_creations.state_user_id = :id', { id })
.andWhere({ .andWhere({
targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :endDate`, {
date: dateBeforeLastMonth, date: dateBeforeLastMonth,
enddate: dateLastMonth, endDate: dateNextMonth,
}), }),
}) })
.getRawOne() .groupBy('target_month')
.orderBy('target_month', 'ASC')
const createdAmountLastMonth = await transactionCreationRepository .getRawMany()
.createQueryBuilder('transaction_creations')
.select('SUM(transaction_creations.amount)', 'sum')
.where('transaction_creations.state_user_id = :id', { id })
.andWhere({
targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, {
date: dateLastMonth,
enddate: dateMonth,
}),
})
.getRawOne()
const createdAmountMonth = await transactionCreationRepository
.createQueryBuilder('transaction_creations')
.select('SUM(transaction_creations.amount)', 'sum')
.where('transaction_creations.state_user_id = :id', { id })
.andWhere({
targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, {
date: dateMonth,
enddate: dateNextMonth,
}),
})
.getRawOne()
const loginPendingTasksAdminRepository = getCustomRepository(LoginPendingTasksAdminRepository) const loginPendingTasksAdminRepository = getCustomRepository(LoginPendingTasksAdminRepository)
const pendingAmountMounth = await loginPendingTasksAdminRepository const pendingAmountsQuery = await loginPendingTasksAdminRepository
.createQueryBuilder('login_pending_tasks_admin') .createQueryBuilder('login_pending_tasks_admin')
.select('SUM(login_pending_tasks_admin.amount)', 'sum') .select('MONTH(login_pending_tasks_admin.date)', 'target_month')
.addSelect('SUM(login_pending_tasks_admin.amount)', 'sum')
.where('login_pending_tasks_admin.userId = :id', { id }) .where('login_pending_tasks_admin.userId = :id', { id })
.andWhere({ .andWhere({
date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: Raw((alias) => `${alias} >= :date and ${alias} < :endDate`, {
date: dateMonth,
enddate: dateNextMonth,
}),
})
.getRawOne()
const pendingAmountLastMounth = await loginPendingTasksAdminRepository
.createQueryBuilder('login_pending_tasks_admin')
.select('SUM(login_pending_tasks_admin.amount)', 'sum')
.where('login_pending_tasks_admin.userId = :id', { id })
.andWhere({
date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, {
date: dateLastMonth,
enddate: dateMonth,
}),
})
.getRawOne()
const pendingAmountBeforeLastMounth = await loginPendingTasksAdminRepository
.createQueryBuilder('login_pending_tasks_admin')
.select('SUM(login_pending_tasks_admin.amount)', 'sum')
.where('login_pending_tasks_admin.userId = :id', { id })
.andWhere({
date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, {
date: dateBeforeLastMonth, date: dateBeforeLastMonth,
enddate: dateLastMonth, endDate: dateNextMonth,
}), }),
}) })
.getRawOne() .groupBy('target_month')
.orderBy('target_month', 'ASC')
.getRawMany()
const map = new Map()
if (Array.isArray(createdAmountsQuery) && createdAmountsQuery.length > 0) {
createdAmountsQuery.forEach((createdAmount) => {
if (!map.has(createdAmount.target_month)) {
map.set(createdAmount.target_month, createdAmount.sum)
} else {
const store = map.get(createdAmount.target_month)
map.set(createdAmount.target_month, Number(store) + Number(createdAmount.sum))
}
})
}
if (Array.isArray(pendingAmountsQuery) && pendingAmountsQuery.length > 0) {
pendingAmountsQuery.forEach((pendingAmount) => {
if (!map.has(pendingAmount.target_month)) {
map.set(pendingAmount.target_month, pendingAmount.sum)
} else {
const store = map.get(pendingAmount.target_month)
map.set(pendingAmount.target_month, Number(store) + Number(pendingAmount.sum))
}
})
}
const usedCreationBeforeLastMonth = map.get(Number(beforeLastMonthNumber))
? Number(map.get(Number(beforeLastMonthNumber))) / 10000
: 0
const usedCreationLastMonth = map.get(Number(lastMonthNumber))
? Number(map.get(Number(lastMonthNumber))) / 10000
: 0
const usedCreationCurrentMonth = map.get(Number(currentMonthNumber))
? Number(map.get(Number(currentMonthNumber))) / 10000
: 0
// COUNT amount from 2 tables
const usedCreationBeforeLastMonth =
(Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum)) / 10000
const usedCreationLastMonth =
(Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000
const usedCreationMonth =
(Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000
return [ return [
1000 - usedCreationBeforeLastMonth, 1000 - usedCreationBeforeLastMonth,
1000 - usedCreationLastMonth, 1000 - usedCreationLastMonth,
1000 - usedCreationMonth, 1000 - usedCreationCurrentMonth,
] ]
} }

View File

@ -45,9 +45,11 @@
}, },
"error": { "error": {
"change-password": "Fehler beim Ändern des Passworts", "change-password": "Fehler beim Ändern des Passworts",
"empty-transactionlist": "Es gab einen Fehler mit der Übermittlung der Anzahl deiner Transaktionen.",
"error": "Fehler", "error": "Fehler",
"no-account": "Leider konnten wir keinen Account finden mit diesen Daten!", "no-account": "Leider konnten wir keinen Account finden mit diesen Daten!",
"no-email-verify": "Die Email wurde noch nicht bestätigt, bitte überprüfe deine Emails und klicke auf den Aktivierungslink!", "no-email-verify": "Die Email wurde noch nicht bestätigt, bitte überprüfe deine Emails und klicke auf den Aktivierungslink!",
"no-transactionlist": "Es gab leider einen Fehler. Es wurden keine Transaktionen vom Server übermittelt",
"session-expired": "Die Sitzung wurde aus Sicherheitsgründen beendet." "session-expired": "Die Sitzung wurde aus Sicherheitsgründen beendet."
}, },
"form": { "form": {
@ -55,6 +57,7 @@
"at": "am", "at": "am",
"cancel": "Abbrechen", "cancel": "Abbrechen",
"close": "schließen", "close": "schließen",
"current_balance": "aktueller Kontostand",
"date": "Datum", "date": "Datum",
"description": "Beschreibung", "description": "Beschreibung",
"edit": "bearbeiten", "edit": "bearbeiten",
@ -64,6 +67,7 @@
"lastname": "Nachname", "lastname": "Nachname",
"memo": "Nachricht", "memo": "Nachricht",
"message": "Nachricht", "message": "Nachricht",
"new_balance": "neuer Kontostand nach Bestätigung",
"password": "Passwort", "password": "Passwort",
"passwordRepeat": "Passwort wiederholen", "passwordRepeat": "Passwort wiederholen",
"password_new": "neues Passwort", "password_new": "neues Passwort",
@ -88,7 +92,8 @@
"is-not": "Du kannst dir selbst keine Gradidos überweisen", "is-not": "Du kannst dir selbst keine Gradidos überweisen",
"usernmae-regex": "Der Username muss mit einem Buchstaben beginnen auf den mindestens zwei alfanumerische Zeichen folgen müssen.", "usernmae-regex": "Der Username muss mit einem Buchstaben beginnen auf den mindestens zwei alfanumerische Zeichen folgen müssen.",
"usernmae-unique": "Der Username ist bereits vergeben." "usernmae-unique": "Der Username ist bereits vergeben."
} },
"your_amount": "Dein Betrag"
}, },
"gdt": { "gdt": {
"action": "Aktion", "action": "Aktion",

View File

@ -45,9 +45,11 @@
}, },
"error": { "error": {
"change-password": "Error while changing password", "change-password": "Error while changing password",
"empty-transactionlist": "There was an error with the transmission of the number of your transactions.",
"error": "Error", "error": "Error",
"no-account": "Unfortunately we could not find an account to the given data!", "no-account": "Unfortunately we could not find an account to the given data!",
"no-email-verify": "Your email is not activated yet, please check your emails and click the activation link!", "no-email-verify": "Your email is not activated yet, please check your emails and click the activation link!",
"no-transactionlist": "Unfortunately, there was an error. No transactions have been sent from the server.",
"session-expired": "The session was closed for security reasons." "session-expired": "The session was closed for security reasons."
}, },
"form": { "form": {
@ -55,6 +57,7 @@
"at": "at", "at": "at",
"cancel": "Cancel", "cancel": "Cancel",
"close": "Close", "close": "Close",
"current_balance": "current balance",
"date": "Date", "date": "Date",
"description": "Description", "description": "Description",
"edit": "Edit", "edit": "Edit",
@ -64,6 +67,7 @@
"lastname": "Lastname", "lastname": "Lastname",
"memo": "Message", "memo": "Message",
"message": "Message", "message": "Message",
"new_balance": "account balance after confirmation",
"password": "Password", "password": "Password",
"passwordRepeat": "Repeat password", "passwordRepeat": "Repeat password",
"password_new": "New password", "password_new": "New password",
@ -88,7 +92,8 @@
"is-not": "You cannot send Gradidos to yourself", "is-not": "You cannot send Gradidos to yourself",
"usernmae-regex": "The username must start with a letter, followed by at least two alphanumeric characters.", "usernmae-regex": "The username must start with a letter, followed by at least two alphanumeric characters.",
"usernmae-unique": "The username is already taken." "usernmae-unique": "The username is already taken."
} },
"your_amount": "Your amount"
}, },
"gdt": { "gdt": {
"action": "Action", "action": "Action",

View File

@ -36,9 +36,42 @@ describe('GddTransactionList', () => {
expect(wrapper.find('div.gdd-transaction-list').exists()).toBeTruthy() expect(wrapper.find('div.gdd-transaction-list').exists()).toBeTruthy()
}) })
describe('no transactions from server', () => {
beforeEach(async () => {
await wrapper.setProps({
transactions: false,
})
})
it('shows error no transaction list', () => {
expect(wrapper.find('div.test-no-transactionlist').text()).toContain(
'error.no-transactionlist',
)
})
})
describe('0 transactions from server', () => {
beforeEach(async () => {
await wrapper.setProps({
transactions: [],
transactionCount: 0,
})
})
it('Transactions Array is empty, 0 transactions', () => {
expect(wrapper.find('div.test-empty-transactionlist').text()).toContain(
'error.empty-transactionlist',
)
})
})
describe('without any properties', () => { describe('without any properties', () => {
it('renders text saying that there are no transactions', () => { it('renders text saying that there are error.empty-transactionlist ', () => {
expect(wrapper.find('div.gdd-transaction-list').text()).toBe('transaction.nullTransactions') expect(wrapper.find('div.gdd-transaction-list').text()).toContain(
'error.empty-transactionlist',
)
})
it('renders text saying that there are no transaction.nullTransactions', () => {
expect(wrapper.find('div.gdd-transaction-list').text()).toContain(
'transaction.nullTransactions',
)
}) })
}) })

View File

@ -1,6 +1,16 @@
<template> <template>
<div class="gdd-transaction-list"> <div class="gdd-transaction-list">
<div class="list-group"> <div class="list-group">
<div v-if="!transactions" class="test-no-transactionlist text-right">
<b-icon icon="exclamation-triangle" class="mr-2" style="color: red"></b-icon>
<small>
{{ $t('error.no-transactionlist') }}
</small>
</div>
<div v-if="!transactionCount" class="test-empty-transactionlist text-right">
<b-icon icon="exclamation-triangle" class="mr-2" style="color: red"></b-icon>
<small>{{ $t('error.empty-transactionlist') }}</small>
</div>
<div <div
v-for="{ decay, transactionId, type, date, balance, name, memo } in transactions" v-for="{ decay, transactionId, type, date, balance, name, memo } in transactions"
:key="transactionId" :key="transactionId"

View File

@ -13,7 +13,9 @@ describe('SendOverview', () => {
const propsData = { const propsData = {
balance: 123.45, balance: 123.45,
transactionCount: 1, GdtBalance: 1234.56,
transactions: [{ balance: 0.1 }],
pending: true,
} }
const mocks = { const mocks = {
@ -42,18 +44,16 @@ describe('SendOverview', () => {
expect(wrapper.find('div.gdd-send').exists()).toBeTruthy() expect(wrapper.find('div.gdd-send').exists()).toBeTruthy()
}) })
// it('has a transactions table', () => {
// expect(wrapper.find('div.gdd-transaction-list').exists()).toBeTruthy()
// })
describe('transaction form', () => { describe('transaction form', () => {
it('steps forward in the dialog', async () => { beforeEach(async () => {
await wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', { wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', {
email: 'user@example.org', email: 'user@example.org',
amount: 23.45, amount: 23.45,
memo: 'Make the best of it!', memo: 'Make the best of it!',
}) })
expect(wrapper.findComponent({ name: 'TransactionConfirmation' }).exists()).toBeTruthy() })
it('steps forward in the dialog', () => {
expect(wrapper.findComponent({ name: 'TransactionConfirmation' }).exists()).toBe(true)
}) })
}) })
@ -112,18 +112,22 @@ describe('SendOverview', () => {
describe('transaction is confirmed and server response is error', () => { describe('transaction is confirmed and server response is error', () => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() jest.clearAllMocks()
sendMock.mockRejectedValue({ message: 'receiver not found' }) sendMock.mockRejectedValue({ message: 'recipiant not known' })
await wrapper await wrapper
.findComponent({ name: 'TransactionConfirmation' }) .findComponent({ name: 'TransactionConfirmation' })
.vm.$emit('send-transaction') .vm.$emit('send-transaction')
}) })
it('shows the error page', () => { it('shows the error page', () => {
expect(wrapper.find('div.card-body').text()).toContain('form.send_transaction_error') expect(wrapper.find('.test-send_transaction_error').text()).toContain(
'form.send_transaction_error',
)
}) })
it('shows recipient not found', () => { it('shows recipient not found', () => {
expect(wrapper.text()).toContain('transaction.receiverNotFound') expect(wrapper.find('.test-receiver-not-found').text()).toContain(
'transaction.receiverNotFound',
)
}) })
}) })
}) })

View File

@ -1,12 +1,14 @@
<template> <template>
<div> <div>
<b-container> <b-container>
<gdd-send :currentTransactionStep="currentTransactionStep"> <gdd-send :currentTransactionStep="currentTransactionStep" class="pt-3">
<template #transaction-form> <template #transaction-form>
<transaction-form :balance="balance" @set-transaction="setTransaction"></transaction-form> <transaction-form :balance="balance" @set-transaction="setTransaction"></transaction-form>
</template> </template>
<template #transaction-confirmation> <template #transaction-confirmation>
<transaction-confirmation <transaction-confirmation
:balance="balance"
:transactions="transactions"
:email="transactionData.email" :email="transactionData.email"
:amount="transactionData.amount" :amount="transactionData.amount"
:memo="transactionData.memo" :memo="transactionData.memo"
@ -44,7 +46,6 @@ export default {
name: 'SendOverview', name: 'SendOverview',
components: { components: {
GddSend, GddSend,
TransactionForm, TransactionForm,
TransactionConfirmation, TransactionConfirmation,
TransactionResult, TransactionResult,

View File

@ -2,23 +2,61 @@
<div> <div>
<b-row> <b-row>
<b-col> <b-col>
<div class="display-4 p-4">{{ $t('form.send_check') }}</div> <div class="display-4 pb-4">{{ $t('form.send_check') }}</div>
<b-list-group> <b-list-group class="">
<b-list-group-item class="d-flex justify-content-between align-items-center"> <label class="input-1" for="input-1">{{ $t('form.recipient') }}</label>
{{ email }} <b-input-group id="input-group-1" class="borderbottom" size="lg">
<b-badge variant="primary" pill>{{ $t('form.recipient') }}</b-badge> <b-input-group-prepend class="d-none d-md-block gray-background">
</b-list-group-item> <b-icon icon="envelope" class="display-4 m-3"></b-icon>
<b-list-group-item class="d-flex justify-content-between align-items-center"> </b-input-group-prepend>
{{ $n(amount, 'decimal') }} GDD <div class="p-3">{{ email }}</div>
<b-badge variant="primary" pill>{{ $t('form.amount') }}</b-badge> </b-input-group>
</b-list-group-item> <br />
<b-list-group-item class="d-flex justify-content-between align-items-center"> <label class="input-2" for="input-2">{{ $t('form.amount') }}</label>
{{ memo ? memo : '-' }} <b-input-group id="input-group-2" class="borderbottom" size="lg">
<b-badge variant="primary" pill>{{ $t('form.message') }}</b-badge> <b-input-group-prepend class="p-2 d-none d-md-block gray-background">
</b-list-group-item> <div class="m-1 mt-2">GDD</div>
</b-input-group-prepend>
<div class="p-3">{{ $n(amount, 'decimal') }}</div>
</b-input-group>
<br />
<label class="input-3" for="input-3">{{ $t('form.message') }}</label>
<b-input-group id="input-group-3" class="borderbottom">
<b-input-group-prepend class="d-none d-md-block gray-background">
<b-icon icon="chat-right-text" class="display-4 m-3 mt-4"></b-icon>
</b-input-group-prepend>
<div class="p-3">{{ memo ? memo : '-' }}</div>
</b-input-group>
</b-list-group> </b-list-group>
</b-col> </b-col>
</b-row> </b-row>
<b-container class="bv-example-row mt-3 gray-background p-2">
<b-row class="pr-3">
<b-col class="text-right">{{ $t('form.current_balance') }}</b-col>
<b-col class="text-right">{{ $n(balance, 'decimal') }}</b-col>
</b-row>
<b-row class="pr-3">
<b-col class="text-right">
<strong>{{ $t('form.your_amount') }}</strong>
</b-col>
<b-col class="text-right">
<strong>- {{ $n(amount, 'decimal') }}</strong>
</b-col>
</b-row>
<b-row class="pr-3">
<b-col class="text-right">{{ $t('decay.decay') }}</b-col>
<b-col class="text-right" style="border-bottom: double">- {{ $n(decay, 'decimal') }}</b-col>
</b-row>
<b-row class="pr-3">
<b-col class="text-right">{{ $t('form.new_balance') }}</b-col>
<b-col class="text-right">~ {{ $n(balance - amount - decay, 'decimal') }}</b-col>
</b-row>
</b-container>
<b-row class="mt-4"> <b-row class="mt-4">
<b-col> <b-col>
<b-button @click="$emit('on-reset')">{{ $t('form.cancel') }}</b-button> <b-button @click="$emit('on-reset')">{{ $t('form.cancel') }}</b-button>
@ -35,10 +73,27 @@
export default { export default {
name: 'TransactionConfirmation', name: 'TransactionConfirmation',
props: { props: {
balance: { type: Number, default: 0 },
email: { type: String, default: '' }, email: { type: String, default: '' },
amount: { type: Number, default: 0 }, amount: { type: Number, default: 0 },
memo: { type: String, default: '' }, memo: { type: String, default: '' },
loading: { type: Boolean, default: false }, loading: { type: Boolean, default: false },
transactions: {
default: () => [],
},
},
data() {
return {
decay: this.transactions[0].balance,
}
}, },
} }
</script> </script>
<style>
.gray-background {
background-color: #ecebe6a3 !important;
}
.borderbottom {
border-bottom: 1px solid rgb(70, 65, 65);
}
</style>

View File

@ -20,10 +20,10 @@
<div>{{ $t('form.sorry') }}</div> <div>{{ $t('form.sorry') }}</div>
<hr /> <hr />
<div>{{ $t('form.send_transaction_error') }}</div> <div class="test-send_transaction_error">{{ $t('form.send_transaction_error') }}</div>
<hr /> <hr />
<div v-if="errorResult === 'receiver not found'"> <div class="test-receiver-not-found" v-if="errorResult === 'recipiant not known'">
{{ $t('transaction.receiverNotFound') }} {{ $t('transaction.receiverNotFound') }}
</div> </div>
<div v-else>({{ errorResult }})</div> <div v-else>({{ errorResult }})</div>