createSlot method
- Slot slot
Creates a new slot.
Implementation
Future<void> createSlot(Slot slot) async {
if (!state.hasData) {
log('Cannot create new slot: No data');
return;
}
log('Creating slot with id ${slot.id}');
try {
final createdSlot = await _datasource.createSlot(
token: _auth.state.requireData.pick(Webservice.lb_planner_api),
slot: slot,
);
log('Created slot with id ${slot.id}');
await captureEvent(
'slot_created',
properties: {
'weekday': slot.weekday,
'size': slot.size,
'start': slot.startUnit,
'end': slot.endUnit,
},
);
for (final supervisorId in slot.supervisors) {
await addSlotSupervisor(slotId: createdSlot.id, supervisorId: supervisorId);
}
final mappings = slot.mappings.map((m) => m.copyWith(slotId: createdSlot.id)).toList();
for (final mapping in mappings) {
await addMapping(
slotId: createdSlot.id,
mapping: mapping,
);
}
await build(this);
} catch (e, s) {
log('Failed to create slot', e, s);
}
}