mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into refactor-find-contribtiions
This commit is contained in:
commit
d5ec495785
@ -53,4 +53,5 @@ export enum RIGHTS {
|
||||
UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK',
|
||||
ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE',
|
||||
DENY_CONTRIBUTION = 'DENY_CONTRIBUTION',
|
||||
ADMIN_OPEN_CREATIONS = 'ADMIN_OPEN_CREATIONS',
|
||||
}
|
||||
|
||||
@ -28,11 +28,11 @@ import { RIGHTS } from '@/auth/RIGHTS'
|
||||
import { Context, getUser, getClientTimezoneOffset } from '@/server/context'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import {
|
||||
getCreationDates,
|
||||
getUserCreation,
|
||||
validateContribution,
|
||||
updateCreations,
|
||||
isValidDateString,
|
||||
getOpenCreations,
|
||||
} from './util/creations'
|
||||
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
||||
import {
|
||||
@ -554,21 +554,17 @@ export class ContributionResolver {
|
||||
|
||||
@Authorized([RIGHTS.OPEN_CREATIONS])
|
||||
@Query(() => [OpenCreation])
|
||||
async openCreations(
|
||||
async openCreations(@Ctx() context: Context): Promise<OpenCreation[]> {
|
||||
return getOpenCreations(getUser(context).id, getClientTimezoneOffset(context))
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.ADMIN_OPEN_CREATIONS])
|
||||
@Query(() => [OpenCreation])
|
||||
async adminOpenCreations(
|
||||
@Arg('userId', () => Int) userId: number,
|
||||
@Ctx() context: Context,
|
||||
@Arg('userId', () => Int, { nullable: true }) userId?: number | null,
|
||||
): Promise<OpenCreation[]> {
|
||||
const id = userId || getUser(context).id
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
const creationDates = getCreationDates(clientTimezoneOffset)
|
||||
const creations = await getUserCreation(id, clientTimezoneOffset)
|
||||
return creationDates.map((date, index) => {
|
||||
return {
|
||||
month: date.getMonth(),
|
||||
year: date.getFullYear(),
|
||||
amount: creations[index],
|
||||
}
|
||||
})
|
||||
return getOpenCreations(userId, getClientTimezoneOffset(context))
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.DENY_CONTRIBUTION])
|
||||
|
||||
@ -6,6 +6,7 @@ import { getConnection } from '@dbTools/typeorm'
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { FULL_CREATION_AVAILABLE, MAX_CREATION_AMOUNT } from '../const/const'
|
||||
import { OpenCreation } from '@model/OpenCreation'
|
||||
|
||||
interface CreationMap {
|
||||
id: number
|
||||
@ -102,7 +103,7 @@ const getCreationMonths = (timezoneOffset: number): number[] => {
|
||||
return getCreationDates(timezoneOffset).map((date) => date.getMonth() + 1)
|
||||
}
|
||||
|
||||
export const getCreationDates = (timezoneOffset: number): Date[] => {
|
||||
const getCreationDates = (timezoneOffset: number): Date[] => {
|
||||
const clientNow = new Date()
|
||||
clientNow.setTime(clientNow.getTime() - timezoneOffset * 60 * 1000)
|
||||
logger.info(
|
||||
@ -154,3 +155,18 @@ export const updateCreations = (
|
||||
export const isValidDateString = (dateString: string): boolean => {
|
||||
return new Date(dateString).toString() !== 'Invalid Date'
|
||||
}
|
||||
|
||||
export const getOpenCreations = async (
|
||||
userId: number,
|
||||
timezoneOffset: number,
|
||||
): Promise<OpenCreation[]> => {
|
||||
const creations = await getUserCreation(userId, timezoneOffset)
|
||||
const creationDates = getCreationDates(timezoneOffset)
|
||||
return creationDates.map((date, index) => {
|
||||
return {
|
||||
month: date.getMonth(),
|
||||
year: date.getFullYear(),
|
||||
amount: creations[index],
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user