Felix Olszewski

101
reputation

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable() export class DatabaseService { private client: Pool;

constructor() { this.client = new Pool({ host: 'localhost', port: 5432, user: 'felixolszewski', database: 'postgres', }); }

async query(text: string, params?: any[]) { return this.client.query(text, params); }

async getAllDepartment() { const queryResult = await this.query('SELECT * FROM department'); return queryResult.rows }

async getDepartment(name: string) { const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]); return queryResult.rows }

async getAllEmployeesByDepartment(id: string) { console.log(id); const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]); return queryResult.rows }

}

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable() export class DatabaseService { private client: Pool;

constructor() { this.client = new Pool({ host: 'localhost', port: 5432, user: 'felixolszewski', database: 'postgres', }); }

async query(text: string, params?: any[]) { return this.client.query(text, params); }

async getAllDepartment() { const queryResult = await this.query('SELECT * FROM department'); return queryResult.rows }

async getDepartment(name: string) { const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]); return queryResult.rows }

async getAllEmployeesByDepartment(id: string) { console.log(id); const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]); return queryResult.rows }

}

database.service.ts

import { Injectable } from '@nestjs/common';
import { Pool } from 'pg';

@Injectable() export class DatabaseService { private client: Pool;

constructor() { this.client = new Pool({ host: 'localhost', port: 5432, user: 'felixolszewski', database: 'postgres', }); }

async query(text: string, params?: any[]) { return this.client.query(text, params); }

async getAllDepartment() { const queryResult = await this.query('SELECT * FROM department'); return queryResult.rows }

async getDepartment(name: string) { const queryResult = await this.query('SELECT * FROM department WHERE name = $1', [name]); return queryResult.rows }

async getAllEmployeesByDepartment(id: string) { console.log(id); const queryResult = await this.query('SELECT * FROM employee WHERE departmentid = $1', [id]); return queryResult.rows }

}