save method
- ComponentTemplate component
override
Save/update component
Implementation
@override
Future<Either<String, void>> save(ComponentTemplate component) async {
try {
await isar.writeTxn(() async {
final existing = await isar.componentModels
.filter()
.componentIdEqualTo(component.id)
.findFirst();
final model = ComponentModelMapper.fromDomain(component);
if (existing != null) {
model
..id = existing.id
..createdAt = existing.createdAt
..updatedAt = DateTime.now();
}
await isar.componentModels.put(model);
});
return const Right(null);
} catch (e) {
return Left('Failed to save component: $e');
}
}