@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
63 lines • 2.91 kB
JavaScript
;
// Copyright (c) 2023 S44, LLC
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SequelizeSecurityEventRepository = void 0;
const SecurityEvent_1 = require("../model/SecurityEvent");
const Base_1 = require("./Base");
const sequelize_1 = require("sequelize");
class SequelizeSecurityEventRepository extends Base_1.SequelizeRepository {
constructor(config, logger, sequelizeInstance) {
super(config, SecurityEvent_1.SecurityEvent.MODEL_NAME, logger, sequelizeInstance);
}
createByStationId(tenantId, value, stationId) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.create(tenantId, SecurityEvent_1.SecurityEvent.build(Object.assign({ tenantId,
stationId }, value)));
});
}
readByStationIdAndTimestamps(tenantId, stationId, from, to) {
return __awaiter(this, void 0, void 0, function* () {
const timestampQuery = this.generateTimestampQuery(from === null || from === void 0 ? void 0 : from.toISOString(), to === null || to === void 0 ? void 0 : to.toISOString());
return yield this.readAllByQuery(tenantId, {
where: Object.assign({ stationId }, timestampQuery),
}).then((row) => row);
});
}
deleteByKey(tenantId, key) {
const _super = Object.create(null, {
deleteByKey: { get: () => super.deleteByKey }
});
return __awaiter(this, void 0, void 0, function* () {
return yield _super.deleteByKey.call(this, tenantId, key);
});
}
/**
* Private Methods
*/
generateTimestampQuery(from, to) {
if (!from && !to) {
return {};
}
if (!from && to) {
return { timestamp: { [sequelize_1.Op.lte]: to } };
}
if (from && !to) {
return { timestamp: { [sequelize_1.Op.gte]: from } };
}
return { timestamp: { [sequelize_1.Op.between]: [from, to] } };
}
}
exports.SequelizeSecurityEventRepository = SequelizeSecurityEventRepository;
//# sourceMappingURL=SecurityEvent.js.map