diff --git a/src/controllers/evaluationController.ts b/src/controllers/evaluationController.ts index 80ea3ce..9f8e6c8 100644 --- a/src/controllers/evaluationController.ts +++ b/src/controllers/evaluationController.ts @@ -108,27 +108,13 @@ export const recreateEvaluationQuestions = async ( return; } - const [errorReset] = await catchError( - evaluationQuestionService.resetEvaluationQuestions( - chainId, - alloPoolId, - evaluationQuestions - ) + await evaluationQuestionService.resetEvaluationQuestions( + chainId, + alloPoolId, + evaluationQuestions ); - if (errorReset !== undefined) { - logger.error('Failed to reset evaluation questions', { errorReset }); - res.status(500).json({ message: 'Failed to reset evaluation questions' }); - return; - } - - const [errorClean] = await catchError(evaluationService.cleanEvaluations()); - - if (errorClean !== undefined) { - logger.error('Failed to clean evaluations', { errorClean }); - res.status(500).json({ message: 'Failed to clean evaluations' }); - return; - } + await evaluationService.cleanEvaluations(); res.status(200).json(evaluationQuestions); }; @@ -164,16 +150,14 @@ export const evaluateApplication = async ( summaryInput, }; - const [isAllowedError, isAllowed] = await catchError( - isPoolManager( - createEvaluationParams, - signature, - chainId, - alloPoolId - ) + const isAllowed = await isPoolManager( + createEvaluationParams, + signature, + chainId, + alloPoolId ); - if (isAllowedError !== undefined || isAllowed === undefined) { + if (!isAllowed) { logger.warn( `User with address: ${evaluator} is not allowed to evaluate application` ); @@ -317,17 +301,16 @@ export const triggerLLMEvaluation = async ( questions, }; - const [error] = await catchError(createLLMEvaluations([data])); - if (error !== undefined) { + try { + await createLLMEvaluations([data]); + res.status(200).json({ message: 'LLM evaluation triggered successfully' }); + } catch (error) { logger.error('Failed to create evaluations:', error); res.status(500).json({ message: 'Failed to create evaluations', error: error.message, }); } - - logger.info('LLM evaluation triggered successfully'); - res.status(200).json({ message: 'LLM evaluation triggered successfully' }); }; const batchPromises = (array: T[], batchSize: number): T[][] => { diff --git a/src/controllers/passportValidationController.ts b/src/controllers/passportValidationController.ts index 3981371..11899fd 100644 --- a/src/controllers/passportValidationController.ts +++ b/src/controllers/passportValidationController.ts @@ -1,15 +1,12 @@ import type { Request, Response } from 'express'; -import { catchError, validateRequest } from '@/utils'; +import { validateRequest } from '@/utils'; import type { ProjectApplicationForManager } from '@/ext/passport/types'; import { isVerified } from '@/ext/passport/credentialverification'; -import { createLogger } from '@/logger'; interface SocialCredentialBody { application: Partial; } -const logger = createLogger(); - export const validateSocialCredential = async ( req: Request, res: Response @@ -18,16 +15,13 @@ export const validateSocialCredential = async ( const { application } = req.body as SocialCredentialBody; - const [error, result] = await catchError(isVerified(application)); - if (error !== undefined) { - logger.error('Failed to validate social credential:', error); + try { + const result = await isVerified(application); + res.json({ + message: 'Social credential validated', + provider: result, + }); + } catch (error) { res.status(400).json({ message: 'Error validating social credential' }); - return; } - - logger.info('Social credential validated', { result }); - res.json({ - message: 'Social credential validated', - provider: result, - }); }; diff --git a/src/controllers/poolController.ts b/src/controllers/poolController.ts index 5914bcf..b288916 100644 --- a/src/controllers/poolController.ts +++ b/src/controllers/poolController.ts @@ -186,17 +186,11 @@ const handlePoolEvaluationQuestions = async ( pool: Pool, poolMetadata: IndexerRoundMetadata ): Promise => { - const [error, questions] = await catchError( - evaluationQuestionService.getEvaluationQuestionsByAlloPoolId( + const questions = + await evaluationQuestionService.getEvaluationQuestionsByAlloPoolId( pool.alloPoolId, pool.chainId - ) - ); - - if (error !== undefined || questions === undefined) { - logger.error('Failed to get evaluation questions:', error); - throw new Error('Failed to get evaluation questions'); - } + ); if (questions.length > 0) { return questions.map(question => question.question); diff --git a/src/ext/indexer/indexer.ts b/src/ext/indexer/indexer.ts index 93be1ac..224cfcb 100644 --- a/src/ext/indexer/indexer.ts +++ b/src/ext/indexer/indexer.ts @@ -87,6 +87,7 @@ class IndexerClient { getRoundManager, requestVariables ); + if (response.rounds.length === 0) { this.logger.warn( `No round found for poolId: ${alloPoolId} on chainId: ${chainId}` @@ -96,7 +97,7 @@ class IndexerClient { const round = response.rounds[0]; - if (round.roundRoles.length === 0) { + if (round.roles.length === 0) { this.logger.warn( `No manager found for poolId: ${alloPoolId} on chainId: ${chainId}` ); @@ -104,7 +105,7 @@ class IndexerClient { } this.logger.info(`Successfully fetched round manager`); - return round.roundRoles.map(role => role.address); + return round.roles.map(role => role.address); } catch (error) { this.logger.error(`Failed to fetch round manager: ${error.message}`, { error, @@ -156,16 +157,7 @@ class IndexerClient { return null; } - const round = { - chainId: response.rounds[0].chainId, - id: response.rounds[0].id, - roundMetadata: response.rounds[0].roundMetadata, - roundMetadataCid: response.rounds[0].roundMetadataCid, - applications: response.rounds[0].applications.map(application => ({ - ...application, - project: application.projects[0], - })), - }; + const round = response.rounds[0]; // Cache the result this.cache.set(cacheKey, round); @@ -205,7 +197,7 @@ class IndexerClient { requestVariables ); - const application = response.applications[0]; + const application = response.application; if (application == null) { this.logger.warn( @@ -213,7 +205,7 @@ class IndexerClient { ); return null; } - return application; + return response.application; } catch (error) { this.logger.error( `Failed to fetch round with single application: ${error.message}`, diff --git a/src/ext/indexer/queries.ts b/src/ext/indexer/queries.ts index cd51645..7758b9f 100644 --- a/src/ext/indexer/queries.ts +++ b/src/ext/indexer/queries.ts @@ -2,8 +2,10 @@ import { gql } from 'graphql-request'; export const getRoundManager = gql` query RoundManager($chainId: Int!, $alloPoolId: String!) { - rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $alloPoolId } }) { - roundRoles { + rounds( + filter: { chainId: { equalTo: $chainId }, id: { equalTo: $alloPoolId } } + ) { + roles { address } } @@ -12,7 +14,9 @@ export const getRoundManager = gql` export const getRoundWithApplications = gql` query RoundApplications($chainId: Int!, $roundId: String!) { - rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $roundId } }) { + rounds( + filter: { chainId: { equalTo: $chainId }, id: { equalTo: $roundId } } + ) { chainId id roundMetadata @@ -23,7 +27,7 @@ export const getRoundWithApplications = gql` metadataCid status projectId - projects(where: { projectType: { _eq: "canonical" } }) { + project: canonicalProject { metadata metadataCid } @@ -38,13 +42,7 @@ export const getApplicationWithRound = gql` $roundId: String! $applicationId: String! ) { - applications( - where: { - chainId: { _eq: $chainId } - roundId: { _eq: $roundId } - id: { _eq: $applicationId } - } - ) { + application(chainId: $chainId, roundId: $roundId, id: $applicationId) { metadata metadataCid round { diff --git a/src/ext/indexer/types.ts b/src/ext/indexer/types.ts index 1cb5d36..5a76268 100644 --- a/src/ext/indexer/types.ts +++ b/src/ext/indexer/types.ts @@ -1,4 +1,3 @@ -// 1. Basic Types & Enums export type Address = `0x${string}`; export enum Status { @@ -7,7 +6,6 @@ export enum Status { REJECTED = 'REJECTED', } -// 2. Metadata & Supporting Interfaces export interface ApplicationMetadata { signature: string; application: { @@ -54,48 +52,34 @@ export interface ProjectMetadata { projectTwitter?: string; userGithub?: string; projectGithub?: string; + // credentials: ProjectCredentials; owners: Array<{ address: string }>; createdAt: number; lastUpdated: number; } -// 3. Base Interfaces (Used in Multiple Places) -export interface BaseProject { - metadata: ProjectMetadata; - metadataCid: string; -} - -export interface BaseApplication { +export interface Application { id: string; metadata: ApplicationMetadata; metadataCid: string; status: Status; projectId: string; + project: { + metadata: ProjectMetadata; + metadataCid: string; + }; } -// 4. Extended Implementations -export interface Application extends BaseApplication { - project: BaseProject; -} - -export interface ApplicationQuery extends BaseApplication { - projects: BaseProject[]; -} - -export interface BaseRound { +export interface RoundWithApplications { chainId: number; id: string; roundMetadata: RoundMetadata; roundMetadataCid: string; - applications: T[]; + applications: Application[]; } -export type RoundWithApplications = BaseRound; -export type RoundWithApplicationsQuery = BaseRound; - -// 5. API Response Structures export interface RoundApplicationsQueryResponse { - rounds: RoundWithApplicationsQuery[]; + rounds: RoundWithApplications[]; } export interface ApplicationWithRound { @@ -110,12 +94,12 @@ export interface ApplicationWithRound { } export interface ApplicationRoundQueryResponse { - applications: ApplicationWithRound[]; + application: ApplicationWithRound; } export interface ManagerRolesResponse { rounds: Array<{ - roundRoles: Array<{ + roles: Array<{ address: string; }>; }>; diff --git a/src/utils.ts b/src/utils.ts index 86d6a1b..c817a72 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -59,23 +59,14 @@ export async function isPoolManager( chainId: number, alloPoolId: string ): Promise { - const [error, validAddresses] = await catchError( - indexerClient.getRoundManager({ - chainId, - alloPoolId, - }) - ); - - if (error !== undefined || validAddresses === undefined) { - logger.error('Failed to fetch pool manager', { error }); - return false; - } - + const validAddresses = await indexerClient.getRoundManager({ + chainId, + alloPoolId, + }); if (env.NODE_ENV === 'development' && signature === '0xdeadbeef') { logger.info('Skipping signature check in development mode'); return true; } - try { const address = await recoverSignerAddress(obj, signature); logger.info(`Recovered address: ${address}`);