refactor(pdfgeneration): Switch cards over to new service
This commit is contained in:
49
src/components/pdf_generation/DocumentServer.ts
Normal file
49
src/components/pdf_generation/DocumentServer.ts
Normal 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;
|
||||
Reference in New Issue
Block a user