import { ISystemMetadataRepository } from '@app/domain/repositories/system-metadata.repository'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { SystemMetadata, SystemMetadataEntity } from '../entities'; export class SystemMetadataRepository implements ISystemMetadataRepository { constructor( @InjectRepository(SystemMetadataEntity) private repository: Repository, ) {} async get(key: T): Promise { const metadata = await this.repository.findOne({ where: { key } }); if (!metadata) { return null; } return metadata.value as SystemMetadata[T]; } async set(key: T, value: SystemMetadata[T]): Promise { await this.repository.upsert({ key, value }, { conflictPaths: { key: true } }); } }