|
@@ -14,6 +14,39 @@ async function getNextId(Model, where, items) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function getPreviousId(Model, where, items, limit) {
|
|
|
+ try {
|
|
|
+ let minId = await Model.min('id', { where })
|
|
|
+ let firstItem = items[0]
|
|
|
+
|
|
|
+ let lteVal
|
|
|
+
|
|
|
+ if(firstItem.id - limit) {
|
|
|
+ lteVal = firstItem.id - limit
|
|
|
+ } else {
|
|
|
+ minId
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!firstItem || minId === firstItem.id) {
|
|
|
+ return null
|
|
|
+ } else {
|
|
|
+ let instance = await Model.findOne({
|
|
|
+ where: Object.assign({}, {
|
|
|
+ id: {
|
|
|
+ $lte: lteVal
|
|
|
+ }
|
|
|
+ }, where)
|
|
|
+ })
|
|
|
+
|
|
|
+ return instance.id
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ return null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
function getPaginationProps(query) {
|
|
|
let lastId = 0
|
|
|
let limit = 10
|
|
@@ -26,5 +59,6 @@ function getPaginationProps(query) {
|
|
|
|
|
|
module.exports = {
|
|
|
getNextId,
|
|
|
+ getPreviousId,
|
|
|
getPaginationProps
|
|
|
}
|