UNPKG

@citrineos/data

Version:

The OCPP data module which includes all persistence layer implementation.

46 lines 1.57 kB
import { OCPP2_0_1 } from '@citrineos/base'; import { SecurityEvent } from '../model/index.js'; import { SequelizeRepository } from './Base.js'; import { Op } from 'sequelize'; import { Sequelize } from 'sequelize-typescript'; import { Logger } from 'tslog'; export class SequelizeSecurityEventRepository extends SequelizeRepository { constructor(config, logger, sequelizeInstance) { super(config, SecurityEvent.MODEL_NAME, logger, sequelizeInstance); } async createByStationId(tenantId, value, stationId) { return await this.create(tenantId, SecurityEvent.build({ tenantId, stationId, ...value, })); } async readByStationIdAndTimestamps(tenantId, stationId, from, to) { const timestampQuery = this.generateTimestampQuery(from?.toISOString(), to?.toISOString()); return await this.readAllByQuery(tenantId, { where: { stationId, ...timestampQuery, }, }).then((row) => row); } async deleteByKey(tenantId, key) { return await super.deleteByKey(tenantId, key); } /** * Private Methods */ generateTimestampQuery(from, to) { if (!from && !to) { return {}; } if (!from && to) { return { timestamp: { [Op.lte]: to } }; } if (from && !to) { return { timestamp: { [Op.gte]: from } }; } return { timestamp: { [Op.between]: [from, to] } }; } } //# sourceMappingURL=SecurityEvent.js.map