Skip to content

Commit

Permalink
feat: add create product route (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorDePaula committed Feb 25, 2023
1 parent 45870e6 commit 117b108
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/controller/catalogController.js
Expand Up @@ -90,6 +90,22 @@ export async function changeProductImage(req, res) {
}
}

export async function addProduct(req, res) {
const { name, image, description, price, url, retailerId } = req.body;
if (!name || !image || !price)
return res.status(401).send({
message: 'name, price and image was not informed',
});

try {
const result = await req.client.createProduct(name, image, description, price, url, retailerId);
res.status(201).json({ status: 'success', response: result });
} catch (error) {
console.log(error);
res.status(500).json({ status: 'Error', message: 'Error on add product.', error: error });
}
}

export async function addProductImage(req, res) {
const { id, base64 } = req.body;
if (!id || !base64)
Expand Down
1 change: 1 addition & 0 deletions src/routes/index.js
Expand Up @@ -206,6 +206,7 @@ routes.post('/api/:session/reject-call', verifyToken, statusConnection, DeviceCo
// Catalog
routes.get('/api/:session/get-products', verifyToken, statusConnection, CatalogController.getProducts);
routes.get('/api/:session/get-product-by-id', verifyToken, statusConnection, CatalogController.getProductById);
routes.post('/api/:session/add-product', verifyToken, statusConnection, CatalogController.addProduct);
routes.post('/api/:session/edit-product', verifyToken, statusConnection, CatalogController.editProduct);
routes.post('/api/:session/del-products', verifyToken, statusConnection, CatalogController.delProducts);
routes.post('/api/:session/change-product-image', verifyToken, statusConnection, CatalogController.changeProductImage);
Expand Down
76 changes: 76 additions & 0 deletions src/swagger.json
Expand Up @@ -12072,6 +12072,52 @@
"deprecated": false
}
},
"/add-product": {
"post": {
"tags": ["Catalog"],
"summary": "Add a new product",
"description": "Add a new product on catalog on whatsapp business account.",
"operationId": "AddProduct",
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AddProductRequest"
},
"example": {
"name": "Cat",
"description": "white cat",
"image": "data:image/png;base64,..........",
"price": 19.9,
"url": "url my cat",
"retailerId": "ID00123"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"headers": {},
"content": {}
},
"400": {
"description": "Bad Request",
"headers": {},
"content": {}
},
"401": {
"description": "Unauthorized",
"headers": {},
"content": {}
}
},
"deprecated": false
}
},
"/add-product-image": {
"post": {
"tags": ["Catalog"],
Expand Down Expand Up @@ -12117,6 +12163,36 @@
},
"components": {
"schemas": {
"AddProductRequest": {
"title": "AddProductRequest",
"required": ["name", "image", "price"],
"type": "object",
"properties": {
"name": {
"type": "string"
},
"image": {
"type": "string"
},
"price": {
"type": "float"
},
"description": {
"type": "string"
},
"url": {
"type": "string"
},
"retailerId": {
"type": "string"
}
},
"example": {
"name": "white cat",
"image": "data:image/png;base64,..........",
"price": 19.9
}
},
"AddProductImageRequest": {
"title": "AddProductImageRequest",
"required": ["id", "base64"],
Expand Down

0 comments on commit 117b108

Please sign in to comment.