@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
32 lines • 1.44 kB
JavaScript
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache-2.0
import { Sequelize } from 'sequelize-typescript';
import { SequelizeRepository, Subscription } from '../index.js';
import { Logger } from 'tslog';
export class SequelizeSubscriptionRepository extends SequelizeRepository {
constructor(config, logger, sequelizeInstance) {
super(config, Subscription.MODEL_NAME, logger, sequelizeInstance);
}
/**
* Creates a new {@link Subscription} in the database.
* Input is assumed to not have an id, and id will be removed if present.
* Object is rebuilt to ensure access to essential {@link Model} function {@link Model.save()} (Model is extended by Subscription).
*
* @param value {@link Subscription} object which may have been deserialized from JSON
* @returns Saved {@link Subscription} if successful, undefined otherwise
*/
create(tenantId, value) {
const { ...rawSubscription } = value;
rawSubscription.tenantId = tenantId;
rawSubscription.id = null;
return super.create(tenantId, Subscription.build({ ...rawSubscription }));
}
readAllByStationId(tenantId, stationId) {
return super.readAllByQuery(tenantId, { where: { stationId: stationId } });
}
deleteByKey(tenantId, key) {
return super.deleteByKey(tenantId, key);
}
}
//# sourceMappingURL=Subscription.js.map