Compare commits
No commits in common. "853aeddb75b776c860bed14682b01a732766bd90" and "abbe8fba8c1f5c83c074366db6e0b31cd5d1c787" have entirely different histories.
853aeddb75
...
abbe8fba8c
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
|
|
@ -26,17 +26,8 @@
|
||||||
"@nestjs/common": "^11.0.17",
|
"@nestjs/common": "^11.0.17",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
|
||||||
"@types/multer": "^2.0.0",
|
|
||||||
"multer": "^2.0.2",
|
|
||||||
"node-printer": "^1.0.4",
|
|
||||||
"oracledb": "^6.10.0",
|
|
||||||
"pdf-to-printer": "^5.6.1",
|
|
||||||
"printer": "^0.4.0",
|
|
||||||
"puppeteer": "^24.35.0",
|
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1"
|
||||||
"typeorm": "^0.3.28"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { ListPrinterController } from './controller/list-printer.controller';
|
|
||||||
import { ListPrinterService } from './services/list-printer';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { typeOrmConfig } from './config/typeorm.config';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forRoot(typeOrmConfig)],
|
imports: [],
|
||||||
controllers: [AppController, ListPrinterController],
|
controllers: [AppController],
|
||||||
providers: [AppService, ListPrinterService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
|
|
||||||
export const typeOrmConfig: DataSourceOptions = {
|
export const AppDataSource = new DataSource({
|
||||||
type: 'oracle',
|
type: 'oracle',
|
||||||
username: process.env.DB_USERNAME || 'teste',
|
username: process.env.DB_USERNAME || 'teste',
|
||||||
password: process.env.DB_PASSWORD || 'teste',
|
password: process.env.DB_PASSWORD || 'teste',
|
||||||
|
|
@ -15,6 +15,4 @@ export const typeOrmConfig: DataSourceOptions = {
|
||||||
poolSize: parseInt(process.env.DB_POOL_SIZE || '10', 10),
|
poolSize: parseInt(process.env.DB_POOL_SIZE || '10', 10),
|
||||||
maxRows: parseInt(process.env.DB_MAX_ROWS || '1000', 10),
|
maxRows: parseInt(process.env.DB_MAX_ROWS || '1000', 10),
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
export const AppDataSource = new DataSource(typeOrmConfig);
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { Controller, Get, Post, Body } from '@nestjs/common';
|
|
||||||
import { ListPrinterService } from '../services/list-printer';
|
|
||||||
|
|
||||||
@Controller('printers')
|
|
||||||
export class ListPrinterController {
|
|
||||||
constructor(private readonly listPrinterService: ListPrinterService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
async getPrinters() {
|
|
||||||
return this.listPrinterService.listPrinters();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('print')
|
|
||||||
async print(@Body() body: { printerName: string; filePath: string }) {
|
|
||||||
return this.listPrinterService.printDocument(body.printerName, body.filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { exec } from 'child_process';
|
|
||||||
import { promisify } from 'util';
|
|
||||||
import { print } from 'pdf-to-printer';
|
|
||||||
|
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ListPrinterService {
|
|
||||||
async listPrinters(): Promise<string[]> {
|
|
||||||
try {
|
|
||||||
const { stdout } = await execAsync(
|
|
||||||
'powershell -Command "Get-Printer | Select-Object -ExpandProperty Name"',
|
|
||||||
{ encoding: 'utf-8' }
|
|
||||||
);
|
|
||||||
|
|
||||||
const printers = stdout
|
|
||||||
.split('\r\n')
|
|
||||||
.map(line => line.trim())
|
|
||||||
.filter(line => line && line !== 'Name');
|
|
||||||
|
|
||||||
return printers;
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`Failed to list printers: ${(error as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async printDocument(printerName: string, filePath: string): Promise<{ success: boolean; message: string }> {
|
|
||||||
try {
|
|
||||||
await print(filePath, { printer: printerName });
|
|
||||||
return { success: true, message: `Document sent to printer: ${printerName}` };
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`Failed to print document: ${(error as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"target": "ES2021",
|
"target": "ES2023",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue