This repository was archived by the owner on Nov 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathproduct-controller.js
More file actions
85 lines (67 loc) · 2.21 KB
/
product-controller.js
File metadata and controls
85 lines (67 loc) · 2.21 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import ProductService from './../services/product-service.js'
class ProductController {
static createProduct = (require, response) => {
ProductService.createProduct(require)
.then(() => {
response.status(201).send({message: 'Successfully create product'})
})
.catch(err => {
response.status(500).send({message: err.message})
})
}
static getProducts = (require, response) => {
ProductService.getProducts(require)
.then(products => {
response.status(200).send(products)
})
.catch(err => {
response.status(400).send({message: err.message})
})
}
static searchProductsByCategory = (require, response) => {
ProductService.searchProductsByCategory(require)
.then(products => {
response.status(200).send(products)
})
.catch(err => {
response.status(400).send({message: err.message})
})
}
static searchProductByTitle = (require, response) => {
ProductService.searchProductByTitle(require)
.then(product => {
response.status(200).send(product)
})
.catch(err => {
response.status(400).send({message: err.message})
})
}
static getProduct = (require, response) => {
ProductService.getProduct(require)
.then(product => {
response.status(200).send(product)
})
.catch(err => {
response.status(400).send({message: err.message})
})
}
static updateProduct = (require, response) => {
ProductService.updateProduct(require)
.then( success => {
response.status(200).send({message: 'Successfully update product'})
})
.catch(err => {
response.status(500).send({message: err.message})
})
}
static deleteProduct = (require, response) => {
ProductService.deleteProduct(require)
.then(() => {
response.status(200).send({message: 'Successfully delete product'})
})
.catch(err => {
response.status(500).send({message: err.message})
})
}
}
export default ProductController