poller and release on end to frontend
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { getLinkController } from "@pkg/logic/domains/link/controller";
|
||||
import { createLinkSchema, updateLinkSchema } from "@pkg/logic/domains/link/data";
|
||||
import { getDeviceController } from "@pkg/logic/domains/device/controller";
|
||||
import { getFlowExecCtxForRemoteFuncs, unauthorized } from "$lib/core/server.utils";
|
||||
import { command, getRequestEvent, query } from "$app/server";
|
||||
import * as v from "valibot";
|
||||
|
||||
const lc = getLinkController();
|
||||
const dc = getDeviceController();
|
||||
|
||||
export const listLinksSQ = query(async () => {
|
||||
const event = getRequestEvent();
|
||||
@@ -66,10 +68,25 @@ export const revokeLinkSC = command(
|
||||
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
|
||||
if (!fctx.userId) return unauthorized(fctx);
|
||||
|
||||
const res = await lc.revoke(fctx, payload.id);
|
||||
return res.isOk()
|
||||
? { data: res.value, error: null }
|
||||
: { data: null, error: res.error };
|
||||
const linkResult = await lc.getById(fctx, payload.id);
|
||||
if (linkResult.isErr()) {
|
||||
return { data: null, error: linkResult.error };
|
||||
}
|
||||
|
||||
const revokeResult = await lc.revoke(fctx, payload.id);
|
||||
if (revokeResult.isErr()) {
|
||||
return { data: null, error: revokeResult.error };
|
||||
}
|
||||
|
||||
const linkedDeviceId = linkResult.value.linkedDeviceId;
|
||||
if (linkedDeviceId !== null) {
|
||||
const releaseResult = await dc.release(fctx, linkedDeviceId);
|
||||
if (releaseResult.isErr()) {
|
||||
return { data: null, error: releaseResult.error };
|
||||
}
|
||||
}
|
||||
|
||||
return { data: revokeResult.value, error: null };
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user