UNPKG

@golemio/parkings

Version:
46 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParkingMachinesRepository = void 0; const _sch_1 = require("../../schema-definitions"); const ParkingMachinesModel_1 = require("../../schema-definitions/models/ParkingMachinesModel"); const models_1 = require("@golemio/core/dist/integration-engine/models"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator"); const sequelize_1 = require("@golemio/core/dist/shared/sequelize"); class ParkingMachinesRepository extends models_1.PostgresModel { constructor() { super("ParkingMachinesRepository", { outputSequelizeAttributes: ParkingMachinesModel_1.ParkingMachinesModel.attributeModel, pgSchema: _sch_1.Parkings.pgSchema, pgTableName: "parking_machines", savingType: "insertOrUpdate", }, new golemio_validator_1.JSONSchemaValidator("ParkingMachinesRepositoryValidator", ParkingMachinesModel_1.ParkingMachinesModel.jsonSchema)); } async bulkSaveMarkInactive(source, data, attributeList, updatedAt) { if (!this.sequelizeModel.sequelize) { throw new golemio_errors_1.FatalError("Sequelize is not initialized", this.constructor.name); } const transaction = await this.sequelizeModel.sequelize.transaction(); try { await this.bulkSave(data, attributeList, undefined, undefined, transaction); await this.updateInactive(source, updatedAt, transaction); await transaction.commit(); } catch (err) { await transaction.rollback(); throw new golemio_errors_1.GeneralError("Error while saving parking machines data", this.constructor.name, err); } } async updateInactive(source, updatedAt, transaction) { await this.sequelizeModel.update({ active: false }, { where: { source, updated_at: { [sequelize_1.Op.lt]: updatedAt }, active: true, }, transaction, }); } } exports.ParkingMachinesRepository = ParkingMachinesRepository; //# sourceMappingURL=ParkingMachinesRepository.js.map