Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

59 lignes
1.3 KiB

  1. import { inject, injectable } from 'tsyringe';
  2. import AppError from '../../erros/AppError';
  3. import IPdfToTextProvider from '../../containers/providers/pdfToText/IPdfToTextProvider';
  4. import regexMapaFolha from '../../utils/regex/regexMapaFolha';
  5. import * as format from '../../utils/format';
  6. interface IRequest {
  7. files: Express.Multer.File[];
  8. }
  9. interface ICompanyContent {
  10. name: string;
  11. code: string;
  12. cnpj: string;
  13. refEndDate: string;
  14. refStartDate: string;
  15. address: string;
  16. contentEmployee: string;
  17. }
  18. type IResponse = Array<{
  19. fileName: string;
  20. content: string;
  21. }>;
  22. @injectable()
  23. export default class ExempleService {
  24. constructor(
  25. @inject('PdfToTextProvider')
  26. private pdfToTextProvider: IPdfToTextProvider,
  27. ) {}
  28. public async execute({ files }: IRequest): Promise<IResponse> {
  29. if (!files) {
  30. throw new AppError('File is required');
  31. }
  32. files.forEach(file => {
  33. if (file.mimetype !== 'application/pdf') {
  34. throw new AppError('Only PDF is accepted');
  35. }
  36. });
  37. const response: IResponse = [];
  38. for (let indexFile = 0; indexFile < files.length; indexFile++) {
  39. const file = files[indexFile];
  40. const contentFile = await this.pdfToTextProvider.extract(file.path);
  41. response.push({
  42. fileName: file.filename,
  43. content: contentFile,
  44. });
  45. }
  46. return response;
  47. }
  48. }