You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.1 KiB
59 lines
2.1 KiB
const asyncHandler = require("../Middleware/async"); |
|
const sequelize = require('sequelize') |
|
const db = require('../Config/db') |
|
const WarehouseModel = require('../Model/WarehouseModel') |
|
const ErrorResponse = require('../utils/ErrorResponse') |
|
const fs = require('fs'); |
|
const SuccessResponse = require('../utils/SuccessResponse'); |
|
const dateFormat = require('dateformat') |
|
|
|
exports.getAllWarehouse = asyncHandler(async (req, res, next) => { |
|
try { |
|
const warehouse = await WarehouseModel.findAll({ |
|
where: |
|
{ |
|
DB_CODE: req.user.DB_CODE, |
|
WAR_STAT: 'A' |
|
} |
|
|
|
}) |
|
if (!warehouse) { |
|
return next(new ErrorResponse("Warehouse not found", 404)) |
|
} |
|
res.status(200).json(new SuccessResponse(200, warehouse)) |
|
|
|
} catch (e) { |
|
return next(new ErrorResponse(e, 500)) |
|
|
|
} |
|
}) |
|
|
|
exports.createWarehouse = asyncHandler(async (req, res, next) => { |
|
try { |
|
var date = dateFormat(new Date(), "yyyy-mm-dd HH:mm:ss") |
|
console.log("REQUEST BODY CREATE WAREHOUSE ", req.body) |
|
await db.transaction(async (t) => { |
|
const warehouse = await WarehouseModel.create({ |
|
DB_CODE: req.user.DB_CODE, |
|
WAR_CODE: req.body.WAR_CODE, |
|
WAR_NAME: req.body.WAR_NAME, |
|
WAR_DESC: req.body.WAR_DESC ?? "", |
|
WAR_ADD1: req.body.WAR_ADDRESS ?? "", |
|
WAR_ADD2: req.body.WAR_ADD2 ?? "", |
|
WAR_ADD3: req.body.WAR_ADD3 ?? "", |
|
WAR_TEL1: req.body.WAR_TEL1 ?? "", |
|
WAR_TEL2: req.body.WAR_TEL2 ?? "", |
|
WAR_FAX: req.body.WAR_FAX ?? "", |
|
WAR_COM1: req.body.WAR_COM1 ?? "", |
|
WAR_COM2: req.body.WAR_COM2 ?? "", |
|
WAR_CREA: date, |
|
USER_CODE: req.user.USER_CODE, |
|
WAR_STAT: 'A' |
|
}, { transaction: t }) |
|
res.status(200).json(new SuccessResponse("Operation Successful", warehouse)) |
|
}) |
|
} catch (e) { |
|
console.log("ERROR CREATING WAREHOUSE ", e) |
|
return next(new ErrorResponse(`Something when wrong ${e}`, 500)); |
|
} |
|
}) |