c2-mongoose 2.1.21 → 2.1.23
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/dist/flow/CrudFlow.d.ts +1 -0
- package/dist/flow/CrudFlow.js +14 -0
- package/dist/flow/SearchFlow.d.ts +1 -1
- package/dist/flow/SearchFlow.js +2 -10
- package/package.json +1 -1
- package/src/flow/CrudFlow.ts +5 -0
- package/src/flow/SearchFlow.ts +2 -13
package/dist/flow/CrudFlow.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare class CrudFlow<D> {
|
|
|
10
10
|
delete(id: string, session?: any): Promise<void>;
|
|
11
11
|
deleteMany(conditions: {}, session?: any): Promise<void>;
|
|
12
12
|
update(id: string, data: D, session?: any): Promise<D>;
|
|
13
|
+
updateAny(id: string, data: any, session?: any): Promise<D>;
|
|
13
14
|
find(): Promise<SearchResponse<D>>;
|
|
14
15
|
getOne(model: D, params?: any): Promise<D>;
|
|
15
16
|
get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
|
package/dist/flow/CrudFlow.js
CHANGED
|
@@ -96,6 +96,20 @@ var CrudFlow = /** @class */ (function () {
|
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
+
CrudFlow.prototype.updateAny = function (id, data, session) {
|
|
100
|
+
if (session === void 0) { session = undefined; }
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var dataAfter;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: session })];
|
|
106
|
+
case 1:
|
|
107
|
+
dataAfter = _a.sent();
|
|
108
|
+
return [2 /*return*/, dataAfter];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
99
113
|
CrudFlow.prototype.find = function () {
|
|
100
114
|
return __awaiter(this, void 0, void 0, function () {
|
|
101
115
|
return __generator(this, function (_a) {
|
|
@@ -9,11 +9,11 @@ declare abstract class SearchFlow {
|
|
|
9
9
|
select: string;
|
|
10
10
|
populate: any;
|
|
11
11
|
filters: any;
|
|
12
|
+
pageable: boolean;
|
|
12
13
|
constructor(params: any);
|
|
13
14
|
buildPopulate(): any;
|
|
14
15
|
buildPath(target: string, nested?: string): any;
|
|
15
16
|
buildOrdenation(): any;
|
|
16
|
-
private isPageable;
|
|
17
17
|
diacriticSensitiveRegex(string?: string): string;
|
|
18
18
|
search(model: mongoose.Model<any>): Promise<SearchResponse<any>>;
|
|
19
19
|
private searchPageable;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -56,15 +56,7 @@ var Utils_1 = require("../utils/Utils");
|
|
|
56
56
|
var SearchFlow = /** @class */ (function () {
|
|
57
57
|
function SearchFlow(params) {
|
|
58
58
|
var _this = this;
|
|
59
|
-
this.
|
|
60
|
-
if ((0, Utils_1.isEmpty)(_this.page)) {
|
|
61
|
-
_this.page = 1;
|
|
62
|
-
}
|
|
63
|
-
if (_this.page >= 0) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
};
|
|
59
|
+
this.pageable = true;
|
|
68
60
|
this.searchPageable = function (model) { return __awaiter(_this, void 0, void 0, function () {
|
|
69
61
|
var sort, items;
|
|
70
62
|
return __generator(this, function (_a) {
|
|
@@ -141,7 +133,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
141
133
|
return __generator(this, function (_a) {
|
|
142
134
|
switch (_a.label) {
|
|
143
135
|
case 0:
|
|
144
|
-
if (!this.
|
|
136
|
+
if (!this.pageable) return [3 /*break*/, 2];
|
|
145
137
|
return [4 /*yield*/, this.searchPageable(model)];
|
|
146
138
|
case 1: return [2 /*return*/, _a.sent()];
|
|
147
139
|
case 2: return [4 /*yield*/, this.searchNoPageable(model)];
|
package/package.json
CHANGED
package/src/flow/CrudFlow.ts
CHANGED
|
@@ -34,6 +34,11 @@ class CrudFlow<D> {
|
|
|
34
34
|
return dataAfter as D
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
public async updateAny(id: string, data: any, session: any = undefined): Promise<D> {
|
|
38
|
+
const dataAfter = await this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session })
|
|
39
|
+
return dataAfter as D
|
|
40
|
+
}
|
|
41
|
+
|
|
37
42
|
public async find(): Promise<SearchResponse<D>> {
|
|
38
43
|
return await this.search.search(this.repository)
|
|
39
44
|
}
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -13,6 +13,7 @@ abstract class SearchFlow {
|
|
|
13
13
|
select: string
|
|
14
14
|
populate: any
|
|
15
15
|
filters: any
|
|
16
|
+
pageable: boolean = true
|
|
16
17
|
|
|
17
18
|
constructor(params: any) {
|
|
18
19
|
this.searchText = params.searchText || ""
|
|
@@ -59,18 +60,6 @@ abstract class SearchFlow {
|
|
|
59
60
|
return order
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
private isPageable = () => {
|
|
63
|
-
if (isEmpty(this.page)) {
|
|
64
|
-
this.page = 1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (this.page >= 0) {
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
63
|
public diacriticSensitiveRegex(string: string = ""): string {
|
|
75
64
|
return string
|
|
76
65
|
.replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
|
|
@@ -82,7 +71,7 @@ abstract class SearchFlow {
|
|
|
82
71
|
}
|
|
83
72
|
|
|
84
73
|
public async search(model: mongoose.Model<any>): Promise<SearchResponse<any>> {
|
|
85
|
-
if (this.
|
|
74
|
+
if (this.pageable) {
|
|
86
75
|
return await this.searchPageable(model)
|
|
87
76
|
}
|
|
88
77
|
|