/* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ import { useRequestQuery } from '@routup/query'; import type { Request, Response } from 'routup'; import { send, useRequestParam } from 'routup'; import { applyQuery, useDataSource, } from 'typeorm-extension'; import { NotFoundError } from '@ebec/http'; import { IdentityProviderRoleEntity } from '@authup/server-database'; export async function getManyIdentityProviderRoleRouteHandler(req: Request, res: Response) : Promise { const dataSource = await useDataSource(); const repository = dataSource.getRepository(IdentityProviderRoleEntity); const query = repository.createQueryBuilder('providerRole'); const { pagination } = applyQuery(query, useRequestQuery(req), { defaultAlias: 'providerRole', filters: { allowed: ['role_id', 'provider_id'], }, sort: { allowed: ['id', 'created_at', 'updated_at'], }, pagination: { maxLimit: 50, }, }); const [entities, total] = await query.getManyAndCount(); return send(res, { data: entities, meta: { total, ...pagination, }, }); } // --------------------------------------------------------------------------------- export async function getOneIdentityProviderRoleRouteHandler(req: Request, res: Response) : Promise { const id = useRequestParam(req, 'id'); const dataSource = await useDataSource(); const repository = dataSource.getRepository(IdentityProviderRoleEntity); const query = repository.createQueryBuilder('providerRole') .where('providerRole.id = :id', { id }); const result = await query.getOne(); if (!result) { throw new NotFoundError(); } return send(res, result); }