71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
|
import { saveAs } from "file-saver";
|
||
|
import { _4X4Cert } from "./certs/4X4";
|
||
|
import { CertData } from "./certs/CertData";
|
||
|
import { matpelCert } from "./certs/MATPEL";
|
||
|
import { Matpel } from "./certs/utils";
|
||
|
|
||
|
import { manejoDefensivoCert } from "./certs/MANEJO_DEFENSIVO";
|
||
|
import { mecanicaBasicaCert } from "./certs/MECANICA_BASICA";
|
||
|
import { segOpMaqPesCert } from "./certs/SEG_OP_MAQ_PES";
|
||
|
import { supervisorEscolta } from "./certs/SUPERVISOR_ESCOLTA";
|
||
|
import { ipercCert } from "./certs/IPERC";
|
||
|
|
||
|
declare global {
|
||
|
interface Window {
|
||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||
|
docx: any,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function download(document: Document, filename: string = "filename.docx") {
|
||
|
const blob = await window.docx.Packer.toBlob(document);
|
||
|
saveAs(blob, filename);
|
||
|
}
|
||
|
|
||
|
const certGeneratorGenerator = <T>(generatorFn: (options: CertData<T>) => Promise<Document>) => (options: CertData<T>, filename: string) => {
|
||
|
generatorFn(options)
|
||
|
.then((doc) => {
|
||
|
download(doc, filename);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export const certGenerator = Object.freeze({
|
||
|
matpel1: (options: CertData<null>, filename: string) => {
|
||
|
const options_f: CertData<Matpel> = {
|
||
|
...options,
|
||
|
matpel: Matpel._1,
|
||
|
};
|
||
|
matpelCert(options_f)
|
||
|
.then((doc) => {
|
||
|
download(doc, filename);
|
||
|
});
|
||
|
},
|
||
|
matpel2: (options: CertData<null>, filename: string) => {
|
||
|
const options_f: CertData<Matpel> = {
|
||
|
...options,
|
||
|
matpel: Matpel._2,
|
||
|
};
|
||
|
matpelCert(options_f)
|
||
|
.then((doc) => {
|
||
|
download(doc, filename);
|
||
|
});
|
||
|
},
|
||
|
matpel3: (options: CertData<null>, filename: string) => {
|
||
|
const options_f: CertData<Matpel> = {
|
||
|
...options,
|
||
|
matpel: Matpel._3,
|
||
|
};
|
||
|
matpelCert(options_f)
|
||
|
.then((doc) => {
|
||
|
download(doc, filename);
|
||
|
});
|
||
|
},
|
||
|
manejoDefensivo: certGeneratorGenerator(manejoDefensivoCert),
|
||
|
mecanicaBasica: certGeneratorGenerator(mecanicaBasicaCert),
|
||
|
"4x4": certGeneratorGenerator(_4X4Cert),
|
||
|
segOpMaqPes: certGeneratorGenerator(segOpMaqPesCert),
|
||
|
supervisorEscolta: certGeneratorGenerator(supervisorEscolta),
|
||
|
iperc: certGeneratorGenerator(ipercCert),
|
||
|
});
|
||
|
|