Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
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
23 changes: 15 additions & 8 deletions app/config/rct-data/quality/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,23 @@
"obsolete": "0"
},
{
"id": "65500",
"method": "ObsoleteFlagExample",
"name": "Obsolete flag example",
"bad": "1",
"obsolete": "1"
"id": "32768",
"method": "Good",
"name": "Good",
"bad": "0",
"obsolete": "0"
},
{
"id": "32769",
"method": "Bad",
"name": "Bad",
"bad": "0",
"obsolete": "0"
},
{
"id": "65501",
"method": "NotBadFlagExample",
"name": "Not bad flag example",
"id": "32770",
"method": "Mixed",
"name": "Mixed",
"bad": "0",
"obsolete": "0"
},
Expand Down
4 changes: 4 additions & 0 deletions app/lib/database/adapters/QualityControlFlagAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class QualityControlFlagAdapter {
data_pass_id,
run_number,
detector_id,
entire,
timeStart,
timeEnd,
comment,
Expand All @@ -48,6 +49,7 @@ class QualityControlFlagAdapter {
data_pass_id,
run_number,
detector_id,
entire,
timeStart,
timeEnd,
comment,
Expand All @@ -71,6 +73,7 @@ class QualityControlFlagAdapter {
data_pass_id,
run_number,
detector_id,
entire,
timeStart,
timeEnd,
comment,
Expand All @@ -86,6 +89,7 @@ class QualityControlFlagAdapter {
data_pass_id,
run_number,
detector_id,
entire,
timeStart,
timeEnd,
comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ module.exports = {
},
bad: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
obsolate: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ module.exports = {
},
time_start: {
type: Sequelize.DATE,
allowNull: false,
allowNull: true,
},
time_end: {
type: Sequelize.DATE,
allowNull: true,
},
entire: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
comment: {
Expand All @@ -38,31 +42,31 @@ module.exports = {
},
run_number: {
type: Sequelize.INTEGER,
allowNull: true,
allowNull: false,
references: {
model: 'runs',
key: 'run_number',
},
},
data_pass_id: {
type: Sequelize.INTEGER,
allowNull: true,
allowNull: false,
references: {
model: 'data_passes',
key: 'id',
},
},
detector_id: {
type: Sequelize.INTEGER,
allowNull: true,
allowNull: false,
references: {
model: 'detectors_subsystems',
key: 'id',
},
},
flag_type_id: {
type: Sequelize.INTEGER,
allowNull: true,
allowNull: false,
references: {
model: 'flag_types_dictionary',
key: 'id',
Expand Down
2 changes: 0 additions & 2 deletions app/lib/database/models/FlagType.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ module.exports = (sequelize) => {
},
bad: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
obsolate: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
}, { timestamps: false, tableName: 'flag_types_dictionary'});
Expand Down
8 changes: 6 additions & 2 deletions app/lib/database/models/QualitControlFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const QualityControlFlag = sequelize.define('QualityControlFlag', {
entire: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
timeStart: {
type: Sequelize.DATE,
allowNull: false,
allowNull: true,
get() {
return Number(this.getDataValue('timeStart'))
}
},
timeEnd: {
type: Sequelize.DATE,
allowNull: false,
allowNull: true,
get() {
return Number(this.getDataValue('timeEnd'))
}
Expand Down
33 changes: 19 additions & 14 deletions app/lib/server/controllers/qualityControl.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
* or submit itself to any jurisdiction.
*/

const { O2TokenService } = require('@aliceo2/web-ui');
const { jwt } = require('../../config/configProvider');
const { qualityControlService } = require('../../services/qualityControl/QualityControlService');
const { stdDataRequestDTO } = require('../../domain/dtos');
const { validateDtoOrRepondOnFailure } = require('../utilities');
const Joi = require('joi');
const { adaptFindAndCountAllInService } = require('../../utils');
const { adaptFindAndCountAllInService, isInDevMode, isInTestMode, throwWrapper } = require('../../utils');

const getUser = (session) => session?.username ??
(isInDevMode() || isInTestMode() ? 'dev/test-anonymous' :
throwWrapper('Neither req.session.username is provided nor app is in dev or test mode'));

/**
* List All time based qualities / flags in db including their verification
Expand All @@ -44,36 +46,40 @@ const listAllTimeBasedFlagsHandler = async (req, res, next) => {
const createTimeBasedQualityControlFlag = async (req, res, next) => {
const customDTO = stdDataRequestDTO.concat(Joi.object({
query: {
time_end: Joi.number().required(),
time_start: Joi.number().required(),
entire: Joi.boolean().required(),
time_end: Joi.number().optional(),
time_start: Joi.number().optional(),
data_pass_id: Joi.number().required(),
run_number: Joi.number().required(),
detector_id: Joi.number().required(),
flag_type_id: Joi.number().required(),
comment: Joi.string().optional(),
},
}));

const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const {
entire,
time_end,
time_start,
data_pass_id,
run_number,
detector_id,
flag_type_id,
comment,
} = validatedDTO.query;

const { token } = req.query;

const entityParams = {
addedBy: token ? new O2TokenService(jwt).verify(token).username : 'test',
entire,
timeEnd: time_end,
timeStart: time_start,
data_pass_id: data_pass_id,
run_number: run_number,
detector_id: detector_id,
flag_type_id: flag_type_id,
addedBy: getUser(req.session),
data_pass_id,
run_number,
detector_id,
flag_type_id,
comment,
};
await qualityControlService.createTimeBasedQualityControlFlag(entityParams);
res.sendStatus(201);
Expand All @@ -96,10 +102,9 @@ const createTimeBasedQualityControlFlagVerification = async (req, res, next) =>

const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const { token } = req.query;
const entityParams = {
qcf_id: validatedDTO.params.qcFlagId,
verifiedBy: token ? new O2TokenService(jwt).verify(token).username : 'test',
verifiedBy: getUser(req.session),
};
await qualityControlService.createTimeBasedQualityControlFlagVerification(entityParams);
res.sendStatus(201);
Expand Down
1 change: 0 additions & 1 deletion app/lib/server/routers/qualityControl.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
args: { public: false },
children: [
{
path: '/time-based',
method: 'get',
controller: QualityControlController.listAllTimeBasedFlagsHandler,
description: 'List all time based qualities / flags present in DB, including their verifications',
Expand Down
6 changes: 3 additions & 3 deletions app/lib/services/qualityControl/QualityControlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class QualityControlService {
* @returns {Promise} Promise object represents the result of this use case.
*/
async createTimeBasedQualityControlFlag(entityParams) {
await QualityControlFlagRepository.T.create(entityParams);
await QualityControlFlagRepository.create(entityParams);
}

/**
Expand All @@ -71,7 +71,7 @@ class QualityControlService {
* @returns {Promise} Promise object represents the result of this use case.
*/
async deleteTimeBasedQualityControlFlag(id) {
return await QualityControlFlagRepository.T.removeOne({ where: { id } });
return await QualityControlFlagRepository.removeOne({ where: { id } });
}

/**
Expand All @@ -80,7 +80,7 @@ class QualityControlService {
* @returns {Promise} Promise object represents the result of this use case.
*/
async createTimeBasedQualityControlFlagVerification(entityParams) {
await QualityControlFlagVerificationRepository.T.create(entityParams);
await QualityControlFlagVerificationRepository.create(entityParams);
}
}

Expand Down