Spaces:
Runtime error
Runtime error
Bansari Akhani commited on
Commit ·
dfe6d55
1
Parent(s): 0d23101
change variable naming
Browse files
src/controllers/settings/vendorConfig.controller.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { Request, Response } from 'express';
|
|
| 2 |
import { VendorConfig } from '../../models/VendorConfig';
|
| 3 |
|
| 4 |
export const setVendorConfig = async (req: Request, res: Response) => {
|
| 5 |
-
const {
|
| 6 |
|
| 7 |
try {
|
| 8 |
const [vendorConfig, created] = await VendorConfig.upsert({
|
| 9 |
-
pw_vendor_id:
|
| 10 |
-
single_line_item:
|
| 11 |
});
|
| 12 |
|
| 13 |
res.status(200).json({ vendorConfig, created });
|
|
@@ -18,10 +18,10 @@ export const setVendorConfig = async (req: Request, res: Response) => {
|
|
| 18 |
};
|
| 19 |
|
| 20 |
export const getVendorConfig = async (req: Request, res: Response) => {
|
| 21 |
-
const {
|
| 22 |
|
| 23 |
try {
|
| 24 |
-
const vendorConfig = await VendorConfig.findOne({ where: { pw_vendor_id:
|
| 25 |
|
| 26 |
if (!vendorConfig) {
|
| 27 |
return res.status(404).json({ message: 'Vendor configuration not found' });
|
|
|
|
| 2 |
import { VendorConfig } from '../../models/VendorConfig';
|
| 3 |
|
| 4 |
export const setVendorConfig = async (req: Request, res: Response) => {
|
| 5 |
+
const { vendor_id, single_line_item } = req.body;
|
| 6 |
|
| 7 |
try {
|
| 8 |
const [vendorConfig, created] = await VendorConfig.upsert({
|
| 9 |
+
pw_vendor_id:vendor_id,
|
| 10 |
+
single_line_item:single_line_item,
|
| 11 |
});
|
| 12 |
|
| 13 |
res.status(200).json({ vendorConfig, created });
|
|
|
|
| 18 |
};
|
| 19 |
|
| 20 |
export const getVendorConfig = async (req: Request, res: Response) => {
|
| 21 |
+
const { vendor_id } = req.params;
|
| 22 |
|
| 23 |
try {
|
| 24 |
+
const vendorConfig = await VendorConfig.findOne({ where: { pw_vendor_id:vendor_id } });
|
| 25 |
|
| 26 |
if (!vendorConfig) {
|
| 27 |
return res.status(404).json({ message: 'Vendor configuration not found' });
|
src/routes/vendorConfig.routes.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { setVendorConfig, getVendorConfig, getAllVendorConfigs } from '../contro
|
|
| 4 |
import { jwtMiddleware } from '../middlewares/authMiddleware';
|
| 5 |
|
| 6 |
const vendorConfigRouter = express.Router();
|
| 7 |
-
vendorConfigRouter.use(jwtMiddleware);
|
| 8 |
|
| 9 |
/**
|
| 10 |
* @swagger
|
|
@@ -13,6 +12,34 @@ vendorConfigRouter.use(jwtMiddleware);
|
|
| 13 |
* description: API for managing vendor configurations.
|
| 14 |
*/
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
/**
|
| 17 |
* @swagger
|
| 18 |
* /api/vendor-config:
|
|
@@ -26,15 +53,15 @@ vendorConfigRouter.use(jwtMiddleware);
|
|
| 26 |
* schema:
|
| 27 |
* type: object
|
| 28 |
* properties:
|
| 29 |
-
*
|
| 30 |
* type: integer
|
| 31 |
* description: The ID of the vendor.
|
| 32 |
-
*
|
| 33 |
* type: boolean
|
| 34 |
* description: Indicates if the bill split items should be a single line item.
|
| 35 |
* required:
|
| 36 |
-
* -
|
| 37 |
-
* -
|
| 38 |
* responses:
|
| 39 |
* 200:
|
| 40 |
* description: Vendor configuration set or updated successfully.
|
|
@@ -47,9 +74,9 @@ vendorConfigRouter.use(jwtMiddleware);
|
|
| 47 |
* type: object
|
| 48 |
* description: The vendor configuration.
|
| 49 |
* properties:
|
| 50 |
-
*
|
| 51 |
* type: integer
|
| 52 |
-
*
|
| 53 |
* type: boolean
|
| 54 |
* created:
|
| 55 |
* type: boolean
|
|
@@ -60,13 +87,13 @@ vendorConfigRouter.post('/', setVendorConfig);
|
|
| 60 |
|
| 61 |
/**
|
| 62 |
* @swagger
|
| 63 |
-
* /api/vendor-config/{
|
| 64 |
* get:
|
| 65 |
* summary: Get vendor configuration by ID
|
| 66 |
* tags: [VendorConfig]
|
| 67 |
* parameters:
|
| 68 |
* - in: path
|
| 69 |
-
* name:
|
| 70 |
* schema:
|
| 71 |
* type: integer
|
| 72 |
* required: true
|
|
@@ -81,43 +108,18 @@ vendorConfigRouter.post('/', setVendorConfig);
|
|
| 81 |
* properties:
|
| 82 |
* id:
|
| 83 |
* type: integer
|
| 84 |
-
*
|
| 85 |
* type: integer
|
| 86 |
-
*
|
| 87 |
* type: boolean
|
| 88 |
* 404:
|
| 89 |
* description: Vendor configuration not found.
|
| 90 |
* 500:
|
| 91 |
* description: Internal server error.
|
| 92 |
*/
|
| 93 |
-
vendorConfigRouter.get('/:
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
-
/**
|
| 97 |
-
* @swagger
|
| 98 |
-
* /api/vendor-config:
|
| 99 |
-
* get:
|
| 100 |
-
* summary: Get all vendor configurations
|
| 101 |
-
* tags: [VendorConfig]
|
| 102 |
-
* responses:
|
| 103 |
-
* 200:
|
| 104 |
-
* description: Successfully retrieved all vendor configurations.
|
| 105 |
-
* content:
|
| 106 |
-
* application/json:
|
| 107 |
-
* schema:
|
| 108 |
-
* type: array
|
| 109 |
-
* items:
|
| 110 |
-
* type: object
|
| 111 |
-
* properties:
|
| 112 |
-
* id:
|
| 113 |
-
* type: integer
|
| 114 |
-
* vendorId:
|
| 115 |
-
* type: integer
|
| 116 |
-
* singleLineItem:
|
| 117 |
-
* type: boolean
|
| 118 |
-
* 500:
|
| 119 |
-
* description: Internal server error.
|
| 120 |
-
*/
|
| 121 |
-
vendorConfigRouter.get('/', getAllVendorConfigs);
|
| 122 |
|
| 123 |
export default vendorConfigRouter;
|
|
|
|
| 4 |
import { jwtMiddleware } from '../middlewares/authMiddleware';
|
| 5 |
|
| 6 |
const vendorConfigRouter = express.Router();
|
|
|
|
| 7 |
|
| 8 |
/**
|
| 9 |
* @swagger
|
|
|
|
| 12 |
* description: API for managing vendor configurations.
|
| 13 |
*/
|
| 14 |
|
| 15 |
+
/**
|
| 16 |
+
* @swagger
|
| 17 |
+
* /api/vendor-config:
|
| 18 |
+
* get:
|
| 19 |
+
* summary: Get all vendor configurations
|
| 20 |
+
* tags: [VendorConfig]
|
| 21 |
+
* responses:
|
| 22 |
+
* 200:
|
| 23 |
+
* description: Successfully retrieved all vendor configurations.
|
| 24 |
+
* content:
|
| 25 |
+
* application/json:
|
| 26 |
+
* schema:
|
| 27 |
+
* type: array
|
| 28 |
+
* items:
|
| 29 |
+
* type: object
|
| 30 |
+
* properties:
|
| 31 |
+
* id:
|
| 32 |
+
* type: integer
|
| 33 |
+
* vendor_ID:
|
| 34 |
+
* type: integer
|
| 35 |
+
* single_line_item:
|
| 36 |
+
* type: boolean
|
| 37 |
+
* 500:
|
| 38 |
+
* description: Internal server error.
|
| 39 |
+
*/
|
| 40 |
+
vendorConfigRouter.get('/', getAllVendorConfigs);
|
| 41 |
+
vendorConfigRouter.use(jwtMiddleware);
|
| 42 |
+
|
| 43 |
/**
|
| 44 |
* @swagger
|
| 45 |
* /api/vendor-config:
|
|
|
|
| 53 |
* schema:
|
| 54 |
* type: object
|
| 55 |
* properties:
|
| 56 |
+
* vendor_id:
|
| 57 |
* type: integer
|
| 58 |
* description: The ID of the vendor.
|
| 59 |
+
* single_line_item:
|
| 60 |
* type: boolean
|
| 61 |
* description: Indicates if the bill split items should be a single line item.
|
| 62 |
* required:
|
| 63 |
+
* - vendor_id
|
| 64 |
+
* - single_line_item
|
| 65 |
* responses:
|
| 66 |
* 200:
|
| 67 |
* description: Vendor configuration set or updated successfully.
|
|
|
|
| 74 |
* type: object
|
| 75 |
* description: The vendor configuration.
|
| 76 |
* properties:
|
| 77 |
+
* vendor_id:
|
| 78 |
* type: integer
|
| 79 |
+
* single_line_item:
|
| 80 |
* type: boolean
|
| 81 |
* created:
|
| 82 |
* type: boolean
|
|
|
|
| 87 |
|
| 88 |
/**
|
| 89 |
* @swagger
|
| 90 |
+
* /api/vendor-config/{vendor_id}:
|
| 91 |
* get:
|
| 92 |
* summary: Get vendor configuration by ID
|
| 93 |
* tags: [VendorConfig]
|
| 94 |
* parameters:
|
| 95 |
* - in: path
|
| 96 |
+
* name: vendor_id
|
| 97 |
* schema:
|
| 98 |
* type: integer
|
| 99 |
* required: true
|
|
|
|
| 108 |
* properties:
|
| 109 |
* id:
|
| 110 |
* type: integer
|
| 111 |
+
* vendor_id:
|
| 112 |
* type: integer
|
| 113 |
+
* single_line_item:
|
| 114 |
* type: boolean
|
| 115 |
* 404:
|
| 116 |
* description: Vendor configuration not found.
|
| 117 |
* 500:
|
| 118 |
* description: Internal server error.
|
| 119 |
*/
|
| 120 |
+
vendorConfigRouter.get('/:vendor_id', getVendorConfig);
|
| 121 |
+
|
| 122 |
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
export default vendorConfigRouter;
|