@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
48 lines • 2.46 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.SequelizeChangeConfigurationRepository = void 0;
const __1 = require("..");
class SequelizeChangeConfigurationRepository extends __1.SequelizeRepository {
constructor(config, logger, sequelizeInstance) {
super(config, __1.ChangeConfiguration.MODEL_NAME, logger, sequelizeInstance);
}
createOrUpdateChangeConfiguration(tenantId, configuration) {
return __awaiter(this, void 0, void 0, function* () {
let changeConfiguration;
yield this.s.transaction((sequelizeTransaction) => __awaiter(this, void 0, void 0, function* () {
const [savedConfig, created] = yield this.readOrCreateByQuery(tenantId, {
where: {
tenantId: tenantId,
stationId: configuration.stationId,
key: configuration.key,
},
defaults: Object.assign({}, configuration),
transaction: sequelizeTransaction,
});
if (created) {
changeConfiguration = savedConfig;
}
else {
changeConfiguration = yield savedConfig.update(Object.assign({}, configuration), { transaction: sequelizeTransaction });
this.emit('updated', [changeConfiguration]);
}
}));
return changeConfiguration;
});
}
}
exports.SequelizeChangeConfigurationRepository = SequelizeChangeConfigurationRepository;
//# sourceMappingURL=ChangeConfiguration.js.map