-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
44 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1(dev) | ||
v0.0.1(dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Paging from './paging' | ||
import { getPagingOptions } from './paging' | ||
import MongooseBase from './base' | ||
|
||
export { MongooseBase, Paging } | ||
export { MongooseBase, getPagingOptions } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
/** 分页器 */ | ||
class Paging { | ||
/** 分页参数 */ | ||
interface PagingParams { | ||
/** 每页数据量 */ | ||
public limit = 10 | ||
limit?: number | ||
/** 跳过的数据量 */ | ||
public skip = 0 | ||
/** 排序依据 */ | ||
public orderField: string | null = null | ||
skip?: number | ||
/** 排序依据字段 */ | ||
orderField?: string | ||
/** 是否倒序 */ | ||
public descend = false | ||
descend?: boolean | ||
} | ||
|
||
const defaultPagingParams: PagingParams = { | ||
limit: 10, | ||
skip: 0 | ||
} | ||
|
||
/** | ||
* 获取分页选项 | ||
*/ | ||
function getPagingOptions(query: Partial<PagingParams>) { | ||
const { limit, skip, orderField, descend } = query | ||
|
||
const options = Object.assign({}, defaultPagingParams) | ||
|
||
constructor(pojo: Pojo) { | ||
const { limit, skip, orderField, descend } = pojo | ||
if (typeof limit === 'number' || typeof Number(limit) === 'number') options.limit = Number(limit) | ||
if (typeof skip === 'number' || typeof Number(skip) === 'number') options.skip = Number(skip) | ||
if (orderField && typeof orderField === 'string') options.orderField = orderField | ||
if (typeof descend === 'boolean') options.descend = descend | ||
|
||
if (typeof limit === 'number' || typeof Number(limit) === 'number') this.limit = Number(limit) | ||
if (typeof skip === 'number' || typeof Number(skip) === 'number') this.skip = Number(skip) | ||
if (orderField && typeof orderField === 'string') this.orderField = orderField | ||
if (typeof descend === 'boolean') this.descend = descend | ||
} | ||
return options | ||
} | ||
|
||
export default Paging | ||
export { getPagingOptions } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters