forked from airamez/codando-live
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_05_ProductService.js
More file actions
65 lines (54 loc) · 1.55 KB
/
_05_ProductService.js
File metadata and controls
65 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
export default class DataAccessService {
constructor() {
this.products = [];
this.nextId = 1;
// Simulating database retrieval for suppliers and categories
this.suppliers = [
{ id: 1, name: "TechNova Solutions" },
{ id: 2, name: "Digital Powerhouse" },
{ id: 3, name: "ElectroGenius Supplies" },
{ id: 4, name: "NextWave Electronics" },
{ id: 5, name: "Innovatech Components" }
];
this.categories = [
{ id: 1, name: "Smartphones & Accessories" },
{ id: 2, name: "Computers & Laptops" },
{ id: 3, name: "Audio & Sound Systems" },
{ id: 4, name: "Gaming & Consoles" },
{ id: 5, name: "Wearable Tech" },
{ id: 6, name: "Home Automation & IoT" },
{ id: 7, name: "Cameras & Photography" }
];
}
addProduct(product) {
product.id = this.nextId++;
this.products.push(product);
}
updateProduct(updatedProduct) {
const index = this.products.findIndex(p => p.id === updatedProduct.id);
if (index !== -1) {
this.products[index] = updatedProduct;
}
}
deleteProduct(id) {
this.products = this.products.filter(p => p.id !== id);
}
getProducts() {
return this.products;
}
getProductById(id) {
return this.products.find(p => p.id === id);
}
getSuppliers() {
return this.suppliers;
}
getCategories() {
return this.categories;
}
getSupplier(id) {
return this.suppliers.find(supplier => supplier.id === id) || null;
}
getCategory(id) {
return this.categories.find(category => category.id === id) || null;
}
}