mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 00:38:11 +00:00
fix: type errors
This commit is contained in:
@@ -67,7 +67,11 @@ const byIdPath = (resource: RuleEngineResourceSlug, id: string): string => {
|
||||
}
|
||||
};
|
||||
|
||||
const defaultMeta = (dataLength: number, page = 1, pageSize = 10): RuleEngineListMeta => ({
|
||||
const defaultMeta = (
|
||||
dataLength: number,
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
): RuleEngineListMeta => ({
|
||||
total: dataLength,
|
||||
page,
|
||||
pageSize,
|
||||
@@ -79,7 +83,7 @@ const isPaginatedListResult = <T extends RuleEngineRecord>(
|
||||
): value is RuleEngineListResult<T> =>
|
||||
Boolean(value) &&
|
||||
typeof value === "object" &&
|
||||
"data" in value &&
|
||||
"data" in (value ?? {}) &&
|
||||
Array.isArray((value as RuleEngineListResult<T>).data);
|
||||
|
||||
const normalizeList = <T extends RuleEngineRecord>(
|
||||
@@ -104,7 +108,10 @@ const normalizeList = <T extends RuleEngineRecord>(
|
||||
}
|
||||
|
||||
if (Array.isArray(body)) {
|
||||
return { data: body as T[], meta: defaultMeta(body.length, page, pageSize) };
|
||||
return {
|
||||
data: body as T[],
|
||||
meta: defaultMeta(body.length, page, pageSize),
|
||||
};
|
||||
}
|
||||
|
||||
return { data: [], meta: defaultMeta(0, page, pageSize) };
|
||||
@@ -161,7 +168,10 @@ export const ruleEngineService = {
|
||||
return normalizeEntity<T>(response.data);
|
||||
},
|
||||
|
||||
remove: async (resource: RuleEngineResourceSlug, id: string): Promise<void> => {
|
||||
remove: async (
|
||||
resource: RuleEngineResourceSlug,
|
||||
id: string,
|
||||
): Promise<void> => {
|
||||
await client.delete(byIdPath(resource, id));
|
||||
},
|
||||
|
||||
@@ -181,24 +191,36 @@ export const ruleEngineService = {
|
||||
},
|
||||
|
||||
submitRate: async <T extends RuleEngineRecord>(id: string): Promise<T> => {
|
||||
const response = await client.post(URL_CONSTANTS.RULE_ENGINE.RATE_SUBMIT(id));
|
||||
const response = await client.post(
|
||||
URL_CONSTANTS.RULE_ENGINE.RATE_SUBMIT(id),
|
||||
);
|
||||
return normalizeEntity<T>(response.data);
|
||||
},
|
||||
|
||||
approveRate: async <T extends RuleEngineRecord>(id: string): Promise<T> => {
|
||||
const response = await client.post(URL_CONSTANTS.RULE_ENGINE.RATE_APPROVE(id));
|
||||
const response = await client.post(
|
||||
URL_CONSTANTS.RULE_ENGINE.RATE_APPROVE(id),
|
||||
);
|
||||
return normalizeEntity<T>(response.data);
|
||||
},
|
||||
|
||||
getApprovalChain: async (
|
||||
requiresDirectorApproval = true,
|
||||
): Promise<RuleEngineRecord[]> => {
|
||||
const response = await client.get(URL_CONSTANTS.RULE_ENGINE.APPROVAL_RULES_CHAIN, {
|
||||
params: { requiresDirectorApproval },
|
||||
});
|
||||
const response = await client.get(
|
||||
URL_CONSTANTS.RULE_ENGINE.APPROVAL_RULES_CHAIN,
|
||||
{
|
||||
params: { requiresDirectorApproval },
|
||||
},
|
||||
);
|
||||
const body = unwrap(response.data) as unknown;
|
||||
if (Array.isArray(body)) return body as RuleEngineRecord[];
|
||||
if (body && typeof body === "object" && "data" in body && Array.isArray((body as { data: unknown }).data)) {
|
||||
if (
|
||||
body &&
|
||||
typeof body === "object" &&
|
||||
"data" in body &&
|
||||
Array.isArray((body as { data: unknown }).data)
|
||||
) {
|
||||
return (body as { data: RuleEngineRecord[] }).data;
|
||||
}
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user