mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
* refactor(server): device info * fix: export device service --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
24 lines
789 B
TypeScript
24 lines
789 B
TypeScript
import { DeviceInfoEntity } from '@app/infra/db/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);
|
|
}
|
|
}
|