narinder1231's picture
improve error logging and error messages
d747060
import { Request, Response } from 'express';
import { logger } from '../../utils/logger';
import PWGlaccounts from '../../models/pwGlaccounts';
import { syncGlAccountsFromJsonService } from '../../shared/services/glaccounts.service';
const ExpenseAccountTypes = ['Expense', 'Income', 'Current Liability', 'Current Asset', 'Equity'];
export const fetchGLAccountsData = async (req: Request, res: Response) => {
try {
const glAccounts = await PWGlaccounts.findAll({
attributes: [['pw_id', 'id'], 'name'],
order: [['name', 'ASC']],
});
res.status(200).json(glAccounts);
} catch (error) {
logger.error('Error fetching GL accounts:', error);
logger.error(error);
res.status(500).json({ error: 'Error fetching GL accounts' });
}
};
export const fetchGLAccountsWithDetails = async (req: Request, res: Response) => {
try {
const glAccounts = await PWGlaccounts.findAll({
attributes: [['pw_id', 'id'], 'name', ['account_number', 'accountNumber']],
order: [['name', 'ASC']],
});
res.status(200).json(glAccounts);
} catch (error) {
logger.error('Error fetching GL accounts:', error);
logger.error(error);
res.status(500).json({ error: 'Error fetching GL accounts' });
}
};
export const syncGLAccounts = async (req: Request, res: Response) => {
try {
const result = await syncGlAccountsFromJsonService();
res.status(200).json(result);
} catch (error) {
logger.error('Error syncing GL accounts:', error);
logger.error(error);
res.status(500).json({ error: 'Error syncing GL accounts' });
}
};