Spaces:
Runtime error
Runtime error
File size: 1,555 Bytes
22f3b1c d747060 22f3b1c dfe6d55 22f3b1c dfe6d55 22f3b1c d747060 22f3b1c dfe6d55 22f3b1c dfe6d55 22f3b1c d747060 22f3b1c d747060 22f3b1c |
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 |
import { Request, Response } from 'express';
import { VendorConfig } from '../../models/VendorConfig';
import { logger } from '../../utils/logger';
export const setVendorConfig = async (req: Request, res: Response) => {
const { vendor_id, single_line_item } = req.body;
try {
const [vendorConfig, created] = await VendorConfig.upsert({
pw_vendor_id:vendor_id,
single_line_item:single_line_item,
});
res.status(200).json({ vendorConfig, created });
} catch (error) {
logger.error('Error saving Vendor Config');
logger.error(error);
res.status(500).json({ error: 'Error while saving Vendor Config' });
}
};
export const getVendorConfig = async (req: Request, res: Response) => {
const { vendor_id } = req.params;
try {
const vendorConfig = await VendorConfig.findOne({ where: { pw_vendor_id:vendor_id } });
if (!vendorConfig) {
return res.status(404).json({ message: 'Vendor configuration not found' });
}
res.status(200).json(vendorConfig);
} catch (error) {
logger.error('Error fetching Vendor Config');
logger.error(error);
res.status(500).json({ error:'Error while fetching Vendor Config'});
}
};
export const getAllVendorConfigs = async (req: Request, res: Response) => {
try {
const vendorConfigs = await VendorConfig.findAll();
res.status(200).json(vendorConfigs);
} catch (error) {
logger.error('Error fetching Vendor Configs');
logger.error(error);
res.status(500).json({ error:'Error while fetching Vendor Config'});
}
};
|