Skip to content
28 changes: 19 additions & 9 deletions lib/database/adapters/DataPassAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DataPassAdapter {
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.dataPassVersionAdapter = null;
}

Expand All @@ -30,13 +31,22 @@ class DataPassAdapter {
* @returns {DataPass} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
name,
versions,
skimmingStage,
isFrozen,
} = databaseObject;
const { versions = [] } = databaseObject;

const entity = this.toSummary(databaseObject);
entity.versions = versions.map(this.dataPassVersionAdapter.toEntity);

return entity;
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeDataPass} databaseObject Object to convert.
* @returns {DataPass} Converted entity object.
*/
toSummary(databaseObject) {
const { id, name, skimmingStage, versions = [], isFrozen } = databaseObject;

const runsCount = databaseObject.get('runsCount');
const simulationPassesCount = databaseObject.get('simulationPassesCount');
Expand All @@ -45,9 +55,9 @@ class DataPassAdapter {
return {
id,
name,
skimmingStage,
versions: (versions ?? []).map(this.dataPassVersionAdapter.toEntity),
versions: versions.map(this.dataPassVersionAdapter.toSummary),
pdpBeamTypes,
skimmingStage,
runsCount,
simulationPassesCount,
isFrozen,
Expand Down
37 changes: 22 additions & 15 deletions lib/database/adapters/DataPassVersionAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DataPassVersionAdapter {
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.dataPassVersionStatusAdapter = null;
}

Expand All @@ -30,32 +31,38 @@ class DataPassVersionAdapter {
* @returns {DataPass} Converted entity object.
*/
toEntity(databaseObject) {
const entity = this.toSummary(databaseObject);
const { id, dataPassId, lastSeen, statusHistory = [], createdAt, updatedAt } = databaseObject;

entity.statusHistory = statusHistory.map(this.dataPassVersionStatusAdapter.toEntity);
entity.id = id;
entity.dataPassId = dataPassId;
entity.lastSeen = lastSeen;
entity.createdAt = createdAt ? new Date(createdAt).getTime() : null;
entity.updatedAt = updatedAt ? new Date(updatedAt).getTime() : null;

return entity;
}

/**
* Converts the given database object to an summary object.
*
* @param {SequelizeDataPass} databaseObject Object to convert.
* @returns {DataPass} Converted summary object.
*/
toSummary(databaseObject) {
const {
id,
dataPassId,
description,
reconstructedEventsCount,
outputSize,
lastSeen,

statusHistory = [],

createdAt,
updatedAt,
} = databaseObject;

return {
id,
dataPassId,
description,
reconstructedEventsCount,
outputSize,
lastSeen,

statusHistory: (statusHistory ?? []).map(this.dataPassVersionStatusAdapter.toEntity),

createdAt: createdAt ? new Date(createdAt).getTime() : null,
updatedAt: updatedAt ? new Date(updatedAt).getTime() : null,
statusHistory: statusHistory.map(this.dataPassVersionStatusAdapter.toSummary),
};
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/database/adapters/DataPassVersionStatusAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class DataPassVersionStatusAdapter {
createdAt: createdAt ? new Date(createdAt).getTime() : null,
};
}

/**
* Converts the given database object to an summary object.
*
* @param {SequelizeDataPassVersionStatus} databaseObject Object to convert.
* @returns {DataPassVersionStatus} Converted summary object.
*/
toSummary(databaseObject) {
const { status } = databaseObject;
return { status };
}
}

module.exports = { DataPassVersionStatusAdapter };
20 changes: 20 additions & 0 deletions lib/database/adapters/EnvironmentAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EnvironmentAdapter {
this.environmentHistoryItemAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.toDatabase = this.toDatabase.bind(this);
}

Expand Down Expand Up @@ -64,6 +65,25 @@ class EnvironmentAdapter {
};
}

/**
* Converts the given database object to a summary object.
* @param {SequelizeEnvironment} databaseObject Object to convert.
* @returns {Environment} Converted summary object.
*/
toSummary(databaseObject) {
const { id, createdAt, runs, updatedAt, historyItems } = databaseObject;
const lastHistoryItem = historyItems.at(-1);

return {
id,
runs: runs.map(this.runAdapter.toMinifiedEntity),
historyItems,
status: lastHistoryItem?.status,
createdAt: new Date(createdAt).getTime(),
updatedAt: new Date(updatedAt).getTime(),
};
}

/**
* Converts the given entity object to a database object
*
Expand Down
19 changes: 15 additions & 4 deletions lib/database/adapters/EorReasonAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EorReasonAdapter {
this.reasonTypeAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.toDatabase = this.toDatabase.bind(this);
}

Expand All @@ -34,21 +35,31 @@ class EorReasonAdapter {
* @returns {EorReason} Converted entity object.
*/
toEntity({ id, description, runId, reasonTypeId, reasonType, lastEditedName, createdAt, updatedAt }) {
const entityObject = {
return {
...this.toSummary({ description, reasonType }),
id,
description,
lastEditedName,
reasonTypeId,
runId,
reasonTypeId,
lastEditedName,
createdAt: new Date(createdAt).getTime(),
updatedAt: new Date(updatedAt).getTime(),
};
}

/**
* Converts the given end of run reason database object to an summary reason object.
* @param {SequelizeEorReason} databaseObject Object to convert.
* @returns {EorReason} Converted summary object.
*/
toSummary({ description, reasonType }) {
const entityObject = { description };

if (reasonType) {
const reasonTypeEntity = this.reasonTypeAdapter.toEntity(reasonType);
entityObject.category = reasonTypeEntity.category;
entityObject.title = reasonTypeEntity.title;
}

return entityObject;
}

Expand Down
19 changes: 16 additions & 3 deletions lib/database/adapters/LhcFillAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LhcFillAdapter {
this.statisticsAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.toDatabase = this.toDatabase.bind(this);
}

Expand All @@ -40,6 +41,19 @@ class LhcFillAdapter {
* @returns {LhcFill} Converted entity object.
*/
toEntity(databaseObject) {
const { runs = [] } = databaseObject;
const entity = this.toSummary(databaseObject);
entity.runs = runs.map(this.runAdapter.toEntity);

return entity;
}

/**
* Adapts the fill entity to a minified version.
* @param {SequelizeLhcFill} databaseObject fill object
* @returns {MinifiedLSequelizeLhcFill} minified version of the fill entity
*/
toSummary(databaseObject) {
const {
fillNumber,
stableBeamsStart,
Expand All @@ -49,12 +63,11 @@ class LhcFillAdapter {
fillingSchemeName,
collidingBunchesCount,
deliveredLuminosity,
runs: sequelizeRuns,
runs = [],
statistics: sequelizeStatistics,
} = databaseObject;

const statistics = sequelizeStatistics ? this.statisticsAdapter.toEntity(sequelizeStatistics) : null;
const runs = (sequelizeRuns || []).map(this.runAdapter.toEntity);

return {
fillNumber,
Expand All @@ -66,7 +79,7 @@ class LhcFillAdapter {
collidingBunchesCount,
deliveredLuminosity,
statistics,
runs,
runs: runs.map(this.runAdapter.toLhcFillSummary),
};
}

Expand Down
45 changes: 45 additions & 0 deletions lib/database/adapters/LogAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LogAdapter {
this.userAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.toDatabase = this.toDatabase.bind(this);
}

Expand Down Expand Up @@ -108,6 +109,50 @@ class LogAdapter {
return entityObject;
}

/**
* Adapts the log entity to a minified version.
* @param {SequelizeLog} databaseObject Object to convert.
* @returns {MinifiedLog} minified version of the log entity
*/
toSummary(databaseObject) {
const {
id,
title,
text,
user,
createdAt,
rootLogId,
parentLogId,
replies,
tags = [],
runs = [],
lhcFills = [],
attachments = [],
environments = [],
} = databaseObject;

const entityObject = {
id,
title,
text,
author: user ? this.userAdapter.toNameOnly(user) : { name: 'Anonymous' },
createdAt: new Date(createdAt).getTime(),
rootLogId: rootLogId || id,
parentLogId: parentLogId || id,
runs: runs.map(this.runAdapter.toMinifiedEntity),
tags: tags.map(this.tagAdapter.toSummary),
lhcFills: lhcFills.map(({ fillNumber }) => ({ fillNumber })),
attachments: attachments.map(({ id }) => ({ id })),
environments: environments.map(({ id }) => ({ id })),
};

if (replies) {
entityObject.replies = replies;
}

return entityObject;
}

/**
* Converts the given entity object to a database object.
*
Expand Down
18 changes: 18 additions & 0 deletions lib/database/adapters/QcFlagAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,31 @@ class QcFlagAdapter {
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);

this.qcFlagTypeAdapter = null;
this.qcFlagVerificationAdapter = null;
this.qcFlagEffectivePeriodAdapter = null;
this.userAdapter = null;
}

/**
* Converts the given database object to an summary object.
*
* @param {SequelizeQcFlag} databaseObject Object to convert.
* @returns {QcFlag} Converted summary object.
*/
toSummary(databaseObject) {
const { effectivePeriods = [], detectorId, flagType, id } = databaseObject;

return {
id,
dplDetectorId: detectorId,
flagType: flagType ? { name: flagType.name } : null,
effectivePeriods: effectivePeriods.map(this.qcFlagEffectivePeriodAdapter.toEntity),
};
}

/**
* Converts the given database object to an entity object.
*
Expand Down
23 changes: 23 additions & 0 deletions lib/database/adapters/QcFlagTypeAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class QcFlagTypeAdapter {
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
this.toSummary = this.toSummary.bind(this);
this.userAdapter = null;
}

Expand Down Expand Up @@ -71,6 +72,28 @@ class QcFlagTypeAdapter {
};
}

/**
* Converts the given database object to an summary object.
*
* @param {SequelizeQcFlagType} databaseObject Object to convert.
* @returns {QcFlagType} Converted summary object.
*/
toSummary(databaseObject) {
const { id, bad, color, method, name, createdBy, lastUpdatedBy, createdAt, updatedAt } = databaseObject;

return {
id,
bad,
color,
method,
name,
createdBy: createdBy ? this.userAdapter.toNameOnly(createdBy) : null,
createdAt: createdAt,
lastUpdatedBy: lastUpdatedBy ? this.userAdapter.toNameOnly(lastUpdatedBy) : null,
updatedAt,
};
}

/**
* Converts the given database object to an minified entity object.
*
Expand Down
Loading
Loading