refactor(pdfgeneration): Switch cards over to new service

This commit is contained in:
2024-12-17 17:09:55 +01:00
parent 04494d2a2a
commit e23098410c
2 changed files with 78 additions and 150 deletions

View File

@@ -0,0 +1,49 @@
class DocumentServer {
baseUrl: string;
apiKey: string;
constructor(baseUrl: string, apiKey: string){
this.baseUrl = baseUrl;
this.apiKey = apiKey;
}
async generateCards(cards: any[], locale: string, filename: string) {
const generateCards = new Array<any>();
for (let i = 0; i < cards.length; i++) {
const card = {
id: cards[i].id,
enabled: cards[i].enabled,
code: cards[i].code,
runner: {
id: cards[i].runner.id,
first_name: cards[i].runner.firstname,
middle_name: cards[i].runner.middlename,
last_name: cards[i].runner.lastname,
group: {
id: cards[i].runner.group.id,
name: cards[i].runner.group.name,
}
}
}
generateCards.push(card)
}
const response = await fetch(`${this.baseUrl}/v1/pdfs/cards?key=${this.apiKey}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
locale,
cards: generateCards,
}),
});
const blob = await response.blob();
return blob;
}
}
export default DocumentServer;