mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
* refactor: flatten infra folders * fix: database migrations * fix: test related import * fix: github actions workflow * chore: rename schemas to typesense-schemas
24 lines
786 B
TypeScript
24 lines
786 B
TypeScript
import { DeviceInfoEntity } from '@app/infra/entities';
|
|
import { IDeviceInfoRepository } from './device-info.repository';
|
|
|
|
type UpsertKeys = Pick<DeviceInfoEntity, 'deviceId' | 'userId'>;
|
|
type UpsertEntity = UpsertKeys & Partial<DeviceInfoEntity>;
|
|
|
|
export class DeviceInfoCore {
|
|
constructor(private repository: IDeviceInfoRepository) {}
|
|
|
|
async upsert(entity: UpsertEntity) {
|
|
const exists = await this.repository.get(entity.userId, entity.deviceId);
|
|
if (!exists) {
|
|
if (!entity.isAutoBackup) {
|
|
entity.isAutoBackup = false;
|
|
}
|
|
return this.repository.save(entity);
|
|
}
|
|
|
|
exists.isAutoBackup = entity.isAutoBackup ?? exists.isAutoBackup;
|
|
exists.deviceType = entity.deviceType ?? exists.deviceType;
|
|
return this.repository.save(exists);
|
|
}
|
|
}
|