@@ -135,7 +135,7 @@ class QcFlagService {
135135 throw new BadParameterError ( 'Cannot create QC flag for data pass and simulation pass simultaneously' ) ;
136136 }
137137
138- return dataSource . transaction ( async ( ) => {
138+ return dataSource . transaction ( async ( transaction ) => {
139139 const user = await getUserOrFail ( { userId, externalUserId } ) ;
140140 const detector = await getQcDetectorOrFail ( detectorIdentifier ) ;
141141
@@ -156,7 +156,7 @@ class QcFlagService {
156156
157157 const createdFlags = [ ] ;
158158 for ( const qcFlag of qcFlags ) {
159- const { comment, flagTypeId, origin } = qcFlag ;
159+ const { comment, flagTypeId, origin, verify } = qcFlag ;
160160 // Each flag should be treated separately and the for loop should not fail on the first error
161161 try {
162162 const { from, to } = this . _prepareQcFlagPeriod ( { from : qcFlag . from , to : qcFlag . to } , targetRun ) ;
@@ -179,14 +179,7 @@ class QcFlagService {
179179 }
180180
181181 /** @var {SequelizeQcFlag} createdFlag */
182- const createdFlag = await QcFlagRepository . findOne ( {
183- where : { id : newInstance . id } ,
184- include : [
185- { association : 'dataPasses' } ,
186- { association : 'simulationPasses' } ,
187- { association : 'createdBy' } ,
188- ] ,
189- } ) ;
182+ let createdFlag = await QcFlagRepository . findOne ( { where : { id : newInstance . id } } ) ;
190183
191184 // Update effective periods
192185 const effectivePeriodsToBeUpdated = await QcFlagEffectivePeriodRepository . findOverlappingPeriodsCreatedBeforeLimit (
@@ -202,6 +195,20 @@ class QcFlagService {
202195 to : newInstance . to ,
203196 } ) ;
204197
198+ if ( verify ) {
199+ await this . verifyFlag ( { flagId : newInstance . id } , relations , { transaction } ) ;
200+ }
201+
202+ createdFlag = await QcFlagRepository . findOne ( {
203+ where : { id : newInstance . id } ,
204+ include : [
205+ { association : 'dataPasses' } ,
206+ { association : 'simulationPasses' } ,
207+ { association : 'createdBy' } ,
208+ { association : 'verifications' } ,
209+ ] ,
210+ } ) ;
211+
205212 createdFlags . push ( qcFlagAdapter . toEntity ( createdFlag ) ) ;
206213 } catch ( error ) {
207214 this . _logger . warnMessage ( `Failed to create QC flag with properties: ${ JSON . stringify ( qcFlag ) } . Error: ${ error } ` ) ;
@@ -359,9 +366,11 @@ class QcFlagService {
359366 * @param {object } relations QC Flag entity relations
360367 * @param {UserWithRoles } relations.user user identifier with roles
361368 * @return {Promise<QcFlag> } promise
369+ * @param {object } [options] options
370+ * @param {sequelize.Transaction } [options.transaction] sequelize transaction
362371 * @throws {NotFoundError|AccessDeniedError }
363372 */
364- async verifyFlag ( { flagId, comment } , relations ) {
373+ async verifyFlag ( { flagId, comment } , relations , { transaction } = { } ) {
365374 return dataSource . transaction ( async ( ) => {
366375 const qcFlag = await this . getOneOrFail ( flagId ) ;
367376 if ( qcFlag . deleted ) {
@@ -381,7 +390,7 @@ class QcFlagService {
381390 } ) ;
382391
383392 return await this . getOneOrFail ( flagId ) ;
384- } ) ;
393+ } , { transaction } ) ;
385394 }
386395
387396 /**
0 commit comments