Skip to content

Commit 0a9e241

Browse files
authored
[O2B-1115] Implement runs per data pass API (#1332)
* add migration * add references * add model associations * add jsonRequest method * add abstract synchronizer * cleanup * cleanup * cleanup * cleanup * cleanup * simplify * cleanup * cleanup * add monalisa service * docs annotation * refactor * change main method to return void instead of boolean * db action * handle field mappings * remove abstract class * single concrete class * add variables * use env vars * linter * refactor * docs refactor * typo * refactor * refactor * fixes * refactored * not then chain * refactor{ * types * rename * use seuqlize to fetch last runs * add type, use URL class * remove file read * docs * add synchronizer factory * add docs * cleanup * no await * refactor * typdef * refactor context * rename * docs * docs * rename * working * rename * rename * add test for getting data passes * add test for getting data passes * sync test * add test for data pass sync * amend data * add details fetching * add env * fetching data passes and details * rename * add tests * rename * reduce test data size * docs * refactor * typo * typo * docs * rename * docs * cleanup * remove dead code * add service * cleanup * add filtering by periods * add data passes seeders * rename * add data passes service tests * test * revoke unfound changes * add controllers * rename * refactor * refactor * refactor * no dependency * refactor * refactor * refactor: * reaname' * rename * cleanup * docs * reaname * refactor * add router * restore * amend test * expose api * add test * add tests * amend * docs * amend test * amend * add Data Passes page * expose page * styling * add reset method * rename * use sorting * add unit * docs * add filtering by data pass id * add test * amend test * amend test * use name instead of id * amend test * rename * rename * use filtering by name * add test * use generic model * aboid undefined destruciton error * use proper method * cleanup * linter * make uppercase * amend test * use id * use builder * simplify * remove unncessary stm * use raw query * cleanup
1 parent b7dead5 commit 0a9e241

4 files changed

Lines changed: 28 additions & 25 deletions

File tree

lib/database/utilities/QueryBuilder.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,6 @@ class WhereAssociationQueryBuilder extends WhereQueryBuilder {
356356
this._sequelize = sequelize;
357357

358358
this.association = association;
359-
const sequelizeAssociation = this.queryBuilder.model.associations[this.association];
360-
361-
/**
362-
* In order to utilise the builder with association properly,
363-
* it is needed to know cardinality of the association.
364-
* Existance of property 'through' indicated
365-
* that the association is many-to-many, otherwise, it is one-to-many or one-to-one.
366-
* Depending whether it is true or not a name of target model
367-
* will be acquired in different ways.
368-
* Also construction of 'where clause' in @see _op
369-
* is dependent on that cardinality.
370-
*/
371-
this.isAssociationThroughJunctionTable = Boolean(sequelizeAssociation.through);
372-
this.associatedModelName = this.isAssociationThroughJunctionTable ?
373-
sequelizeAssociation.toTarget.as
374-
: sequelizeAssociation.target.name;
375359
}
376360

377361
/**
@@ -382,17 +366,11 @@ class WhereAssociationQueryBuilder extends WhereQueryBuilder {
382366
*/
383367
_op(operation) {
384368
this.queryBuilder.include({
385-
model: this._sequelize.models[this.associatedModelName],
386-
as: this.association,
369+
association: this.association,
387370
required: true,
388-
through: this.isAssociationThroughJunctionTable ? {
389-
where: {
390-
[`${this.associatedModelName}_${this.column}`]: operation,
391-
},
392-
} : undefined,
393-
where: !this.isAssociationThroughJunctionTable ? {
371+
where: {
394372
[this.column]: operation,
395-
} : undefined,
373+
},
396374
});
397375

398376
return this.queryBuilder;

lib/domain/dtos/filters/RunFilterDto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ exports.RunFilterDto = Joi.object({
5454
odcTopologyFullName: Joi.string().trim(),
5555
detectors: DetectorsFilterDto,
5656
lhcPeriods: Joi.string().trim(),
57+
dataPassIds: Joi.array().items(Joi.number()),
5758
runTypes: CustomJoi.stringArray().items(Joi.string()).single().optional(),
5859
updatedAt: FromToFilterDto,
5960
});

lib/usecases/run/GetAllRunsUseCase.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class GetAllRunsUseCase {
4848
epn,
4949
fillNumbers,
5050
lhcPeriods,
51+
dataPassIds,
5152
nDetectors,
5253
nEpns,
5354
nFlps,
@@ -233,6 +234,20 @@ class GetAllRunsUseCase {
233234
});
234235
}
235236

237+
if (dataPassIds) {
238+
const runNumbers = (await RunRepository.findAll({
239+
attributes: ['runNumber'],
240+
raw: true,
241+
include: [
242+
{
243+
association: 'dataPass',
244+
where: { id: { [Op.in]: dataPassIds } },
245+
},
246+
],
247+
})).map(({ runNumber }) => runNumber);
248+
filteringQueryBuilder.where('runNumber').oneOf(...runNumbers);
249+
}
250+
236251
if (tags && tags.values.length > 0) {
237252
if (tags.operation === 'and') {
238253
const runsWithExpectedTags = await RunRepository.findAll({

test/api/runs.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ module.exports = () => {
219219
expect(data.every(({ definition }) => definition === RunDefinition.Physics)).to.be.true;
220220
});
221221

222+
it ('should succefully filter on data pass id', async () => {
223+
const response = await request(server).get('/api/runs?filter[dataPassIds][]=2&filter[dataPassIds][]=3');
224+
expect(response.status).to.equal(200);
225+
226+
const { data } = response.body;
227+
expect(data).to.lengthOf(7);
228+
expect(data.map(({ runNumber }) => runNumber)).to.have.all.members([1, 2, 55, 49, 54, 56, 105]);
229+
});
230+
222231
it('should return 400 if o2start "to" date is before "from" date', (done) => {
223232
request(server)
224233
.get('/api/runs?filter[o2start][from]=946771200000&filter[o2start][to]=946684800000')

0 commit comments

Comments
 (0)