File size: 652 Bytes
3d23b0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { mapRating } from './constants';
import * as provider from './provider';
import type { CodeChefRating } from './types';

export async function getUserRating(username: string): Promise<CodeChefRating> {
    try {
        const data = await provider.fetchUserRating(username);

        return {
            username,
            platform: 'codechef',
            rating: data.rating,
            level: mapRating(data.rating),
            max_rating: data.max_rating,
        };
    } catch (error: any) {
        console.error(`CodeChef Error for ${username}:`, error.message);
        throw new Error('Error fetching CodeChef rating');
    }
}