express-sweet-generator 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -59,22 +59,22 @@ module.exports = class extends expressExtension.database.Model {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
static async paginate(
|
|
63
|
-
|
|
62
|
+
static async paginate(paginationOptions) {
|
|
63
|
+
paginationOptions = Object.assign({
|
|
64
64
|
start: 0,
|
|
65
65
|
length: 30,
|
|
66
66
|
order: null,
|
|
67
67
|
dir: 'asc',
|
|
68
68
|
search: null,
|
|
69
|
-
},
|
|
69
|
+
}, paginationOptions);
|
|
70
70
|
|
|
71
71
|
const recordsTotal = await super.count();
|
|
72
72
|
|
|
73
73
|
const whereClause = {};
|
|
74
|
-
if (
|
|
74
|
+
if (paginationOptions.search)
|
|
75
75
|
whereClause[super.Op.or] = [
|
|
76
|
-
{email: {[super.Op.like]: `%${
|
|
77
|
-
{name: {[super.Op.like]: `%${
|
|
76
|
+
{email: {[super.Op.like]: `%${paginationOptions.search}%`}},
|
|
77
|
+
{name: {[super.Op.like]: `%${paginationOptions.search}%`}}
|
|
78
78
|
];
|
|
79
79
|
|
|
80
80
|
const recordsFiltered = await super.count({where: whereClause});
|
|
@@ -82,9 +82,9 @@ module.exports = class extends expressExtension.database.Model {
|
|
|
82
82
|
const data = await super.findAll({
|
|
83
83
|
attributes: ['id', 'name', 'email', 'icon', 'modified'],
|
|
84
84
|
where: whereClause,
|
|
85
|
-
order: [[
|
|
86
|
-
offset: parseInt(
|
|
87
|
-
limit: parseInt(
|
|
85
|
+
order: [[paginationOptions.order, paginationOptions.dir]],
|
|
86
|
+
offset: parseInt(paginationOptions.start, 10),
|
|
87
|
+
limit: parseInt(paginationOptions.length),
|
|
88
88
|
raw: true
|
|
89
89
|
});
|
|
90
90
|
return {recordsTotal, recordsFiltered, data};
|
|
@@ -59,22 +59,22 @@ export default class extends expressExtension.database.Model {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
static async paginate(
|
|
63
|
-
|
|
62
|
+
static async paginate(paginationOptions) {
|
|
63
|
+
paginationOptions = Object.assign({
|
|
64
64
|
start: 0,
|
|
65
65
|
length: 30,
|
|
66
66
|
order: null,
|
|
67
67
|
dir: 'asc',
|
|
68
68
|
search: null,
|
|
69
|
-
},
|
|
69
|
+
}, paginationOptions);
|
|
70
70
|
|
|
71
71
|
const recordsTotal = await super.count();
|
|
72
72
|
|
|
73
73
|
const whereClause = {};
|
|
74
|
-
if (
|
|
74
|
+
if (paginationOptions.search)
|
|
75
75
|
whereClause[super.Op.or] = [
|
|
76
|
-
{email: {[super.Op.like]: `%${
|
|
77
|
-
{name: {[super.Op.like]: `%${
|
|
76
|
+
{email: {[super.Op.like]: `%${paginationOptions.search}%`}},
|
|
77
|
+
{name: {[super.Op.like]: `%${paginationOptions.search}%`}}
|
|
78
78
|
];
|
|
79
79
|
|
|
80
80
|
const recordsFiltered = await super.count({where: whereClause});
|
|
@@ -82,9 +82,9 @@ export default class extends expressExtension.database.Model {
|
|
|
82
82
|
const data = await super.findAll({
|
|
83
83
|
attributes: ['id', 'name', 'email', 'icon', 'modified'],
|
|
84
84
|
where: whereClause,
|
|
85
|
-
order: [[
|
|
86
|
-
offset: parseInt(
|
|
87
|
-
limit: parseInt(
|
|
85
|
+
order: [[paginationOptions.order, paginationOptions.dir]],
|
|
86
|
+
offset: parseInt(paginationOptions.start, 10),
|
|
87
|
+
limit: parseInt(paginationOptions.length),
|
|
88
88
|
raw: true
|
|
89
89
|
});
|
|
90
90
|
return {recordsTotal, recordsFiltered, data};
|