Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 48 additions & 43 deletions lib/server/services/qualityControlFlag/QcFlagService.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,50 +156,55 @@
const createdFlags = [];
for (const qcFlag of qcFlags) {
const { comment, flagTypeId, origin } = qcFlag;
const { from, to } = this._prepareQcFlagPeriod({ from: qcFlag.from, to: qcFlag.to }, targetRun);

// Insert
const newInstance = await QcFlagRepository.insert({
from,
to,
comment,
origin,
createdById: user.id,
flagTypeId,
runNumber,
detectorId: detector.id,
});
if (dataPass) {
await newInstance.addDataPass(dataPass);
} else if (simulationPass) {
await newInstance.addSimulationPass(simulationPass);
// Each flag should be treated separately and the for loop should not fail on the first error
try {
const { from, to } = this._prepareQcFlagPeriod({ from: qcFlag.from, to: qcFlag.to }, targetRun);

// Insert
const newInstance = await QcFlagRepository.insert({
from,
to,
comment,
origin,
createdById: user.id,
flagTypeId,
runNumber,
detectorId: detector.id,
});
if (dataPass) {
await newInstance.addDataPass(dataPass);
} else if (simulationPass) {
await newInstance.addSimulationPass(simulationPass);
}

/** @var {SequelizeQcFlag} createdFlag */
const createdFlag = await QcFlagRepository.findOne({
where: { id: newInstance.id },
include: [
{ association: 'dataPasses' },
{ association: 'simulationPasses' },
{ association: 'createdBy' },
],
});

// Update effective periods
const effectivePeriodsToBeUpdated = await QcFlagEffectivePeriodRepository.findOverlappingPeriodsCreatedBeforeLimit(
{ from, to },
createdFlag.createdAt,
{ dataPassId: dataPass?.id, simulationPassId: simulationPass?.id, runNumber, detectorId: detector.id },
);
await this._removeEffectivePeriodsAndPeriodIntersection(createdFlag, effectivePeriodsToBeUpdated);

await QcFlagEffectivePeriodRepository.insert({
flagId: newInstance.id,
from: newInstance.from,
to: newInstance.to,
});

createdFlags.push(qcFlagAdapter.toEntity(createdFlag));
} catch (error) {
this._logger.warnMessage(`Failed to create QC flag with properties: ${JSON.stringify(qcFlag)}. Error: ${error}`);

Check warning on line 206 in lib/server/services/qualityControlFlag/QcFlagService.js

View check run for this annotation

Codecov / codecov/patch

lib/server/services/qualityControlFlag/QcFlagService.js#L206

Added line #L206 was not covered by tests
}

/** @var {SequelizeQcFlag} createdFlag */
const createdFlag = await QcFlagRepository.findOne({
where: { id: newInstance.id },
include: [
{ association: 'dataPasses' },
{ association: 'simulationPasses' },
{ association: 'createdBy' },
],
});

// Update effective periods
const effectivePeriodsToBeUpdated = await QcFlagEffectivePeriodRepository.findOverlappingPeriodsCreatedBeforeLimit(
{ from, to },
createdFlag.createdAt,
{ dataPassId: dataPass?.id, simulationPassId: simulationPass?.id, runNumber, detectorId: detector.id },
);
await this._removeEffectivePeriodsAndPeriodIntersection(createdFlag, effectivePeriodsToBeUpdated);

await QcFlagEffectivePeriodRepository.insert({
flagId: newInstance.id,
from: newInstance.from,
to: newInstance.to,
});

createdFlags.push(qcFlagAdapter.toEntity(createdFlag));
}
return createdFlags;
});
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aliceo2/bookkeeping",
"version": "1.9.1",
"version": "1.9.2",
"author": "ALICEO2",
"scripts": {
"coverage": "nyc npm test && npm run coverage:report",
Expand Down
Loading