Skip to content

Commit a37539c

Browse files
authored
[O2B-1183] Add QC flag types fetching by id endpoint (#1441)
* WIP * rename * fix * amend association * fix naming * fix adapter * rename * add user to verification * cleanup * amend naming * a * typo * docs * insertion works * add ver repo * styling * docs * docs * expose service * docs * docs * correct return * WIP * add pagination * add filtering * controller WIP * docs * correct export * correct columns names * correct filtering * add router * controller * amend associations * amend count * add pagination dto * disallow null * adapt time * merge main * squash code * hadle incorrect states * add seeder * time range * fix timestamp format * add timestamps to seeder * test WIP * fetching tests ok * WIP * amend test * test passing * amend linter * docs * ver test WIP * ver test OK * add addociation name * add controller * add router * add repo * add repo * get all reasons service function * add test * add ep,; test WIP * add provenenace * revoke * test WIP * t WIP * test * WIP * simplify test * wIP * WIP * change error messages * qcf creation test ok * add coalesc comment to null * expose ep * a * add test ok * typo * typo * miss * fixed * revoke * rm verifications * cherry-pick * name archived * obsolate to archived * simplify association * a * Revert "a" This reverts commit a7b880c. * Revert "simplify association" This reverts commit ad453da. * docs * rename * simplify * refactor * refactor * refactor * a * add assoc * rename * cleanup * fix associations * comment * rename table * reason to type * rename * rename * docs * cleanup * refactor * rename * fix * WIP * typo * fix * WIP * typo * rename * serv fixed * seeders * fix Test * simp * docs * WIP * add test * rename * update * fix test * wip * clean * clean * cleanup * add modification control * update modification control * update associatioin name * update * test ok * test ok * docs * add color * add color * test ok * add assoc name * add seeder * cherry-pick * cleanup * cleanup * use QC * restore * fix * use QC * abbr * abbr * abbr * amend endpoint * fetch works * filtering works * works * test * test ok * new test * test ok * rename * add timeout * validator * validator * megre main * simp * simp * docs * simp * refactor * rename * rename * simp * rename * rename * a * renam * rename * rename * rename * docs * docs * change endpoint * ep * rename * amend
1 parent b594eb5 commit a37539c

17 files changed

Lines changed: 472 additions & 36 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
/**
15+
* QcFlagTypeAdapter
16+
*/
17+
class QcFlagTypeAdapter {
18+
/**
19+
* Constructor
20+
*/
21+
constructor() {
22+
this.toEntity = this.toEntity.bind(this);
23+
this.userAdapter = null;
24+
}
25+
26+
/**
27+
* Converts the given database object to an entity object.
28+
*
29+
* @param {SequelizeQcFlagType} databaseObject Object to convert.
30+
* @returns {QcFlagType} Converted entity object.
31+
*/
32+
toEntity(databaseObject) {
33+
const {
34+
id,
35+
name,
36+
method,
37+
bad,
38+
color,
39+
40+
createdBy,
41+
createdById,
42+
createdAt,
43+
44+
lastUpdatedBy,
45+
lastUpdatedById,
46+
updatedAt,
47+
48+
archived,
49+
archivedAt,
50+
} = databaseObject;
51+
52+
return {
53+
id,
54+
name,
55+
method,
56+
bad,
57+
color,
58+
59+
createdBy: createdBy ? this.userAdapter.toEntity(createdBy) : null,
60+
createdById,
61+
createdAt: createdAt ? new Date(createdAt).getTime() : null,
62+
63+
lastUpdatedBy: lastUpdatedBy ? this.userAdapter.toEntity(lastUpdatedBy) : null,
64+
lastUpdatedById,
65+
updatedAt: updatedAt ? new Date(updatedAt).getTime() : null,
66+
67+
archived,
68+
archivedAt: archivedAt ? new Date(archivedAt).getTime() : null,
69+
};
70+
}
71+
}
72+
73+
module.exports = { QcFlagTypeAdapter };

lib/database/adapters/index.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ const LhcPeriodAdapter = require('./LhcPeriodAdapter');
3838
const LhcPeriodStatisticsAdapter = require('./LhcPeriodStatisticsAdapter');
3939
const DataPassAdapter = require('./DataPassAdapter');
4040
const SimulationPassAdapter = require('./SimulationPassAdapter.js');
41+
const { QcFlagTypeAdapter } = require('./QcFlagTypeAdapter');
4142

4243
const attachmentAdapter = new AttachmentAdapter();
44+
const dataPassAdapter = new DataPassAdapter();
4345
const detectorAdapter = new DetectorAdapter();
4446
const dplDetectorAdapter = new DplDetectorAdapter();
45-
const dplProcessExecutionAdapter = new DplProcessExecutionAdapter();
4647
const dplProcessAdapter = new DplProcessAdapter();
48+
const dplProcessExecutionAdapter = new DplProcessExecutionAdapter();
4749
const dplProcessTypeAdapter = new DplProcessTypeAdapter();
4850
const environmentAdapter = new EnvironmentAdapter();
4951
const environmentHistoryItemAdapter = new EnvironmentHistoryItemAdapter();
@@ -52,34 +54,34 @@ const flpRoleAdapter = new FlpRoleAdapter();
5254
const hostAdapter = new HostAdapter();
5355
const lhcFillAdapter = new LhcFillAdapter();
5456
const lhcFillStatisticsAdapter = new LhcFillStatisticsAdapter();
57+
const lhcPeriodAdapter = new LhcPeriodAdapter();
58+
const lhcPeriodStatisticsAdapter = new LhcPeriodStatisticsAdapter();
5559
const logAdapter = new LogAdapter();
5660
const logRunsAdapter = new LogRunsAdapter();
5761
const logTagsAdapter = new LogTagsAdapter();
62+
const qcFlagTypeAdapter = new QcFlagTypeAdapter();
5863
const reasonTypeAdapter = new ReasonTypeAdapter();
5964
const runAdapter = new RunAdapter();
60-
const runTypeAdapter = new RunTypeAdapter();
6165
const runDetectorsAdapter = new RunDetectorsAdapter();
66+
const runTypeAdapter = new RunTypeAdapter();
67+
const simulationPassAdapter = new SimulationPassAdapter();
6268
const subsystemAdapter = new SubsystemAdapter();
6369
const tagAdapter = new TagAdapter();
6470
const userAdapter = new UserAdapter();
65-
const lhcPeriodAdapter = new LhcPeriodAdapter();
66-
const lhcPeriodStatisticsAdapter = new LhcPeriodStatisticsAdapter();
67-
const dataPassAdapter = new DataPassAdapter();
68-
const simulationPassAdapter = new SimulationPassAdapter();
6971

7072
// Fill dependencies
7173
dplDetectorAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;
7274

73-
dplProcessExecutionAdapter.hostAdapter = hostAdapter;
75+
dplProcessAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;
76+
dplProcessAdapter.dplProcessTypeAdapter = dplProcessTypeAdapter;
77+
7478
dplProcessExecutionAdapter.dplDetectorAdapter = dplDetectorAdapter;
7579
dplProcessExecutionAdapter.dplProcessAdapter = dplProcessAdapter;
80+
dplProcessExecutionAdapter.hostAdapter = hostAdapter;
7681
dplProcessExecutionAdapter.runAdapter = runAdapter;
7782

78-
dplProcessAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;
79-
dplProcessAdapter.dplProcessTypeAdapter = dplProcessTypeAdapter;
80-
81-
environmentAdapter.runAdapter = runAdapter;
8283
environmentAdapter.environmentHistoryItemAdapter = environmentHistoryItemAdapter;
84+
environmentAdapter.runAdapter = runAdapter;
8385

8486
eorReasonAdapter.reasonTypeAdapter = reasonTypeAdapter;
8587

@@ -90,30 +92,33 @@ hostAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;
9092
lhcFillAdapter.runAdapter = runAdapter;
9193
lhcFillAdapter.statisticsAdapter = lhcFillStatisticsAdapter;
9294

93-
logAdapter.runAdapter = runAdapter;
95+
lhcPeriodStatisticsAdapter.lhcPeriodAdapter = lhcPeriodAdapter;
96+
9497
logAdapter.attachmentAdapter = attachmentAdapter;
98+
logAdapter.environmentAdapter = environmentAdapter;
99+
logAdapter.lhcFillAdapter = lhcFillAdapter;
100+
logAdapter.runAdapter = runAdapter;
95101
logAdapter.subsystemAdapter = subsystemAdapter;
96102
logAdapter.tagAdapter = tagAdapter;
97103
logAdapter.userAdapter = userAdapter;
98-
logAdapter.lhcFillAdapter = lhcFillAdapter;
99-
logAdapter.environmentAdapter = environmentAdapter;
100104

101-
runAdapter.logAdapter = logAdapter;
102-
runAdapter.tagAdapter = tagAdapter;
105+
qcFlagTypeAdapter.userAdapter = userAdapter;
106+
103107
runAdapter.eorReasonAdapter = eorReasonAdapter;
104-
runAdapter.runTypeAdapter = runTypeAdapter;
105-
runAdapter.lhcFillAdapter = lhcFillAdapter;
106108
runAdapter.flpRoleAdapter = flpRoleAdapter;
109+
runAdapter.lhcFillAdapter = lhcFillAdapter;
107110
runAdapter.lhcPeriodAdapter = lhcPeriodAdapter;
108-
109-
lhcPeriodStatisticsAdapter.lhcPeriodAdapter = lhcPeriodAdapter;
111+
runAdapter.logAdapter = logAdapter;
112+
runAdapter.runTypeAdapter = runTypeAdapter;
113+
runAdapter.tagAdapter = tagAdapter;
110114

111115
module.exports = {
112116
attachmentAdapter,
117+
dataPassAdapter,
113118
detectorAdapter,
114119
dplDetectorAdapter,
115-
dplProcessExecutionAdapter,
116120
dplProcessAdapter,
121+
dplProcessExecutionAdapter,
117122
dplProcessTypeAdapter,
118123
environmentAdapter,
119124
environmentHistoryItemAdapter,
@@ -122,18 +127,18 @@ module.exports = {
122127
hostAdapter,
123128
lhcFillAdapter,
124129
lhcFillStatisticsAdapter,
130+
lhcPeriodAdapter,
131+
lhcPeriodStatisticsAdapter,
125132
logAdapter,
126133
logRunsAdapter,
127134
logTagsAdapter,
135+
qcFlagTypeAdapter,
128136
reasonTypeAdapter,
129137
runAdapter,
130-
runTypeAdapter,
131138
runDetectorsAdapter,
139+
runTypeAdapter,
140+
simulationPassAdapter,
132141
subsystemAdapter,
133142
tagAdapter,
134143
userAdapter,
135-
lhcPeriodAdapter,
136-
lhcPeriodStatisticsAdapter,
137-
dataPassAdapter,
138-
simulationPassAdapter,
139144
};

lib/database/models/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const User = require('./user');
3737
const LhcPeriod = require('./lhcPeriod');
3838
const LhcPeriodStatistics = require('./lhcPeriodsStatistics');
3939
const DataPass = require('./dataPass.js');
40-
const QCFlagType = require('./qcFlagType.js');
40+
const QcFlagType = require('./qcFlagType.js');
4141
const SimulationPass = require('./simulationPass.js');
4242

4343
module.exports = (sequelize) => {
@@ -68,7 +68,7 @@ module.exports = (sequelize) => {
6868
LhcPeriod: LhcPeriod(sequelize),
6969
LhcPeriodStatistics: LhcPeriodStatistics(sequelize),
7070
DataPass: DataPass(sequelize),
71-
QCFlagType: QCFlagType(sequelize),
71+
QcFlagType: QcFlagType(sequelize),
7272
SimulationPass: SimulationPass(sequelize),
7373
};
7474

lib/database/models/qcFlagType.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
const Sequelize = require('sequelize');
1515

1616
module.exports = (sequelize) => {
17-
const QCFlagType = sequelize.define(
18-
'QCFlagType',
17+
const QcFlagType = sequelize.define(
18+
'QcFlagType',
1919
{
2020
id: {
2121
type: Sequelize.INTEGER,
@@ -60,10 +60,10 @@ module.exports = (sequelize) => {
6060
{ tableName: 'quality_control_flag_types' },
6161
);
6262

63-
QCFlagType.associate = (models) => {
64-
QCFlagType.belongsTo(models.User, { as: 'createdBy', foreignKey: 'createdById' });
65-
QCFlagType.belongsTo(models.User, { as: 'lastUpdatedBy', foreignKey: 'lastUpdatedById' });
63+
QcFlagType.associate = (models) => {
64+
QcFlagType.belongsTo(models.User, { as: 'createdBy', foreignKey: 'createdById' });
65+
QcFlagType.belongsTo(models.User, { as: 'lastUpdatedBy', foreignKey: 'lastUpdatedById' });
6666
};
6767

68-
return QCFlagType;
68+
return QcFlagType;
6969
};

lib/database/models/typedefs/SequelizeQCFlagType.js renamed to lib/database/models/typedefs/SequelizeQcFlagType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
/**
15-
* @typedef SequelizeQCFlagType
15+
* @typedef SequelizeQcFlagType
1616
*
1717
* @property {number} id
1818
* @property {string} name
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
const { models: { QcFlagType } } = require('..');
15+
const Repository = require('./Repository');
16+
17+
/**
18+
* Sequelize implementation of the QcFlagTypeRepository.
19+
*/
20+
class QcFlagTypeRepository extends Repository {
21+
/**
22+
* Creates a new `QcFlagTypeRepository` instance.
23+
*/
24+
constructor() {
25+
super(QcFlagType);
26+
}
27+
}
28+
29+
module.exports = new QcFlagTypeRepository();

lib/database/repositories/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const LhcPeriodRepository = require('./LhcPeriodRepository');
4242
const LhcPeriodStatisticsRepository = require('./LhcPeriodStatisticsRepository');
4343
const DataPassRepository = require('./DataPassRepository.js');
4444
const SimulationPassRepository = require('./SimulationPassRepository.js');
45+
const QcFlagTypeRepository = require('./QcFlagTypeRepository.js');
4546

4647
module.exports = {
4748
AttachmentRepository,
@@ -75,4 +76,5 @@ module.exports = {
7576
LhcPeriodStatisticsRepository,
7677
DataPassRepository,
7778
SimulationPassRepository,
79+
QcFlagTypeRepository,
7880
};

lib/domain/entities/qcFlagType.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
/**
15+
* @typedef QcFlagType
16+
*
17+
* @property {number} id
18+
* @property {string} name
19+
* @property {string} method
20+
* @property {boolean} bad
21+
* @property {string} color as hex
22+
*
23+
* @property {boolean} archived
24+
* @property {number} archivedAt
25+
*
26+
* @property {number} createdAt
27+
* @property {number} createdById
28+
* @property {User} createdBy
29+
* @property {number} updatedAt
30+
* @property {number} lastUpdatedById
31+
* @property {User} lastUpdatedBy
32+
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
const Joi = require('joi');
15+
const { DtoFactory } = require('../../domain/dtos/DtoFactory');
16+
const { dtoValidator } = require('../utilities/dtoValidator.js');
17+
const { updateExpressResponseFromNativeError } = require('../express/updateExpressResponseFromNativeError');
18+
const { qcFlagTypeService } = require('../services/qualityControlFlag/QcFlagTypeService');
19+
20+
// eslint-disable-next-line valid-jsdoc
21+
/**
22+
* Get one QC Flag Type by its id
23+
*/
24+
const getQcFlagTypeByIdHandler = async (req, res) => {
25+
const validatedDTO = await dtoValidator(
26+
DtoFactory.paramsOnly({ id: Joi.number() }),
27+
req,
28+
res,
29+
);
30+
if (validatedDTO) {
31+
try {
32+
const qcFlagType = await qcFlagTypeService.getOneOrFail(validatedDTO.params.id);
33+
res.json({ data: qcFlagType });
34+
} catch (error) {
35+
updateExpressResponseFromNativeError(res, error);
36+
}
37+
}
38+
};
39+
40+
exports.QcFlagTypesController = {
41+
getQcFlagTypeByIdHandler,
42+
};

lib/server/routers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const tagsRoute = require('./tags.router');
3232
const { lhcPeriodsRouter } = require('./lhcPeriodsStatistics.router.js');
3333
const { isInTestMode } = require('../../utilities/env-utils');
3434
const { dataPassesRouter } = require('./dataPasses.router');
35+
const { qcFlagTypesRouter } = require('./qcFlagTypes.router.js');
3536
const { simulationPassesRouter } = require('./simulationPasses.router.js');
3637
const { dplDetectorsRouter } = require('./dplDetectors.router');
3738

@@ -55,6 +56,7 @@ const routes = [
5556
tagsRoute,
5657
lhcPeriodsRouter,
5758
dataPassesRouter,
59+
qcFlagTypesRouter,
5860
simulationPassesRouter,
5961
dplDetectorsRouter,
6062
];

0 commit comments

Comments
 (0)