Skip to content

Commit

Permalink
feat: add singleton pattern in cart and products factory
Browse files Browse the repository at this point in the history
  • Loading branch information
joxpulp committed Nov 25, 2021
1 parent e139b84 commit b0778d8
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 99 deletions.
168 changes: 163 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 30 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{
"name": "proyectofinal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon",
"start": "node ./dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.13",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
},
"dependencies": {
"dotenv": "^10.0.0",
"express": "^4.17.1",
"firebase-admin": "^9.11.1",
"knex": "^0.95.11",
"mongoose": "^6.0.6",
"mysql": "^2.18.1",
"regenerator-runtime": "^0.13.9",
"sqlite3": "^5.0.2"
}
"name": "proyectofinal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon --DAO=MEMORIA",
"start": "node ./dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/args": "^5.0.0",
"@types/express": "^4.17.13",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
},
"dependencies": {
"args": "^5.0.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"firebase-admin": "^9.11.1",
"knex": "^0.95.11",
"mongoose": "^6.0.6",
"mysql": "^2.18.1",
"regenerator-runtime": "^0.13.9",
"sqlite3": "^5.0.2"
}
}
5 changes: 2 additions & 3 deletions src/apis/cartapi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { flags } from '../config/config';
import { CartFactoryDAO } from '../models/cart/cartfactory';
import { Cart, Products } from '../models/interfaces';

const tipo = 6;

class CartAPI {
private cart;

constructor() {
this.cart = CartFactoryDAO.get(tipo);
this.cart = CartFactoryDAO.get(flags.D);
}

async getProducts(id?: string): Promise<Cart[] | Products[]> {
Expand Down
5 changes: 2 additions & 3 deletions src/apis/productsapi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { FactoryDAO } from '../models/products/productfactory';
import { Products, newProductI, ProductQuery } from '../models/interfaces';

const tipo = 6;
import { flags } from '../config/config';

class prodAPI {
private products;

constructor() {
this.products = FactoryDAO.get(tipo);
this.products = FactoryDAO.get(flags.D);
}

async getProducts(id?: string): Promise<Products[]> {
Expand Down
4 changes: 4 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import dotenv from 'dotenv';
import args from 'args';

args.option('DAO', 'Sets the DB to use')
export const flags = args.parse(process.argv);

dotenv.config();

Expand Down
Loading

0 comments on commit b0778d8

Please sign in to comment.