-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d417233
commit 8b5d8b5
Showing
39 changed files
with
2,033 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
TS-Assignment/DepartmentalStoreAPI - Express/config/default.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"database":{ | ||
"host":"localhost", | ||
"databaseName":"DepartmentalStoreDB3", | ||
"username":"postgres", | ||
"password":"Pass@123" | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
TS-Assignment/DepartmentalStoreAPI - Express/controllers/category.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
TS-Assignment/DepartmentalStoreAPI - Express/controllers/product.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
TS-Assignment/DepartmentalStoreAPI - Express/controllers/productCategory.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
TS-Assignment/DepartmentalStoreAPI - Express/controllers/productInventory.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
TS-Assignment/DepartmentalStoreAPI - Express/controllers/productSupplier.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
TS-Assignment/DepartmentalStoreAPI - Express/controllers/staff.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
TS-Assignment/DepartmentalStoreAPI - Express/controllers/supplier.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
TS-Assignment/DepartmentalStoreAPI - Express/db/entities.db.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |
Oops, something went wrong.