"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KyselyTOTPRepository = void 0; const TOTPSecret_1 = require("../../domain/entities/TOTPSecret"); const UniqueId_1 = require("../../../../shared/domain/UniqueId"); class KyselyTOTPRepository { constructor(db) { this.db = db; } async save(secret) { await this.db .insertInto('totp_secrets') .values({ id: secret.id.toString(), user_id: secret.userId, secret: secret.secret, verified: secret.verified ? 1 : 0, created_at: secret.createdAt.getTime(), }) .onConflict((oc) => oc.column('user_id').doUpdateSet({ secret: secret.secret, verified: secret.verified ? 1 : 0, })) .execute(); } async findByUserId(userId) { const row = await this.db .selectFrom('totp_secrets') .selectAll() .where('user_id', '=', userId) .executeTakeFirst(); if (!row) return null; return TOTPSecret_1.TOTPSecret.reconstitute({ userId: row.user_id, secret: row.secret, verified: row.verified === 1, createdAt: new Date(row.created_at), }, UniqueId_1.UniqueId.from(row.id)); } async delete(userId) { await this.db.deleteFrom('totp_secrets').where('user_id', '=', userId).execute(); } } exports.KyselyTOTPRepository = KyselyTOTPRepository;