@@ -2,40 +2,10 @@ import _ from 'lodash';
2
2
3
3
import { knex } from '../../../db/knex-database-connection.js' ;
4
4
import { NotFoundError } from '../../../lib/domain/errors.js' ;
5
- import { CertifiedBadge } from '../../../lib/domain/read-models/CertifiedBadge.js' ;
6
- import {
7
- AssessmentResult ,
8
- CompetenceMark ,
9
- PrivateCertificate ,
10
- ResultCompetenceTree ,
11
- ShareableCertificate ,
12
- } from '../../domain/models/index.js' ;
5
+ import { CertifiedBadge } from '../../../src/certification/results/domain/read-models/CertifiedBadge.js' ;
6
+ import { AssessmentResult , ResultCompetenceTree , ShareableCertificate } from '../../domain/models/index.js' ;
13
7
import * as competenceTreeRepository from './competence-tree-repository.js' ;
14
8
15
- const getPrivateCertificate = async function ( id , { locale } = { } ) {
16
- const certificationCourseDTO = await _selectPrivateCertificates ( )
17
- . where ( 'certification-courses.id' , '=' , id )
18
- . groupBy ( 'certification-courses.id' , 'sessions.id' , 'assessment-results.id' )
19
- . where ( 'certification-courses.isPublished' , true )
20
- . where ( 'certification-courses.isCancelled' , false )
21
- . where ( 'assessment-results.status' , AssessmentResult . status . VALIDATED )
22
- . first ( ) ;
23
-
24
- if ( ! certificationCourseDTO ) {
25
- throw new NotFoundError ( `Certificate not found for ID ${ id } ` ) ;
26
- }
27
-
28
- const certifiedBadges = await _getCertifiedBadges ( id ) ;
29
-
30
- const competenceTree = await competenceTreeRepository . get ( { locale } ) ;
31
-
32
- return _toDomainForPrivateCertificate ( {
33
- certificationCourseDTO,
34
- competenceTree,
35
- certifiedBadges,
36
- } ) ;
37
- } ;
38
-
39
9
const getShareableCertificateByVerificationCode = async function ( verificationCode , { locale } = { } ) {
40
10
const shareableCertificateDTO = await _selectShareableCertificates ( )
41
11
. groupBy ( 'certification-courses.id' , 'sessions.id' , 'assessment-results.id' )
@@ -53,7 +23,7 @@ const getShareableCertificateByVerificationCode = async function (verificationCo
53
23
return _toDomainForShareableCertificate ( { shareableCertificateDTO, competenceTree, certifiedBadges } ) ;
54
24
} ;
55
25
56
- export { getPrivateCertificate , getShareableCertificateByVerificationCode } ;
26
+ export { getShareableCertificateByVerificationCode } ;
57
27
58
28
async function _getCertifiedBadges ( certificationCourseId ) {
59
29
const complementaryCertificationCourseResults = await knex
@@ -92,34 +62,6 @@ async function _getCertifiedBadges(certificationCourseId) {
92
62
return CertifiedBadge . fromComplementaryCertificationCourseResults ( complementaryCertificationCourseResults ) ;
93
63
}
94
64
95
- function _selectPrivateCertificates ( ) {
96
- return _getCertificateQuery ( ) . select ( {
97
- id : 'certification-courses.id' ,
98
- firstName : 'certification-courses.firstName' ,
99
- lastName : 'certification-courses.lastName' ,
100
- birthdate : 'certification-courses.birthdate' ,
101
- birthplace : 'certification-courses.birthplace' ,
102
- isPublished : 'certification-courses.isPublished' ,
103
- isCancelled : 'certification-courses.isCancelled' ,
104
- userId : 'certification-courses.userId' ,
105
- date : 'certification-courses.createdAt' ,
106
- verificationCode : 'certification-courses.verificationCode' ,
107
- deliveredAt : 'sessions.publishedAt' ,
108
- certificationCenter : 'sessions.certificationCenter' ,
109
- maxReachableLevelOnCertificationDate : 'certification-courses.maxReachableLevelOnCertificationDate' ,
110
- pixScore : 'assessment-results.pixScore' ,
111
- commentForCandidate : 'assessment-results.commentForCandidate' ,
112
- commentByAutoJury : 'assessment-results.commentByAutoJury' ,
113
- assessmentResultStatus : 'assessment-results.status' ,
114
- assessmentResultId : 'assessment-results.id' ,
115
- competenceMarks : knex . raw ( `
116
- json_agg(
117
- json_build_object('score', "competence-marks".score, 'level', "competence-marks".level, 'competence_code', "competence-marks"."competence_code")
118
- ORDER BY "competence-marks"."competence_code" asc
119
- )` ) ,
120
- } ) ;
121
- }
122
-
123
65
function _selectShareableCertificates ( ) {
124
66
return _getCertificateQuery ( )
125
67
. select ( {
@@ -165,32 +107,6 @@ function _getCertificateQuery() {
165
107
. leftJoin ( 'competence-marks' , 'competence-marks.assessmentResultId' , 'assessment-results.id' ) ;
166
108
}
167
109
168
- function _toDomainForPrivateCertificate ( { certificationCourseDTO, competenceTree, certifiedBadges = [ ] } ) {
169
- if ( competenceTree ) {
170
- const competenceMarks = _ . compact ( certificationCourseDTO . competenceMarks ) . map (
171
- ( competenceMark ) => new CompetenceMark ( { ...competenceMark } ) ,
172
- ) ;
173
-
174
- const resultCompetenceTree = ResultCompetenceTree . generateTreeFromCompetenceMarks ( {
175
- competenceTree,
176
- competenceMarks,
177
- certificationId : certificationCourseDTO . id ,
178
- assessmentResultId : certificationCourseDTO . assessmentResultId ,
179
- } ) ;
180
-
181
- return PrivateCertificate . buildFrom ( {
182
- ...certificationCourseDTO ,
183
- resultCompetenceTree,
184
- certifiedBadgeImages : certifiedBadges ,
185
- } ) ;
186
- }
187
-
188
- return PrivateCertificate . buildFrom ( {
189
- ...certificationCourseDTO ,
190
- certifiedBadgeImages : certifiedBadges ,
191
- } ) ;
192
- }
193
-
194
110
function _toDomainForShareableCertificate ( { shareableCertificateDTO, competenceTree, certifiedBadges } ) {
195
111
const resultCompetenceTree = ResultCompetenceTree . generateTreeFromCompetenceMarks ( {
196
112
competenceTree,
0 commit comments