Build fixes
This commit is contained in:
parent
70d97c1342
commit
04ecef98da
9 changed files with 52 additions and 45 deletions
|
|
@ -4,12 +4,12 @@ import fetch from "node-fetch";
|
|||
import { URLSearchParams } from "url";
|
||||
import { withDb, AppDatabase } from "../db";
|
||||
import { loadConfig } from "@digiresilience/metamigo-config";
|
||||
import { tagMap } from "../lib/tag-map"
|
||||
import { tagMap } from "../lib/tag-map";
|
||||
|
||||
type FormattedZammadTicket = {
|
||||
data: Record<string, unknown>,
|
||||
predictions: Record<string, unknown>[]
|
||||
}
|
||||
predictions: Record<string, unknown>[];
|
||||
};
|
||||
|
||||
const getZammadTickets = async (page: number, minUpdatedTimestamp: Date): Promise<[boolean, FormattedZammadTicket[]]> => {
|
||||
const { leafcutter: { zammadApiUrl, zammadApiKey, contributorName, contributorId } } = await loadConfig();
|
||||
|
|
@ -27,8 +27,8 @@ const getZammadTickets = async (page: number, minUpdatedTimestamp: Date): Promis
|
|||
const rawTickets = await fetch(`${zammadApiUrl}/tickets/search?${ticketsQuery}`,
|
||||
{ headers }
|
||||
);
|
||||
const tickets = await rawTickets.json();
|
||||
console.log({ tickets })
|
||||
const tickets: any = await rawTickets.json();
|
||||
console.log({ tickets });
|
||||
if (!tickets || tickets.length === 0) {
|
||||
return [shouldContinue, docs];
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ const getZammadTickets = async (page: number, minUpdatedTimestamp: Date): Promis
|
|||
const rawArticles = await fetch(`${zammadApiUrl}/ticket_articles/by_ticket/${source_id}`,
|
||||
{ headers }
|
||||
);
|
||||
const articles = await rawArticles.json();
|
||||
const articles: any = await rawArticles.json();
|
||||
let articleText = "";
|
||||
|
||||
for (const article of articles) {
|
||||
|
|
@ -70,7 +70,7 @@ const getZammadTickets = async (page: number, minUpdatedTimestamp: Date): Promis
|
|||
});
|
||||
|
||||
const rawTags = await fetch(`${zammadApiUrl}/tags?${tagsQuery}`, { headers });
|
||||
const { tags } = await rawTags.json();
|
||||
const { tags }: any = await rawTags.json();
|
||||
const transformedTags = [];
|
||||
for (const tag of tags) {
|
||||
const outputs = tagMap[tag];
|
||||
|
|
@ -106,14 +106,14 @@ const getZammadTickets = async (page: number, minUpdatedTimestamp: Date): Promis
|
|||
doc.predictions.push({
|
||||
model_version: `${contributorName}TranslatorV1`,
|
||||
result,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
docs.push(doc);
|
||||
}
|
||||
|
||||
return [shouldContinue, docs];
|
||||
}
|
||||
};
|
||||
|
||||
const fetchFromZammad = async (minUpdatedTimestamp: Date): Promise<FormattedZammadTicket[]> => {
|
||||
const pages = [...Array.from({ length: 10000 }).keys()];
|
||||
|
|
@ -153,7 +153,7 @@ const sendToLabelStudio = async (tickets: FormattedZammadTicket[]) => {
|
|||
|
||||
console.log(JSON.stringify(importResult, undefined, 2));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const importLabelStudioTask = async (): Promise<void> => {
|
||||
withDb(async (db: AppDatabase) => {
|
||||
|
|
@ -167,8 +167,8 @@ const importLabelStudioTask = async (): Promise<void> => {
|
|||
await sendToLabelStudio(tickets);
|
||||
const lastTicket = tickets.pop();
|
||||
const newLastTimestamp = lastTicket.data.source_closed_at;
|
||||
console.log({ newLastTimestamp })
|
||||
await db.settings.upsert(settingName, { minUpdatedTimestamp: newLastTimestamp })
|
||||
console.log({ newLastTimestamp });
|
||||
await db.settings.upsert(settingName, { minUpdatedTimestamp: newLastTimestamp });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue