2023-08-29 16:14:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-08-29 16:44:07 +00:00
|
|
|
const certGeneratorGenerator = <T>(generatorFn: (options: CertData<T>) => Promise<Document>) => (filename: string, options: CertData<T>) => {
|
2023-08-29 16:14:33 +00:00
|
|
|
generatorFn(options)
|
|
|
|
.then((doc) => {
|
|
|
|
download(doc, filename);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-08-29 16:44:07 +00:00
|
|
|
type CertGenObj = {
|
|
|
|
[key: string]: (filename: string, options: CertData<null>) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const certGenerator: CertGenObj = Object.freeze({
|
|
|
|
matpel1: (filename: string, options: CertData<null>) => {
|
2023-08-29 16:14:33 +00:00
|
|
|
const options_f: CertData<Matpel> = {
|
|
|
|
...options,
|
|
|
|
matpel: Matpel._1,
|
|
|
|
};
|
|
|
|
matpelCert(options_f)
|
|
|
|
.then((doc) => {
|
|
|
|
download(doc, filename);
|
|
|
|
});
|
|
|
|
},
|
2023-08-29 16:44:07 +00:00
|
|
|
matpel2: (filename: string, options: CertData<null>) => {
|
2023-08-29 16:14:33 +00:00
|
|
|
const options_f: CertData<Matpel> = {
|
|
|
|
...options,
|
|
|
|
matpel: Matpel._2,
|
|
|
|
};
|
|
|
|
matpelCert(options_f)
|
|
|
|
.then((doc) => {
|
|
|
|
download(doc, filename);
|
|
|
|
});
|
|
|
|
},
|
2023-08-29 16:44:07 +00:00
|
|
|
matpel3: (filename: string, options: CertData<null>) => {
|
2023-08-29 16:14:33 +00:00
|
|
|
const options_f: CertData<Matpel> = {
|
|
|
|
...options,
|
|
|
|
matpel: Matpel._3,
|
|
|
|
};
|
|
|
|
matpelCert(options_f)
|
|
|
|
.then((doc) => {
|
|
|
|
download(doc, filename);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
manejoDefensivo: certGeneratorGenerator(manejoDefensivoCert),
|
2023-08-29 16:44:07 +00:00
|
|
|
"Mec. Basica": certGeneratorGenerator(mecanicaBasicaCert),
|
2023-08-29 16:14:33 +00:00
|
|
|
"4x4": certGeneratorGenerator(_4X4Cert),
|
|
|
|
segOpMaqPes: certGeneratorGenerator(segOpMaqPesCert),
|
|
|
|
supervisorEscolta: certGeneratorGenerator(supervisorEscolta),
|
|
|
|
iperc: certGeneratorGenerator(ipercCert),
|
|
|
|
});
|
|
|
|
|