mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
move into contributions
This commit is contained in:
parent
4b4bb15912
commit
a5cda86610
@ -63,13 +63,12 @@ import { fullName } from '@/util/utilities'
|
|||||||
|
|
||||||
import { ContributionMessage } from '@model/ContributionMessage'
|
import { ContributionMessage } from '@model/ContributionMessage'
|
||||||
import { ContributionMessageType } from '../enum/ContributionMessageType'
|
import { ContributionMessageType } from '../enum/ContributionMessageType'
|
||||||
import { findContribution } from './util/contributions'
|
|
||||||
import { getOpenCreations, getUserCreation, validateContribution } from './util/creations'
|
import { getOpenCreations, getUserCreation, validateContribution } from './util/creations'
|
||||||
import { extractGraphQLFields, extractGraphQLFieldsForSelect } from './util/extractGraphQLFields'
|
import { extractGraphQLFields, extractGraphQLFieldsForSelect } from './util/extractGraphQLFields'
|
||||||
import { findContributionMessages } from './util/findContributionMessages'
|
import { findContributionMessages } from './util/findContributionMessages'
|
||||||
import { findContributions } from './util/findContributions'
|
import { findContributions } from './util/findContributions'
|
||||||
import { getLastTransaction } from './util/getLastTransaction'
|
import { getLastTransaction } from './util/getLastTransaction'
|
||||||
import { loadAllContributions, loadUserContributions } from './util/loadContributions'
|
import { loadAllContributions, loadUserContributions } from './util/contributions'
|
||||||
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
||||||
|
|
||||||
@Resolver(() => Contribution)
|
@Resolver(() => Contribution)
|
||||||
@ -77,11 +76,11 @@ export class ContributionResolver {
|
|||||||
@Authorized([RIGHTS.ADMIN_LIST_CONTRIBUTIONS])
|
@Authorized([RIGHTS.ADMIN_LIST_CONTRIBUTIONS])
|
||||||
@Query(() => Contribution)
|
@Query(() => Contribution)
|
||||||
async contribution(@Arg('id', () => Int) id: number): Promise<Contribution> {
|
async contribution(@Arg('id', () => Int) id: number): Promise<Contribution> {
|
||||||
const contribution = await findContribution(id)
|
const dbContribution = await DbContribution.findOne({ where: { id } })
|
||||||
if (!contribution) {
|
if (!dbContribution) {
|
||||||
throw new LogError('Contribution not found', id)
|
throw new LogError('Contribution not found', id)
|
||||||
}
|
}
|
||||||
return new Contribution(contribution)
|
return new Contribution(dbContribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.CREATE_CONTRIBUTION])
|
@Authorized([RIGHTS.CREATE_CONTRIBUTION])
|
||||||
|
|||||||
@ -1,5 +1,48 @@
|
|||||||
import { Contribution } from 'database'
|
import { Paginated } from '@arg/Paginated'
|
||||||
|
import { Contribution as DbContribution } from 'database'
|
||||||
|
import { FindManyOptions } from 'typeorm'
|
||||||
|
|
||||||
export const findContribution = async (id: number): Promise<Contribution | null> => {
|
|
||||||
return Contribution.findOne({ where: { id } })
|
function buildBaseOptions(paginated: Paginated): FindManyOptions<DbContribution> {
|
||||||
|
const { currentPage, pageSize } = paginated
|
||||||
|
return {
|
||||||
|
skip: (currentPage - 1) * pageSize,
|
||||||
|
take: pageSize,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load user contributions with messages
|
||||||
|
* @param userId if userId is set, load all contributions of the user, with messages
|
||||||
|
* @param paginated pagination, see {@link Paginated}
|
||||||
|
*/
|
||||||
|
export const loadUserContributions = async (
|
||||||
|
userId: number,
|
||||||
|
paginated: Paginated,
|
||||||
|
messagePagination?: Paginated,
|
||||||
|
): Promise<[DbContribution[], number]> => {
|
||||||
|
const { order } = paginated
|
||||||
|
const { order: messageOrder } = messagePagination || { order: 'ASC' }
|
||||||
|
return DbContribution.findAndCount({
|
||||||
|
where: { userId },
|
||||||
|
withDeleted: true,
|
||||||
|
relations: { messages: { user: true } },
|
||||||
|
order: { createdAt: order, id: order, messages: { createdAt: messageOrder } },
|
||||||
|
...buildBaseOptions(paginated),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load all contributions
|
||||||
|
* @param paginated pagination, see {@link Paginated}
|
||||||
|
*/
|
||||||
|
export const loadAllContributions = async (
|
||||||
|
paginated: Paginated,
|
||||||
|
): Promise<[DbContribution[], number]> => {
|
||||||
|
const { order } = paginated
|
||||||
|
return DbContribution.findAndCount({
|
||||||
|
relations: { user: { emailContact: true } },
|
||||||
|
order: { createdAt: order, id: order },
|
||||||
|
...buildBaseOptions(paginated),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,47 +0,0 @@
|
|||||||
import { Paginated } from '@arg/Paginated'
|
|
||||||
import { Contribution as DbContribution } from 'database'
|
|
||||||
import { FindManyOptions } from 'typeorm'
|
|
||||||
|
|
||||||
function buildBaseOptions(paginated: Paginated): FindManyOptions<DbContribution> {
|
|
||||||
const { currentPage, pageSize } = paginated
|
|
||||||
return {
|
|
||||||
skip: (currentPage - 1) * pageSize,
|
|
||||||
take: pageSize,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load user contributions with messages
|
|
||||||
* @param userId if userId is set, load all contributions of the user, with messages
|
|
||||||
* @param paginated pagination, see {@link Paginated}
|
|
||||||
*/
|
|
||||||
export const loadUserContributions = async (
|
|
||||||
userId: number,
|
|
||||||
paginated: Paginated,
|
|
||||||
messagePagination?: Paginated,
|
|
||||||
): Promise<[DbContribution[], number]> => {
|
|
||||||
const { order } = paginated
|
|
||||||
const { order: messageOrder } = messagePagination || { order: 'ASC' }
|
|
||||||
return DbContribution.findAndCount({
|
|
||||||
where: { userId },
|
|
||||||
withDeleted: true,
|
|
||||||
relations: { messages: { user: true } },
|
|
||||||
order: { createdAt: order, id: order, messages: { createdAt: messageOrder } },
|
|
||||||
...buildBaseOptions(paginated),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load all contributions
|
|
||||||
* @param paginated pagination, see {@link Paginated}
|
|
||||||
*/
|
|
||||||
export const loadAllContributions = async (
|
|
||||||
paginated: Paginated,
|
|
||||||
): Promise<[DbContribution[], number]> => {
|
|
||||||
const { order } = paginated
|
|
||||||
return DbContribution.findAndCount({
|
|
||||||
relations: { user: { emailContact: true } },
|
|
||||||
order: { createdAt: order, id: order },
|
|
||||||
...buildBaseOptions(paginated),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user