Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/modules/vouching/dto/vouch.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,37 @@ export class VouchResponseDto {
@ApiProperty() createdAt: string;
@ApiProperty() expiresAt: string;
}

export class VouchRequestItemDto {
@ApiProperty({
description: 'Learner Stellar wallet address',
example: 'GALPHABCDEFGHIJKLMNOPQRSTUVWXYZ23456789ABCDEFGHIJKLMN',
})
learnerWallet: string;

@ApiProperty({
description: 'Learner reputation score (0-100)',
example: 72,
})
reputationScore: number;

@ApiProperty({
description: 'Requested loan amount in USD',
example: 500,
nullable: true,
})
requestedLoanAmount: number | null;

@ApiProperty({
description: 'Loan purpose or message from the learner',
example: 'Need a loan for inventory restocking',
nullable: true,
})
loanPurpose: string | null;

@ApiProperty({
description: 'ISO 8601 timestamp when the vouch was requested',
example: '2026-06-19T12:00:00.000Z',
})
requestedAt: string;
}
11 changes: 11 additions & 0 deletions src/modules/vouching/vouching.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ApproveVouchDto,
RequestVouchDto,
VouchResponseDto,
VouchRequestItemDto,
} from './dto/vouch.dto';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
Expand Down Expand Up @@ -72,4 +73,14 @@ export class VouchingController {
): Promise<VouchResponseDto[]> {
return this.vouchingService.getMentorVouches(user.wallet);
}

@Get('requests')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Get incoming vouch requests for the authenticated mentor' })
@ApiResponse({ status: 200, description: 'List of pending vouch requests', type: [VouchRequestItemDto] })
async getRequests(
@CurrentUser() user: { wallet: string },
): Promise<VouchRequestItemDto[]> {
return this.vouchingService.getIncomingRequests(user.wallet);
}
}
52 changes: 52 additions & 0 deletions src/modules/vouching/vouching.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ApproveVouchDto,
RequestVouchDto,
VouchResponseDto,
VouchRequestItemDto,
VouchStatus,
} from './dto/vouch.dto';

Expand All @@ -17,6 +18,7 @@ interface VouchRow {
mentor_wallet: string;
learner_wallet: string;
message: string | null;
loan_amount: number | null;
status: VouchStatus;
created_at: string;
expires_at: string;
Expand Down Expand Up @@ -167,6 +169,56 @@ export class VouchingService {
return rows.map((row) => this.mapToDto(row));
}

async getIncomingRequests(mentorWallet: string): Promise<VouchRequestItemDto[]> {
const client = this.supabaseService.getClient();

const { data, error } = await client
.from('vouches')
.select('learner_wallet, message, loan_amount, created_at')
.eq('mentor_wallet', mentorWallet)
.eq('status', VouchStatus.PENDING)
.order('created_at', { ascending: false });

if (error) {
this.logger.error(`Failed to fetch incoming requests for ${mentorWallet}: ${error.message}`);
throw new Error('Failed to fetch vouch requests.');
}

const rows = data ?? [];
const results: VouchRequestItemDto[] = [];

for (const row of rows) {
const reputationScore = await this.getLearnerReputationScore(row.learner_wallet);
results.push({
learnerWallet: row.learner_wallet,
reputationScore,
requestedLoanAmount: row.loan_amount ?? null,
loanPurpose: row.message ?? null,
requestedAt: row.created_at,
});
}

return results;
}

private async getLearnerReputationScore(wallet: string): Promise<number> {
try {
const { data, error } = await this.supabaseService.getClient()
.from('reputation_cache')
.select('score')
.eq('wallet_address', wallet)
.maybeSingle();

if (error || !data) {
return 0;
}

return data.score;
} catch {
return 0;
}
}

private mapToDto(data: VouchRow): VouchResponseDto {
return {
id: data.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE public.vouches ADD COLUMN loan_amount NUMERIC;
Loading