From 4142e6df9f16d26e06ac67e6e8d020f37dbc905a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 20 Jan 2022 15:57:13 +0100 Subject: [PATCH] add date, pass date to server --- admin/src/components/CreationFormular.vue | 9 ++- .../components/EditCreationFormular.spec.js | 6 +- admin/src/components/EditCreationFormular.vue | 6 +- admin/src/pages/Creation.vue | 56 +++++++++-------- admin/src/pages/UserSearch.spec.js | 11 +--- admin/src/pages/UserSearch.vue | 60 ++++++++++--------- 6 files changed, 78 insertions(+), 70 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 5b6ca7553..b2152f917 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -199,10 +199,11 @@ export default { // eslint-disable-next-line no-console console.log('SUBMIT CREATION => ' + this.type + ' >> für VIELE ' + i + ' Mitglieder') this.submitObj = [] + const date = new Date(this.radioSelected.date) this.items.forEach((item) => { this.submitObj.push({ email: item.email, - creationDate: this.radioSelected.long, + creationDate: date.toISOString(), amount: Number(this.value), memo: this.text, moderator: Number(this.$store.state.moderator.id), @@ -234,9 +235,10 @@ export default { this.$toasted.error(error.message) }) } else if (this.type === 'singleCreation') { + const date = new Date(this.radioSelected.date) this.submitObj = { email: this.item.email, - creationDate: this.radioSelected.long, + creationDate: date.toISOString(), amount: Number(this.value), memo: this.text, moderator: Number(this.$store.state.moderator.id), @@ -290,6 +292,7 @@ export default { short: this.$d(this.now, 'month'), long: this.$d(this.now, 'short'), year: this.$d(this.now, 'year'), + date: this.now, } }, lastMonth() { @@ -299,6 +302,7 @@ export default { short: this.$d(lastMonth, 'month'), long: this.$d(lastMonth, 'short'), year: this.$d(lastMonth, 'year'), + date: lastMonth, } }, beforeLastMonth() { @@ -308,6 +312,7 @@ export default { short: this.$d(beforeLastMonth, 'month'), long: this.$d(beforeLastMonth, 'short'), year: this.$d(beforeLastMonth, 'year'), + date: beforeLastMonth, } }, }, diff --git a/admin/src/components/EditCreationFormular.spec.js b/admin/src/components/EditCreationFormular.spec.js index 3915fd828..4b2244fe5 100644 --- a/admin/src/components/EditCreationFormular.spec.js +++ b/admin/src/components/EditCreationFormular.spec.js @@ -108,7 +108,7 @@ describe('EditCreationFormular', () => { expect.objectContaining({ variables: { amount: 90, - creationDate: '2021-10-31', + creationDate: '2021-10-31T23:00:00.000Z', email: 'bob@baumeister.de', id: 0, memo: 'Test create coins', @@ -180,7 +180,7 @@ describe('EditCreationFormular', () => { expect.objectContaining({ variables: { amount: 90, - creationDate: '2021-11-30', + creationDate: '2021-11-30T23:00:00.000Z', email: 'bob@baumeister.de', id: 0, memo: 'Test create coins', @@ -236,7 +236,7 @@ describe('EditCreationFormular', () => { expect.objectContaining({ variables: { amount: 90, - creationDate: '2022-01-20', + creationDate: expect.stringContaining('2022-01-20T'), email: 'bob@baumeister.de', id: 0, memo: 'Test create coins', diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index 97c503ad5..30424b83f 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -169,10 +169,11 @@ export default { this.rangeMax = this.creation[index] }, submitCreation() { + const date = new Date(this.radioSelected.date) this.submitObj = { id: this.item.id, email: this.item.email, - creationDate: this.radioSelected.long, + creationDate: date.toISOString(), amount: Number(this.value), memo: this.text, moderator: Number(this.$store.state.moderator.id), @@ -221,6 +222,7 @@ export default { return { short: this.$d(this.now, 'month'), long: this.$d(this.now, 'short'), + date: this.now, } }, lastMonth() { @@ -229,6 +231,7 @@ export default { return { short: this.$d(lastMonth, 'month'), long: this.$d(lastMonth, 'short'), + date: lastMonth, } }, beforeLastMonth() { @@ -237,6 +240,7 @@ export default { return { short: this.$d(beforeLastMonth, 'month'), long: this.$d(beforeLastMonth, 'short'), + date: beforeLastMonth, } }, }, diff --git a/admin/src/pages/Creation.vue b/admin/src/pages/Creation.vue index 20bb586c8..a3c8b4f73 100644 --- a/admin/src/pages/Creation.vue +++ b/admin/src/pages/Creation.vue @@ -65,32 +65,6 @@ export default { data() { return { showArrays: false, - Searchfields: [ - { key: 'bookmark', label: 'bookmark' }, - { key: 'firstName', label: this.$t('firstname') }, - { key: 'lastName', label: this.$t('lastname') }, - { - key: 'creation', - label: this.creationLabel, - formatter: (value, key, item) => { - return value.join(' | ') - }, - }, - { key: 'email', label: this.$t('e_mail') }, - ], - fields: [ - { key: 'email', label: this.$t('e_mail') }, - { key: 'firstName', label: this.$t('firstname') }, - { key: 'lastName', label: this.$t('lastname') }, - { - key: 'creation', - label: this.creationLabel, - formatter: (value, key, item) => { - return value.join(' | ') - }, - }, - { key: 'bookmark', label: this.$t('remove') }, - ], itemsList: [], itemsMassCreation: [], radioSelectedMass: '', @@ -156,6 +130,36 @@ export default { }, }, computed: { + Searchfields() { + return [ + { key: 'bookmark', label: 'bookmark' }, + { key: 'firstName', label: this.$t('firstname') }, + { key: 'lastName', label: this.$t('lastname') }, + { + key: 'creation', + label: this.creationLabel, + formatter: (value, key, item) => { + return value.join(' | ') + }, + }, + { key: 'email', label: this.$t('e_mail') }, + ] + }, + fields() { + return [ + { key: 'email', label: this.$t('e_mail') }, + { key: 'firstName', label: this.$t('firstname') }, + { key: 'lastName', label: this.$t('lastname') }, + { + key: 'creation', + label: this.creationLabel, + formatter: (value, key, item) => { + return value.join(' | ') + }, + }, + { key: 'bookmark', label: this.$t('remove') }, + ] + }, creationLabel() { const now = new Date(this.now) const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1) diff --git a/admin/src/pages/UserSearch.spec.js b/admin/src/pages/UserSearch.spec.js index 4beda0c49..f7df62730 100644 --- a/admin/src/pages/UserSearch.spec.js +++ b/admin/src/pages/UserSearch.spec.js @@ -24,22 +24,13 @@ const toastErrorMock = jest.fn() const mocks = { $t: jest.fn((t) => t), + $d: jest.fn((d) => d), $apollo: { query: apolloQueryMock, }, $toasted: { error: toastErrorMock, }, - $moment: jest.fn(() => { - return { - format: jest.fn((m) => m), - subtract: jest.fn(() => { - return { - format: jest.fn((m) => m), - } - }), - } - }), } describe('UserSearch', () => { diff --git a/admin/src/pages/UserSearch.vue b/admin/src/pages/UserSearch.vue index 4b9bcae8a..b7c19d03a 100644 --- a/admin/src/pages/UserSearch.vue +++ b/admin/src/pages/UserSearch.vue @@ -44,41 +44,14 @@ export default { data() { return { showArrays: false, - fields: [ - { key: 'email', label: this.$t('e_mail') }, - { key: 'firstName', label: this.$t('firstname') }, - { key: 'lastName', label: this.$t('lastname') }, - { - key: 'creation', - label: [ - this.$moment().subtract(2, 'month').format('MMM'), - this.$moment().subtract(1, 'month').format('MMM'), - this.$moment().format('MMM'), - ].join(' | '), - formatter: (value, key, item) => { - return value.join(' | ') - }, - }, - { key: 'show_details', label: this.$t('details') }, - { key: 'confirm_mail', label: this.$t('confirmed') }, - { key: 'transactions_list', label: this.$t('transaction') }, - ], searchResult: [], massCreation: [], criteria: '', - currentMonth: { - short: this.$moment().format('MMMM'), - }, - lastMonth: { - short: this.$moment().subtract(1, 'month').format('MMMM'), - }, - beforeLastMonth: { - short: this.$moment().subtract(2, 'month').format('MMMM'), - }, filterCheckedEmails: false, rows: 0, currentPage: 1, perPage: 25, + now: Date.now(), } }, methods: { @@ -111,6 +84,37 @@ export default { this.getUsers() }, }, + computed: { + lastMonthDate() { + const now = new Date(this.now) + return new Date(now.getFullYear(), now.getMonth() - 1, 1) + }, + beforeLastMonthDate() { + const now = new Date(this.now) + return new Date(now.getFullYear(), now.getMonth() - 2, 1) + }, + fields() { + return [ + { key: 'email', label: this.$t('e_mail') }, + { key: 'firstName', label: this.$t('firstname') }, + { key: 'lastName', label: this.$t('lastname') }, + { + key: 'creation', + label: [ + this.$d(this.beforeLastMonthDate, 'monthShort'), + this.$d(this.lastMonthDate, 'monthShort'), + this.$d(this.now, 'monthShort'), + ].join(' | '), + formatter: (value, key, item) => { + return value.join(' | ') + }, + }, + { key: 'show_details', label: this.$t('details') }, + { key: 'confirm_mail', label: this.$t('confirmed') }, + { key: 'transactions_list', label: this.$t('transaction') }, + ] + }, + }, created() { this.getUsers() },