@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
211 lines • 7.37 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { DEFAULT_TENANT_ID, Namespace } from '@citrineos/base';
import { BeforeCreate, BeforeUpdate, BelongsTo, Column, DataType, ForeignKey, HasMany, HasOne, Model, Table, } from 'sequelize-typescript';
import { MeterValue } from './MeterValue.js';
import { TransactionEvent } from './TransactionEvent.js';
import { ChargingStation, } from '../Location/ChargingStation.js';
import { Connector } from '../Location/Connector.js';
import { Evse } from '../Location/Evse.js';
import { Location } from '../Location/Location.js';
import { StartTransaction, StopTransaction } from './index.js';
import { Authorization } from '../Authorization/index.js';
import { Tariff, Tenant } from '../index.js';
let Transaction = class Transaction extends Model {
static MODEL_NAME = Namespace.TransactionType;
static TRANSACTION_EVENTS_ALIAS = 'transactionEvents';
static TRANSACTION_EVENTS_FILTER_ALIAS = 'transactionEventsFilter';
locationId;
location;
stationId;
station;
authorizationId;
authorization;
tariffId;
tariff;
static setDefaultTenant(instance) {
if (instance.tenantId == null) {
instance.tenantId = DEFAULT_TENANT_ID;
}
}
constructor(...args) {
super(...args);
if (this.tenantId == null) {
this.tenantId = DEFAULT_TENANT_ID;
}
}
};
__decorate([
Column(DataType.INTEGER),
ForeignKey(() => Location),
__metadata("design:type", Number)
], Transaction.prototype, "locationId", void 0);
__decorate([
BelongsTo(() => Location),
__metadata("design:type", Function)
], Transaction.prototype, "location", void 0);
__decorate([
Column({
type: DataType.STRING,
unique: 'stationId_transactionId',
}),
ForeignKey(() => ChargingStation),
__metadata("design:type", String)
], Transaction.prototype, "stationId", void 0);
__decorate([
BelongsTo(() => ChargingStation),
__metadata("design:type", Function)
], Transaction.prototype, "station", void 0);
__decorate([
ForeignKey(() => Evse),
Column(DataType.INTEGER),
__metadata("design:type", Number)
], Transaction.prototype, "evseId", void 0);
__decorate([
BelongsTo(() => Evse),
__metadata("design:type", Object)
], Transaction.prototype, "evse", void 0);
__decorate([
Column(DataType.INTEGER),
ForeignKey(() => Connector),
__metadata("design:type", Number)
], Transaction.prototype, "connectorId", void 0);
__decorate([
BelongsTo(() => Connector),
__metadata("design:type", Object)
], Transaction.prototype, "connector", void 0);
__decorate([
Column(DataType.INTEGER),
ForeignKey(() => Authorization),
__metadata("design:type", Number)
], Transaction.prototype, "authorizationId", void 0);
__decorate([
BelongsTo(() => Authorization),
__metadata("design:type", Authorization)
], Transaction.prototype, "authorization", void 0);
__decorate([
Column(DataType.INTEGER),
ForeignKey(() => Tariff),
__metadata("design:type", Number)
], Transaction.prototype, "tariffId", void 0);
__decorate([
BelongsTo(() => Tariff),
__metadata("design:type", Tariff)
], Transaction.prototype, "tariff", void 0);
__decorate([
Column({
type: DataType.STRING,
unique: 'stationId_transactionId',
}),
__metadata("design:type", String)
], Transaction.prototype, "transactionId", void 0);
__decorate([
Column(DataType.BOOLEAN),
__metadata("design:type", Boolean)
], Transaction.prototype, "isActive", void 0);
__decorate([
HasMany(() => TransactionEvent, {
as: Transaction.TRANSACTION_EVENTS_ALIAS,
foreignKey: 'transactionDatabaseId',
}),
__metadata("design:type", Array)
], Transaction.prototype, "transactionEvents", void 0);
__decorate([
HasMany(() => TransactionEvent, {
as: Transaction.TRANSACTION_EVENTS_FILTER_ALIAS,
foreignKey: 'transactionDatabaseId',
}),
__metadata("design:type", Array)
], Transaction.prototype, "transactionEventsFilter", void 0);
__decorate([
HasMany(() => MeterValue),
__metadata("design:type", Array)
], Transaction.prototype, "meterValues", void 0);
__decorate([
HasOne(() => StartTransaction),
__metadata("design:type", Object)
], Transaction.prototype, "startTransaction", void 0);
__decorate([
HasOne(() => StopTransaction),
__metadata("design:type", Object)
], Transaction.prototype, "stopTransaction", void 0);
__decorate([
Column(DataType.STRING),
__metadata("design:type", Object)
], Transaction.prototype, "chargingState", void 0);
__decorate([
Column(DataType.BIGINT),
__metadata("design:type", Object)
], Transaction.prototype, "timeSpentCharging", void 0);
__decorate([
Column(DataType.DECIMAL),
__metadata("design:type", Object)
], Transaction.prototype, "totalKwh", void 0);
__decorate([
Column(DataType.STRING),
__metadata("design:type", Object)
], Transaction.prototype, "stoppedReason", void 0);
__decorate([
Column(DataType.INTEGER),
__metadata("design:type", Object)
], Transaction.prototype, "remoteStartId", void 0);
__decorate([
Column(DataType.DECIMAL),
__metadata("design:type", Number)
], Transaction.prototype, "totalCost", void 0);
__decorate([
Column({
type: DataType.DATE,
get() {
return this.getDataValue('startTime')?.toISOString();
},
}),
__metadata("design:type", String)
], Transaction.prototype, "startTime", void 0);
__decorate([
Column({
type: DataType.DATE,
get() {
return this.getDataValue('endTime')?.toISOString();
},
}),
__metadata("design:type", String)
], Transaction.prototype, "endTime", void 0);
__decorate([
Column(DataType.JSONB),
__metadata("design:type", Object)
], Transaction.prototype, "customData", void 0);
__decorate([
ForeignKey(() => Tenant),
Column({
type: DataType.INTEGER,
allowNull: false,
onUpdate: 'CASCADE',
onDelete: 'RESTRICT',
}),
__metadata("design:type", Number)
], Transaction.prototype, "tenantId", void 0);
__decorate([
BelongsTo(() => Tenant),
__metadata("design:type", Object)
], Transaction.prototype, "tenant", void 0);
__decorate([
BeforeUpdate,
BeforeCreate,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Transaction]),
__metadata("design:returntype", void 0)
], Transaction, "setDefaultTenant", null);
Transaction = __decorate([
Table,
__metadata("design:paramtypes", [Object])
], Transaction);
export { Transaction };
//# sourceMappingURL=Transaction.js.map