Add link session preparation flow
- wire front link resolve/prepare routes - add orchestrator session command handling - update admin dashboards and device/link logic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { errAsync, ResultAsync } from "neverthrow";
|
||||
import { db } from "@pkg/db";
|
||||
import { type Err } from "@pkg/result";
|
||||
import { ERROR_CODES, type Err } from "@pkg/result";
|
||||
import { FlowExecCtx } from "@core/flow.execution.context";
|
||||
import { CreateDevice, Device, DeviceStatus, UpdateDevice } from "./data";
|
||||
import { DeviceRepository } from "./repository";
|
||||
@@ -46,14 +46,20 @@ export class DeviceController {
|
||||
* Only succeeds if the device is currently online.
|
||||
*/
|
||||
allocate(fctx: FlowExecCtx, id: number): ResultAsync<Device, Err> {
|
||||
return this.repo.getById(fctx, id).andThen((dev) => {
|
||||
if (dev.status !== DeviceStatus.ONLINE || dev.inUse) {
|
||||
return errAsync(deviceErrors.deviceNotAvailable(fctx, id));
|
||||
return this.repo.allocateIfAvailable(fctx, id).orElse((error) => {
|
||||
if (error.code === ERROR_CODES.NOT_ALLOWED) {
|
||||
return this.repo
|
||||
.getById(fctx, id)
|
||||
.andThen((dev) => {
|
||||
if (dev.status !== DeviceStatus.ONLINE || dev.inUse) {
|
||||
return errAsync(deviceErrors.deviceNotAvailable(fctx, id));
|
||||
}
|
||||
return errAsync(error);
|
||||
})
|
||||
.orElse(() => errAsync(error));
|
||||
}
|
||||
return this.repo.update(fctx, id, {
|
||||
status: DeviceStatus.BUSY,
|
||||
inUse: true,
|
||||
});
|
||||
|
||||
return errAsync(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user