const asyncHandler = require("../Middleware/async"); const sequelize = require('sequelize') const db = require('../Config/db') const SupplierModel = require('../Model/SupplierModel') const ErrorResponse = require('../utils/ErrorResponse') const fs = require('fs'); const dateFormat = require('dateformat'); exports.getAllSupplier = asyncHandler(async (req, res, next) => { try { const supplier = await SupplierModel.findAll({ where: { DB_CODE: req.user.DB_CODE } } ) res.status(200).send({ success: true, data: supplier }) } catch (e) { throw new ErrorResponse(e, 400) } }) exports.createSupplier = asyncHandler(async (req, res, next) => { const data = JSON.parse(req.body.data) if (!data.ADD_NAME || !data.ADD_CODE || !data.phoneNumber) { throw new ErrorResponse('Please provide all required fields', 400) } try { data.DB_CODE = req.user.DB_CODE const supplier = await SupplierModel.create({ DB_CODE: req.user.DB_CODE, USER_CODE: req.user.USER_NAME, ADD_NAME: data.ADD_NAME, ADD_CODE: data.ADD_CODE, ADD_LINE_1: data.addressLine1, }) res.status(200).send({ success: true, data: supplier }) } catch (e) { throw new ErrorResponse(e, 400) } })