52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import { ndmClient, userClient, type NdmCameraPageQuery, type NdmCameraResultVO, type NdmCameraUpdateVO, type PageParams, type PageResult, type SnapResult } from '@/apis';
|
|
|
|
export const pageCameraApi = async (pageQuery: PageParams<NdmCameraPageQuery>, options?: { stationCode?: string; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmCamera/page`;
|
|
const resp = await client.post<PageResult<NdmCameraResultVO>>(endpoint, pageQuery, { signal });
|
|
const [err, data] = resp;
|
|
if (err || !data) {
|
|
throw err;
|
|
}
|
|
return data;
|
|
};
|
|
|
|
export const detailCameraApi = async (id: string, optioins?: { stationCode?: string; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = optioins ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmCamera/detail`;
|
|
const resp = await client.get<NdmCameraResultVO>(endpoint, { params: { id }, signal });
|
|
const [err, data] = resp;
|
|
if (err || !data) {
|
|
throw err;
|
|
}
|
|
return data;
|
|
};
|
|
|
|
export const updateCameraApi = async (updateVO: NdmCameraUpdateVO, options?: { stationCode?: string; signal?: AbortSignal }) => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const client = stationCode ? ndmClient : userClient;
|
|
const prefix = stationCode ? `/${stationCode}` : '';
|
|
const endpoint = `${prefix}/api/ndm/ndmCamera`;
|
|
const resp = await client.put<NdmCameraResultVO>(endpoint, updateVO, { signal });
|
|
const [err, data] = resp;
|
|
if (err || !data) {
|
|
throw err;
|
|
}
|
|
return data;
|
|
};
|
|
|
|
export const getCameraSnapApi = async (deviceId: string, options?: { signal?: AbortSignal }) => {
|
|
const { signal } = options ?? {};
|
|
const endpoint = '/api/ndm/ndmCamera/getSnapByDeviceId';
|
|
const resp = await ndmClient.get<SnapResult>(endpoint, { params: { deviceId }, signal });
|
|
const [err, data] = resp;
|
|
if (err || !data) {
|
|
throw err;
|
|
}
|
|
return data;
|
|
};
|