Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
deepkhurana1999 authored Aug 3, 2021
1 parent d417233 commit 8b5d8b5
Showing 39 changed files with 2,033 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"database":{
"host":"localhost",
"databaseName":"DepartmentalStoreDB3",
"username":"postgres",
"password":"Pass@123"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Request, Response } from "express";

import CategoryService from "../services/category.service";
import { ICategory } from "../models/category.model";

export class CategoryController {

private _categoryService: CategoryService;

constructor() {
this._categoryService = new CategoryService();
}

static errorResponse(res: Response) {
console.log('Something happened, think about it!');
return res.status(400).send();
}

public async getCategories(req: Request, res: Response) {
try {
const result: ICategory[] | undefined = await this._categoryService.getCategory();
if (!result || result.length === 0)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return CategoryController.errorResponse(res);
}
}

public async getCategoryByID(req: Request, res: Response) {
try {
const result = await this._categoryService.getCategoryByID(req.params['id']);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return CategoryController.errorResponse(res);
}
}

public async saveCategory(req: Request, res: Response) {
try {
const result = await this._categoryService.saveCategory(req.body);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return CategoryController.errorResponse(res);
}
}

public async updateCategory(req: Request, res: Response) {
try {
const result = await this._categoryService.updateCategory(req.body,req.params['id']);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return CategoryController.errorResponse(res);
}
}

public async deleteCategory(req: Request, res: Response) {
try {
await this._categoryService.deleteCategory(req.params['id']);
return res.status(200).send();
}
catch (err) {
return CategoryController.errorResponse(res);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Request, Response } from "express";

import { IProduct } from "../models/product.model";
import ProductService from "../services/product.service";

export class ProductController {

private _productService: ProductService = new ProductService();

static errorResponse(res: Response) {
console.log('Something happened, think about it!');
return res.status(500).send();
}

public async getProducts(req: Request, res: Response) {
try {
const result: IProduct[] | undefined = await this._productService.get();
if (!result || result.length === 0)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return ProductController.errorResponse(res);
}
}

public async getProductByID(req: Request, res: Response) {
try {
const result:IProduct | undefined = await this._productService.getByID(req.params['id']);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return ProductController.errorResponse(res);
}
}

public async saveProduct(req: Request, res: Response) {
try {
const result = await this._productService.save(req.body);
return res.send(JSON.stringify(result));
}
catch (err) {
return ProductController.errorResponse(res);
}
}

public async updateProduct(req: Request, res: Response) {
try {
const result = await this._productService.update(req.body,req.params['id']);
return res.send(JSON.stringify(result));
}
catch (err) {
return ProductController.errorResponse(res);
}
}

public async deleteProduct(req: Request, res: Response) {
try {
await this._productService.deleteWithAssociation(req.params['id']);
return res.status(200).send();
}
catch (err) {
return ProductController.errorResponse(res);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Request, Response } from "express";

import { ICategory } from "../models/category.model";
import ProductService from "../services/product.service";


export default class ProductCategoryController {

private _productService: ProductService;

constructor() {
this._productService = new ProductService();
}

async getProductCategory(req: Request, res: Response) {
try {
const result:ICategory[] | undefined = await this._productService.getProductCategory(req.params['id']);
if(!result)
return res.status(204).send();
return res.send(result);
}
catch (err) {
console.log('Something happened, think about it!');
return res.status(500).send();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Request, Response } from "express";

import { IInventory } from "../models/inventory.model";
import ProductService from "../services/product.service";


export default class ProductInventoryController {

private _productService: ProductService;

constructor() {
this._productService = new ProductService();
}

async getProductInventory(req: Request, res: Response) {
try {
const result:IInventory[] | undefined = await this._productService.getProductInventory(req.params['id']);
if(!result)
return res.status(204).send();
return res.send(result);
}
catch (err) {
console.log('Something happened, think about it!');
return res.status(500).send();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Request, Response } from "express";

import ISupplier from "../models/supplier.model";
import ProductService from "../services/product.service";


export default class ProductSupplierController {

private _productService: ProductService;

constructor() {
this._productService = new ProductService();
}

async getProductSuppliers(req: Request, res: Response) {
try {
const result:ISupplier[] | undefined = await this._productService.getProductSuppliers(req.params['id']);
if(!result)
return res.status(204).send();
return res.send(result);
}
catch (err) {
console.log('Something happened, think about it!');
return res.status(500).send();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Request, Response } from "express";

import IStaff from "../models/staff.model";
import StaffService from "../services/staff.service";

export default class StaffController {

private _staffService: StaffService;

constructor() {
this._staffService = new StaffService();
}

static errorResponse(res: Response) {
console.log('Something happened, think about it!');
return res.status(400).send();
}

public async getStaff(req: Request, res: Response) {
try {
const result: IStaff[] | undefined = await this._staffService.getStaff();
if (!result || result.length === 0)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return StaffController.errorResponse(res);
}
}

public async getStaffByID(req: Request, res: Response) {
try {
const result = await this._staffService.getStaffByID(req.params['id']);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return StaffController.errorResponse(res);
}
}

public async deleteStaff(req: Request, res: Response) {
try {
await this._staffService.deleteStaff(req.params['id']);
return res.status(200).send();
}
catch (err) {
return StaffController.errorResponse(res);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Request, Response } from "express";

import ISupplier from "../models/supplier.model";
import SupplierService from "../services/supplier.service";

export default class SupplierController {

private _supplierService: SupplierService;

constructor() {
this._supplierService = new SupplierService();
}

static errorResponse(res: Response) {
console.log('Something happened, think about it!');
return res.status(500).send();
}

public async getSuppliers(req: Request, res: Response) {
try {
const result: ISupplier[] | undefined = await this._supplierService.getSuppliers();
if (!result || result.length === 0)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return SupplierController.errorResponse(res);
}
}

public async saveSupplier(req: Request, res: Response) {
try {
let result: ISupplier | undefined = await this._supplierService.saveSupplier(req.body);

if (!result)
return res.status(500).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return SupplierController.errorResponse(res);
}
}

public async getSupplierByID(req: Request, res: Response) {
try {
const result: ISupplier | undefined = await this._supplierService.getSupplierByID(req.params['id']);
if (!result)
return res.status(204).send();
return res.send(JSON.stringify(result));
}
catch (err) {
return SupplierController.errorResponse(res);
}
}



public async deleteSupplier(req: Request, res: Response) {
try {
await this._supplierService.deleteSupplier(req.params['id']);
return res.status(200).send();
}
catch (err) {
return SupplierController.errorResponse(res);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum Entities{
Address = "Address",
Staff = "Staff",
Desingation = "Designation",
Supplier = "Supplier",
Product = "Product",
Category = "Category",
Inventory = "Inventory",
}
11 changes: 11 additions & 0 deletions TS-Assignment/DepartmentalStoreAPI - Express/db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Pool } from "pg";
import config from "config";

export const pool = new Pool({
host: config.get<any>('database').host,
user: config.get<any>('database').username,
password: config.get<any>('database').password,
database: config.get<any>('database').databaseName,
max: 10,
connectionTimeoutMillis: 10000,
});
Loading

0 comments on commit 8b5d8b5

Please sign in to comment.