Compare commits
2 Commits
abbe8fba8c
...
853aeddb75
| Author | SHA1 | Date |
|---|---|---|
|
|
853aeddb75 | |
|
|
e13355ce37 |
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
|
|
@ -26,8 +26,17 @@
|
|||
"@nestjs/common": "^11.0.17",
|
||||
"@nestjs/core": "^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",
|
||||
"rxjs": "^7.8.1"
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
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({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
imports: [TypeOrmModule.forRoot(typeOrmConfig)],
|
||||
controllers: [AppController, ListPrinterController],
|
||||
providers: [AppService, ListPrinterService],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { DataSource } from 'typeorm';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
export const typeOrmConfig: DataSourceOptions = {
|
||||
type: 'oracle',
|
||||
username: process.env.DB_USERNAME || 'teste',
|
||||
password: process.env.DB_PASSWORD || 'teste',
|
||||
|
|
@ -15,4 +15,6 @@ export const AppDataSource = new DataSource({
|
|||
poolSize: parseInt(process.env.DB_POOL_SIZE || '10', 10),
|
||||
maxRows: parseInt(process.env.DB_MAX_ROWS || '1000', 10),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const AppDataSource = new DataSource(typeOrmConfig);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
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,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2023",
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
|
|
|
|||
Loading…
Reference in New Issue