import type { ServiceLayerClient } from '../service-layer-client.ts'; import { userTableEntity } from '../lib/service-layer-paths.ts'; const ENTITY = userTableEntity('OEVN'); export interface OevnRow { code: string; sourceDb: string; status: string; objectType: string; transType: string; fieldNames: string; fieldValue: string; } function toRow(raw: Record): OevnRow { return { code: raw.Code as string, sourceDb: raw.U_SourceDB as string, status: raw.U_Status as string, objectType: raw.U_ObjectType as string, transType: raw.U_TransType as string, fieldNames: raw.U_FieldNames as string, fieldValue: raw.U_FieldValue as string, }; } export async function listNewEvents(client: ServiceLayerClient): Promise { const rows = await client.getAll(`/${ENTITY}?$filter=${encodeURIComponent("U_Status eq 'N'")}`); return rows.map(toRow); } export async function getEvent(client: ServiceLayerClient, code: string): Promise { const res = await client.get(`/${ENTITY}('${code}')`); return res.status === 200 ? toRow(res.data) : null; } export async function deleteEvent(client: ServiceLayerClient, code: string): Promise { await client.delete(`/${ENTITY}('${code}')`); } export async function setEventStatus(client: ServiceLayerClient, code: string, status: string): Promise { await client.patch(`/${ENTITY}('${code}')`, { U_Status: status }); }