fase(16): integrations module
This commit is contained in:
72
dist/modules/integrations/infrastructure/repositories/KyselyIntegrationRepository.js
vendored
Normal file
72
dist/modules/integrations/infrastructure/repositories/KyselyIntegrationRepository.js
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KyselyIntegrationRepository = void 0;
|
||||
const Integration_1 = require("../../domain/entities/Integration");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
const IntegrationType_1 = require("../../domain/value-objects/IntegrationType");
|
||||
class KyselyIntegrationRepository {
|
||||
constructor(db) {
|
||||
this.db = db;
|
||||
}
|
||||
async save(integration) {
|
||||
const row = {
|
||||
id: integration.id.toString(),
|
||||
name: integration.name,
|
||||
type: integration.type.value,
|
||||
enabled: integration.enabled ? 1 : 0,
|
||||
config_json: JSON.stringify(integration.config),
|
||||
created_at: integration.createdAt.getTime(),
|
||||
};
|
||||
await this.db.insertInto('integrations').values(row).execute();
|
||||
}
|
||||
async findById(id) {
|
||||
const row = await this.db
|
||||
.selectFrom('integrations')
|
||||
.selectAll()
|
||||
.where('id', '=', id)
|
||||
.executeTakeFirst();
|
||||
return row ? this.toDomain(row) : undefined;
|
||||
}
|
||||
async findAll() {
|
||||
const rows = await this.db
|
||||
.selectFrom('integrations')
|
||||
.selectAll()
|
||||
.orderBy('created_at', 'desc')
|
||||
.execute();
|
||||
return rows.map(r => this.toDomain(r));
|
||||
}
|
||||
async findEnabled() {
|
||||
const rows = await this.db
|
||||
.selectFrom('integrations')
|
||||
.selectAll()
|
||||
.where('enabled', '=', 1)
|
||||
.execute();
|
||||
return rows.map(r => this.toDomain(r));
|
||||
}
|
||||
async update(integration) {
|
||||
await this.db
|
||||
.updateTable('integrations')
|
||||
.set({
|
||||
name: integration.name,
|
||||
enabled: integration.enabled ? 1 : 0,
|
||||
config_json: JSON.stringify(integration.config),
|
||||
})
|
||||
.where('id', '=', integration.id.toString())
|
||||
.execute();
|
||||
}
|
||||
async delete(id) {
|
||||
await this.db.deleteFrom('integrations').where('id', '=', id).execute();
|
||||
}
|
||||
toDomain(row) {
|
||||
const config = JSON.parse(row.config_json);
|
||||
const props = {
|
||||
name: row.name,
|
||||
type: IntegrationType_1.IntegrationType.fromString(row.type),
|
||||
enabled: row.enabled === 1,
|
||||
config,
|
||||
createdAt: new Date(row.created_at),
|
||||
};
|
||||
return Integration_1.Integration.reconstitute(props, UniqueId_1.UniqueId.from(row.id));
|
||||
}
|
||||
}
|
||||
exports.KyselyIntegrationRepository = KyselyIntegrationRepository;
|
||||
Reference in New Issue
Block a user