import { repositories } from '../database/dataSource.js';
import { deviceIdFromUrl } from './urlFromId.js';
export function toUuid(idurl) {
    if ('url' in idurl) {
        return deviceIdFromUrl(idurl.url);
    }
    else {
        return idurl.uuid;
    }
}
export async function getDevice(id) {
    const device = await repositories.device.findOneOrFail({
        where: { uuid: toUuid(id) },
    });
    return device;
}
export async function updateDevice(id, device) {
    const deviceModel = await repositories.device.findOneOrFail({
        where: { uuid: toUuid(id) },
    });
    await repositories.device.write(deviceModel, { type: deviceModel.type, ...device });
    await repositories.device.save(deviceModel);
}
//# sourceMappingURL=device.js.map