mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
required argument client time zone offset for utils in creation
This commit is contained in:
parent
d36fee0302
commit
ef79580387
@ -380,7 +380,7 @@ export class AdminResolver {
|
||||
let creations = await getUserCreation(user.id, clientTimezoneOffset)
|
||||
|
||||
if (contributionToUpdate.contributionDate.getMonth() === creationDateObj.getMonth()) {
|
||||
creations = updateCreations(creations, contributionToUpdate)
|
||||
creations = updateCreations(creations, contributionToUpdate, clientTimezoneOffset)
|
||||
} else {
|
||||
logger.error('Currently the month of the contribution cannot change.')
|
||||
throw new Error('Currently the month of the contribution cannot change.')
|
||||
|
||||
@ -210,7 +210,7 @@ export class ContributionResolver {
|
||||
const creationDateObj = new Date(creationDate)
|
||||
let creations = await getUserCreation(user.id, clientTimezoneOffset)
|
||||
if (contributionToUpdate.contributionDate.getMonth() === creationDateObj.getMonth()) {
|
||||
creations = updateCreations(creations, contributionToUpdate)
|
||||
creations = updateCreations(creations, contributionToUpdate, clientTimezoneOffset)
|
||||
} else {
|
||||
logger.error('Currently the month of the contribution cannot change.')
|
||||
throw new Error('Currently the month of the contribution cannot change.')
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { Context, getUser } from '@/server/context'
|
||||
import { Context, getUser, getClientTimezoneOffset } from '@/server/context'
|
||||
import { getConnection } from '@dbTools/typeorm'
|
||||
import {
|
||||
Resolver,
|
||||
@ -169,6 +169,7 @@ export class TransactionLinkResolver {
|
||||
@Arg('code', () => String) code: string,
|
||||
@Ctx() context: Context,
|
||||
): Promise<boolean> {
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
const user = getUser(context)
|
||||
const now = new Date()
|
||||
|
||||
@ -258,9 +259,9 @@ export class TransactionLinkResolver {
|
||||
}
|
||||
}
|
||||
|
||||
const creations = await getUserCreation(user.id)
|
||||
const creations = await getUserCreation(user.id, clientTimezoneOffset)
|
||||
logger.info('open creations', creations)
|
||||
validateContribution(creations, contributionLink.amount, now)
|
||||
validateContribution(creations, contributionLink.amount, now, clientTimezoneOffset)
|
||||
const contribution = new DbContribution()
|
||||
contribution.userId = user.id
|
||||
contribution.createdAt = now
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { Context, getUser } from '@/server/context'
|
||||
import { Context, getUser, getClientTimezoneOffset } from '@/server/context'
|
||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||
import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeorm'
|
||||
import CONFIG from '@/config'
|
||||
@ -305,8 +305,9 @@ export class UserResolver {
|
||||
async verifyLogin(@Ctx() context: Context): Promise<User> {
|
||||
logger.info('verifyLogin...')
|
||||
// TODO refactor and do not have duplicate code with login(see below)
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
const userEntity = getUser(context)
|
||||
const user = new User(userEntity, await getUserCreation(userEntity.id))
|
||||
const user = new User(userEntity, await getUserCreation(userEntity.id, clientTimezoneOffset))
|
||||
// user.pubkey = userEntity.pubKey.toString('hex')
|
||||
// Elopage Status & Stored PublisherId
|
||||
user.hasElopage = await this.hasElopage(context)
|
||||
@ -323,6 +324,7 @@ export class UserResolver {
|
||||
@Ctx() context: Context,
|
||||
): Promise<User> {
|
||||
logger.info(`login with ${email}, ***, ${publisherId} ...`)
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
email = email.trim().toLowerCase()
|
||||
const dbUser = await findUserByEmail(email)
|
||||
if (dbUser.deletedAt) {
|
||||
@ -353,7 +355,7 @@ export class UserResolver {
|
||||
logger.addContext('user', dbUser.id)
|
||||
logger.debug('validation of login credentials successful...')
|
||||
|
||||
const user = new User(dbUser, await getUserCreation(dbUser.id))
|
||||
const user = new User(dbUser, await getUserCreation(dbUser.id, clientTimezoneOffset))
|
||||
logger.debug(`user= ${JSON.stringify(user, null, 2)}`)
|
||||
|
||||
// Elopage Status & Stored PublisherId
|
||||
|
||||
@ -13,7 +13,7 @@ export const validateContribution = (
|
||||
creations: Decimal[],
|
||||
amount: Decimal,
|
||||
creationDate: Date,
|
||||
timezoneOffset = 0,
|
||||
timezoneOffset: number,
|
||||
): void => {
|
||||
logger.trace('isContributionValid: ', creations, amount, creationDate)
|
||||
const index = getCreationIndex(creationDate.getMonth(), timezoneOffset)
|
||||
@ -38,7 +38,7 @@ export const validateContribution = (
|
||||
|
||||
export const getUserCreations = async (
|
||||
ids: number[],
|
||||
timezoneOffset = 0,
|
||||
timezoneOffset: number,
|
||||
includePending = true,
|
||||
): Promise<CreationMap[]> => {
|
||||
logger.trace('getUserCreations:', ids, includePending)
|
||||
@ -91,7 +91,7 @@ export const getUserCreations = async (
|
||||
|
||||
export const getUserCreation = async (
|
||||
id: number,
|
||||
timezoneOffset = 0,
|
||||
timezoneOffset: number,
|
||||
includePending = true,
|
||||
): Promise<Decimal[]> => {
|
||||
logger.trace('getUserCreation', id, includePending, timezoneOffset)
|
||||
@ -138,7 +138,7 @@ export const isStartEndDateValid = (
|
||||
export const updateCreations = (
|
||||
creations: Decimal[],
|
||||
contribution: Contribution,
|
||||
timezoneOffset = 0,
|
||||
timezoneOffset: number,
|
||||
): Decimal[] => {
|
||||
const index = getCreationIndex(contribution.contributionDate.getMonth(), timezoneOffset)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user