mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add api support
This commit is contained in:
27
dashboard/server/api/v1/events.post.ts
Normal file
27
dashboard/server/api/v1/events.post.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
import { checkApiKey, checkAuthorization, eventsListApi } from '~/server/services/ApiService';
|
||||
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const { rows, from, to, limit } = await readBody(event);
|
||||
|
||||
const token = checkAuthorization(event);
|
||||
if (!token) return;
|
||||
|
||||
const apiKeyResult = await checkApiKey(token);
|
||||
if (!apiKeyResult.ok) return setResponseStatus(event, 401, 'ApiKey not valid');
|
||||
|
||||
if (!rows) return setResponseStatus(event, 400, 'rows is required');
|
||||
if (!Array.isArray(rows)) return setResponseStatus(event, 400, 'rows must be an array');
|
||||
if (rows.length == 0) return setResponseStatus(event, 400, 'rows cannot be empty');
|
||||
|
||||
if (Array.isArray(from)) return setResponseStatus(event, 400, 'Only one "from" is allowed');
|
||||
if (Array.isArray(to)) return setResponseStatus(event, 400, 'Only one "to" is allowed');
|
||||
|
||||
const result = await eventsListApi(apiKeyResult.data.apiKey, apiKeyResult.data.project_id.toString(), rows, limit as string, from as string, to as string);
|
||||
|
||||
if (result.ok) return result;
|
||||
return setResponseStatus(event, result.code, result.error);
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user