1
1
import lodash from 'lodash' ;
2
2
3
- import { knex } from '../../../../../db/knex-database-connection.js' ;
4
3
import { constants } from '../../../../shared/domain/constants.js' ;
5
4
import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js' ;
6
5
import { NotFoundError } from '../../../../shared/domain/errors.js' ;
@@ -119,7 +118,8 @@ const getAllCampaignParticipationsInCampaignForASameLearner = async function ({
119
118
} ;
120
119
121
120
const getCampaignParticipationsForOrganizationLearner = async function ( { organizationLearnerId, campaignId } ) {
122
- const campaignParticipations = await knex ( 'campaign-participations' )
121
+ const knexConn = DomainTransaction . getConnection ( ) ;
122
+ const campaignParticipations = await knexConn ( 'campaign-participations' )
123
123
. where ( {
124
124
campaignId,
125
125
organizationLearnerId,
@@ -139,7 +139,8 @@ const remove = async function ({ id, deletedAt, deletedBy }) {
139
139
} ;
140
140
141
141
const findProfilesCollectionResultDataByCampaignId = async function ( campaignId ) {
142
- const results = await knex ( 'campaign-participations' )
142
+ const knexConn = DomainTransaction . getConnection ( ) ;
143
+ const results = await knexConn ( 'campaign-participations' )
143
144
. select ( [
144
145
'campaign-participations.*' ,
145
146
'view-active-organization-learners.studentNumber' ,
@@ -163,11 +164,12 @@ const findProfilesCollectionResultDataByCampaignId = async function (campaignId)
163
164
} ;
164
165
165
166
const findOneByCampaignIdAndUserId = async function ( { campaignId, userId } ) {
166
- const campaignParticipation = await knex ( 'campaign-participations' )
167
+ const knexConn = DomainTransaction . getConnection ( ) ;
168
+ const campaignParticipation = await knexConn ( 'campaign-participations' )
167
169
. where ( { userId, isImproved : false , campaignId } )
168
170
. first ( ) ;
169
171
if ( ! campaignParticipation ) return null ;
170
- const assessments = await knex ( 'assessments' ) . where ( { campaignParticipationId : campaignParticipation . id } ) ;
172
+ const assessments = await knexConn ( 'assessments' ) . where ( { campaignParticipationId : campaignParticipation . id } ) ;
171
173
const campaign = await campaignRepository . get ( campaignId ) ;
172
174
return new CampaignParticipation ( {
173
175
...campaignParticipation ,
@@ -182,7 +184,8 @@ const findOneByCampaignIdAndUserId = async function ({ campaignId, userId }) {
182
184
} ;
183
185
184
186
const hasAssessmentParticipations = async function ( userId ) {
185
- const { count } = await knex ( 'assessments' )
187
+ const knexConn = DomainTransaction . getConnection ( ) ;
188
+ const { count } = await knexConn ( 'assessments' )
186
189
. count ( 'assessments.id' )
187
190
. leftJoin ( 'campaign-participations' , 'campaignParticipationId' , 'campaign-participations.id' )
188
191
. leftJoin ( 'campaigns' , 'campaigns.id' , 'campaignId' )
@@ -223,13 +226,14 @@ const getCodeOfLastParticipationToProfilesCollectionCampaignForUser = async func
223
226
} ;
224
227
225
228
const isRetrying = async function ( { campaignParticipationId } ) {
226
- const { id : campaignId , userId } = await knex ( 'campaigns' )
229
+ const knexConn = DomainTransaction . getConnection ( ) ;
230
+ const { id : campaignId , userId } = await knexConn ( 'campaigns' )
227
231
. select ( 'campaigns.id' , 'userId' )
228
232
. join ( 'campaign-participations' , 'campaigns.id' , 'campaignId' )
229
233
. where ( { 'campaign-participations.id' : campaignParticipationId } )
230
234
. first ( ) ;
231
235
232
- const campaignParticipations = await knex ( 'campaign-participations' )
236
+ const campaignParticipations = await knexConn ( 'campaign-participations' )
233
237
. select ( 'sharedAt' , 'isImproved' )
234
238
. where ( { campaignId, userId } ) ;
235
239
0 commit comments