making strides in the device and link domain setup

This commit is contained in:
user
2026-03-27 23:58:06 +02:00
parent 8c45efc92e
commit c7c303a934
17 changed files with 1202 additions and 198 deletions

View File

@@ -0,0 +1,88 @@
import { getDeviceController } from "@pkg/logic/domains/device/controller";
import { createDeviceSchema, updateDeviceSchema } from "@pkg/logic/domains/device/data";
import { getFlowExecCtxForRemoteFuncs, unauthorized } from "$lib/core/server.utils";
import { command, getRequestEvent, query } from "$app/server";
import * as v from "valibot";
const dc = getDeviceController();
export const listDevicesSQ = query(async () => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.list(fctx);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
});
export const getDeviceByIdSQ = query(
v.object({ id: v.number() }),
async (input) => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.getById(fctx, input.id);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
},
);
export const createDeviceSC = command(createDeviceSchema, async (payload) => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.create(fctx, payload);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
});
export const updateDeviceSC = command(
v.object({ id: v.number(), data: updateDeviceSchema }),
async (payload) => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.update(fctx, payload.id, payload.data);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
},
);
export const deleteDeviceSC = command(
v.object({ id: v.number() }),
async (payload) => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.delete(fctx, payload.id);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
},
);
export const setDeviceStatusSC = command(
v.object({
id: v.number(),
status: v.picklist(["online", "offline", "busy", "error"]),
}),
async (payload) => {
const event = getRequestEvent();
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
if (!fctx.userId) return unauthorized(fctx);
const res = await dc.setStatus(fctx, payload.id, payload.status as any);
return res.isOk()
? { data: res.value, error: null }
: { data: null, error: res.error };
},
);