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.
67 lines
2.1 KiB
67 lines
2.1 KiB
const asyncHandler = require("../Middleware/async"); |
|
const sequelize = require('sequelize') |
|
const DBInfo = require("../Model/Database"); |
|
|
|
exports.getDBInfo = asyncHandler(async (req, res, next) => { |
|
console.log("GET DB INFO EXEC ") |
|
var hasNext = false; |
|
// const decode = decodeURIComponent |
|
const { limit, offset = 0, name = "", nodelivery = 0 } = req.query; |
|
const decode = decodeURIComponent(name); |
|
// console.log("DECODE ", decode) |
|
if (name) { |
|
// get count of all databases |
|
const count = await DBInfo.count({ |
|
where: { |
|
DB_NAME: sequelize.where( |
|
sequelize.fn("LOWER", sequelize.col("DB_NAME")), |
|
"LIKE", |
|
"%" + decode.toLowerCase() + "%" |
|
), |
|
}, |
|
}); |
|
|
|
// check if count is greater than offset + limit |
|
if (count > offset + limit) { |
|
hasNext = true; |
|
} |
|
const allDBInfo = await DBInfo.findAll({ |
|
where: { |
|
DB_NAME: sequelize.where( |
|
sequelize.fn("LOWER", sequelize.col("DB_NAME")), |
|
"LIKE", |
|
"%" + decode.toLowerCase() + "%" |
|
), |
|
|
|
}, |
|
offset: offset, |
|
limit: limit, |
|
}).then((db) => { |
|
var list = { databases: db, hasNext: hasNext, count: db.length }; |
|
return res.status(200).send(JSON.stringify(list)); |
|
}); |
|
|
|
|
|
} else { |
|
// if there is no name provide then get all databases |
|
const count = await DBInfo.count(); |
|
if (count > offset + limit) { |
|
hasNext = true; |
|
} |
|
const allDBInfo = await DBInfo.findAll({ |
|
where: { |
|
DB_STAT: "A" |
|
}, |
|
offset: offset, |
|
limit: limit, |
|
}).then((db) => { |
|
var list = { databases: db, hasNext: hasNext, count: db.length }; |
|
return res.status(200).send(JSON.stringify(list)); |
|
}); |
|
} |
|
|
|
// res.status(200).JSON({ |
|
// success: True, |
|
// description: allDBInfo |
|
// }) |
|
})
|