@@ -16,6 +16,28 @@ import {
1616export class ContributorRepository {
1717 constructor ( private readonly postgresService : PostgresService ) { }
1818
19+ public async findName ( contributorId : string ) {
20+ const statement = sql `
21+ SELECT
22+ ${ contributorsTable . id } ,
23+ ${ contributorsTable . name }
24+ FROM
25+ ${ contributorsTable }
26+ WHERE
27+ ${ contributorsTable . id } = ${ contributorId }
28+ ` ;
29+
30+ const raw = await this . postgresService . db . execute ( statement ) ;
31+ const entries = Array . from ( raw ) ;
32+ const entry = entries [ 0 ] ;
33+
34+ if ( ! entry ) return null ;
35+
36+ const unStringifiedRaw = unStringifyDeep ( entry ) ;
37+ const camelCased = camelCaseObject ( unStringifiedRaw ) ;
38+ return camelCased ;
39+ }
40+
1941 public async findForProject ( projectId : string ) {
2042 const statement = sql `
2143 SELECT
@@ -50,7 +72,9 @@ export class ContributorRepository {
5072 ${ contributorsTable . id } ,
5173 ${ contributorsTable . name } ,
5274 ${ contributorsTable . avatarUrl } ,
53- sum(${ contributorRepositoryRelationTable . score } ) as ranking
75+ sum(${ contributorRepositoryRelationTable . score } ) as total_contribution_score,
76+ count(DISTINCT ${ contributorRepositoryRelationTable . repositoryId } ) as total_repository_count,
77+ (sum(${ contributorRepositoryRelationTable . score } ) * count(DISTINCT ${ contributorRepositoryRelationTable . repositoryId } )) as ranking
5478 FROM
5579 ${ contributorRepositoryRelationTable }
5680 JOIN
@@ -111,4 +135,35 @@ export class ContributorRepository {
111135 . delete ( contributorsTable )
112136 . where ( ne ( contributorsTable . runId , runId ) ) ;
113137 }
138+
139+ public async findWithStats ( contributorId : string ) {
140+ const statement = sql `
141+ SELECT
142+ ${ contributorsTable . id } ,
143+ ${ contributorsTable . name } ,
144+ ${ contributorsTable . avatarUrl } ,
145+ ${ contributorsTable . username } ,
146+ ${ contributorsTable . url } ,
147+ sum(${ contributorRepositoryRelationTable . score } ) as total_contribution_score,
148+ count(DISTINCT ${ contributorRepositoryRelationTable . repositoryId } ) as total_repository_count,
149+ (sum(${ contributorRepositoryRelationTable . score } ) * count(DISTINCT ${ contributorRepositoryRelationTable . repositoryId } )) as ranking
150+ FROM
151+ ${ contributorRepositoryRelationTable }
152+ JOIN
153+ ${ repositoriesTable } ON ${ contributorRepositoryRelationTable . repositoryId } = ${ repositoriesTable . id }
154+ JOIN
155+ ${ contributorsTable } ON ${ contributorRepositoryRelationTable . contributorId } = ${ contributorsTable . id }
156+ WHERE
157+ ${ contributorsTable . id } = ${ contributorId }
158+ GROUP BY
159+ ${ contributorsTable . id }
160+ ` ;
161+
162+ const raw = await this . postgresService . db . execute ( statement ) ;
163+ const entries = Array . from ( raw ) ;
164+ const entry = entries [ 0 ] ;
165+ const unStringifiedRaw = unStringifyDeep ( entry ) ;
166+ const camelCased = camelCaseObject ( unStringifiedRaw ) ;
167+ return camelCased ;
168+ }
114169}
0 commit comments