@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
162 lines • 5.03 kB
JavaScript
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache-2.0
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);
};
var Tariff_1;
import { DEFAULT_TENANT_ID, OCPP2_0_1_Namespace } from '@citrineos/base';
import { BeforeCreate, BeforeUpdate, BelongsTo, Column, DataType, ForeignKey, HasMany, Model, Table, } from 'sequelize-typescript';
import { Connector } from '../Location/index.js';
import { Tenant } from '../Tenant.js';
let Tariff = class Tariff extends Model {
static { Tariff_1 = this; }
static MODEL_NAME = OCPP2_0_1_Namespace.Tariff;
get data() {
return {
id: this.id,
currency: this.currency,
pricePerKwh: this.pricePerKwh,
pricePerMin: this.pricePerMin,
pricePerSession: this.pricePerSession,
taxRate: this.taxRate,
authorizationAmount: this.authorizationAmount,
paymentFee: this.paymentFee,
};
}
static newInstance(data) {
return Tariff_1.build({ ...data });
}
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([
HasMany(() => Connector),
__metadata("design:type", Array)
], Tariff.prototype, "connectors", void 0);
__decorate([
Column({
type: DataType.CHAR(3),
allowNull: false,
}),
__metadata("design:type", String)
], Tariff.prototype, "currency", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
allowNull: false,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('pricePerKwh'));
},
}),
__metadata("design:type", Number)
], Tariff.prototype, "pricePerKwh", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('pricePerMin'));
},
}),
__metadata("design:type", Object)
], Tariff.prototype, "pricePerMin", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('pricePerSession'));
},
}),
__metadata("design:type", Object)
], Tariff.prototype, "pricePerSession", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('authorizationAmount'));
},
}),
__metadata("design:type", Object)
], Tariff.prototype, "authorizationAmount", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('paymentFee'));
},
}),
__metadata("design:type", Object)
], Tariff.prototype, "paymentFee", void 0);
__decorate([
Column({
type: DataType.DECIMAL,
validate: {
min: 0,
},
get() {
return parseFloat(this.getDataValue('taxRate'));
},
}),
__metadata("design:type", Object)
], Tariff.prototype, "taxRate", void 0);
__decorate([
Column(DataType.JSONB),
__metadata("design:type", Object)
], Tariff.prototype, "tariffAltText", void 0);
__decorate([
ForeignKey(() => Tenant),
Column({
type: DataType.INTEGER,
allowNull: false,
onUpdate: 'CASCADE',
onDelete: 'RESTRICT',
}),
__metadata("design:type", Number)
], Tariff.prototype, "tenantId", void 0);
__decorate([
BelongsTo(() => Tenant),
__metadata("design:type", Object)
], Tariff.prototype, "tenant", void 0);
__decorate([
BeforeUpdate,
BeforeCreate,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Tariff]),
__metadata("design:returntype", void 0)
], Tariff, "setDefaultTenant", null);
Tariff = Tariff_1 = __decorate([
Table,
__metadata("design:paramtypes", [Object])
], Tariff);
export { Tariff };
//# sourceMappingURL=Tariffs.js.map