c2-mongoose 2.0.7 → 2.1.1
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 +6 -3
- package/dist/flow/CrudFlow.js +11 -30
- package/dist/flow/SearchFlow.d.ts +1 -0
- package/dist/flow/SearchFlow.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/flow/CrudFlow.ts +12 -6
- package/src/flow/SearchFlow.ts +4 -2
- package/src/index.ts +2 -1
- package/src/types/SearchResponse.d.ts +3 -3
package/dist/flow/CrudFlow.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
+
import { SearchResponse } from "../types/SearchResponse";
|
|
2
3
|
import SearchFlow from "./SearchFlow";
|
|
3
|
-
declare class CrudFlow<D>
|
|
4
|
+
declare class CrudFlow<D> {
|
|
4
5
|
private repository;
|
|
5
|
-
|
|
6
|
+
private search;
|
|
7
|
+
constructor(repository: mongoose.Model<any>, search?: SearchFlow);
|
|
8
|
+
prepareSearch(search: SearchFlow): void;
|
|
6
9
|
create(data: any, session?: any): Promise<any[]>;
|
|
7
10
|
delete(id: string, session?: any): Promise<void>;
|
|
8
11
|
update(id: string, data: D, session?: any): Promise<D>;
|
|
9
|
-
find(
|
|
12
|
+
find(): Promise<SearchResponse<D>>;
|
|
10
13
|
getOne(model: D, params?: any): Promise<D>;
|
|
11
14
|
get(id: string, pop?: string, sel?: string): Promise<D>;
|
|
12
15
|
}
|
package/dist/flow/CrudFlow.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,19 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
36
|
}
|
|
52
37
|
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (model === void 0) { model = {}; }
|
|
62
|
-
var _this = _super.call(this, model) || this;
|
|
63
|
-
_this.repository = repository;
|
|
64
|
-
return _this;
|
|
39
|
+
var CrudFlow = /** @class */ (function () {
|
|
40
|
+
function CrudFlow(repository, search) {
|
|
41
|
+
this.repository = repository;
|
|
42
|
+
this.search = search;
|
|
65
43
|
}
|
|
44
|
+
CrudFlow.prototype.prepareSearch = function (search) {
|
|
45
|
+
this.search = search;
|
|
46
|
+
};
|
|
66
47
|
CrudFlow.prototype.create = function (data, session) {
|
|
67
48
|
if (session === void 0) { session = undefined; }
|
|
68
49
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -101,11 +82,11 @@ var CrudFlow = /** @class */ (function (_super) {
|
|
|
101
82
|
});
|
|
102
83
|
});
|
|
103
84
|
};
|
|
104
|
-
CrudFlow.prototype.find = function (
|
|
85
|
+
CrudFlow.prototype.find = function () {
|
|
105
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
106
87
|
return __generator(this, function (_a) {
|
|
107
88
|
switch (_a.label) {
|
|
108
|
-
case 0: return [4 /*yield*/, search.search(this.repository)];
|
|
89
|
+
case 0: return [4 /*yield*/, this.search.search(this.repository)];
|
|
109
90
|
case 1: return [2 /*return*/, _a.sent()];
|
|
110
91
|
}
|
|
111
92
|
});
|
|
@@ -117,7 +98,7 @@ var CrudFlow = /** @class */ (function (_super) {
|
|
|
117
98
|
var data;
|
|
118
99
|
return __generator(this, function (_a) {
|
|
119
100
|
switch (_a.label) {
|
|
120
|
-
case 0: return [4 /*yield*/,
|
|
101
|
+
case 0: return [4 /*yield*/, this.search.findOne(this.repository, model, params)];
|
|
121
102
|
case 1:
|
|
122
103
|
data = _a.sent();
|
|
123
104
|
return [2 /*return*/, data];
|
|
@@ -141,5 +122,5 @@ var CrudFlow = /** @class */ (function (_super) {
|
|
|
141
122
|
});
|
|
142
123
|
};
|
|
143
124
|
return CrudFlow;
|
|
144
|
-
}(
|
|
125
|
+
}());
|
|
145
126
|
exports.default = CrudFlow;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -181,7 +181,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
181
181
|
paging.limit = this.limit;
|
|
182
182
|
searchResponse = {};
|
|
183
183
|
searchResponse.items = items;
|
|
184
|
-
searchResponse.
|
|
184
|
+
searchResponse.pagination = paging;
|
|
185
185
|
return [2 /*return*/, searchResponse];
|
|
186
186
|
}
|
|
187
187
|
});
|
|
@@ -256,6 +256,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
256
256
|
filters.$and.push(condition);
|
|
257
257
|
}
|
|
258
258
|
else if (key.endsWith('Like')) {
|
|
259
|
+
console.log(key);
|
|
259
260
|
var keyAux = key.replace('Like', '');
|
|
260
261
|
condition[keyAux] = { $regex: value, $options: 'i' };
|
|
261
262
|
filters.$and.push(condition);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.SearchFlow = exports.CrudFlow = void 0;
|
|
7
7
|
var CrudFlow_1 = __importDefault(require("./flow/CrudFlow"));
|
|
8
8
|
exports.CrudFlow = CrudFlow_1.default;
|
|
9
9
|
var SearchFlow_1 = __importDefault(require("./flow/SearchFlow"));
|
package/package.json
CHANGED
package/src/flow/CrudFlow.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import mongoose from "mongoose"
|
|
2
|
+
import { SearchResponse } from "../types/SearchResponse"
|
|
2
3
|
import SearchFlow from "./SearchFlow"
|
|
3
4
|
|
|
4
|
-
class CrudFlow<D>
|
|
5
|
+
class CrudFlow<D> {
|
|
5
6
|
|
|
6
7
|
private repository: mongoose.Model<any>
|
|
8
|
+
private search: any
|
|
7
9
|
|
|
8
|
-
constructor(repository: mongoose.Model<any>,
|
|
9
|
-
super(model as D)
|
|
10
|
+
constructor(repository: mongoose.Model<any>, search?: SearchFlow) {
|
|
10
11
|
this.repository = repository
|
|
12
|
+
this.search = search
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public prepareSearch(search: SearchFlow) {
|
|
16
|
+
this.search = search
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
public async create(data: any, session: any = undefined) {
|
|
@@ -23,12 +29,12 @@ class CrudFlow<D> extends SearchFlow {
|
|
|
23
29
|
return dataAfter as D
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
public async find(
|
|
27
|
-
return await search.search(this.repository)
|
|
32
|
+
public async find(): Promise<SearchResponse<D>> {
|
|
33
|
+
return await this.search.search(this.repository)
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
public async getOne(model: D, params: any = {}): Promise<D> {
|
|
31
|
-
const data = await
|
|
37
|
+
const data = await this.search.findOne(this.repository, model, params)
|
|
32
38
|
return data as D
|
|
33
39
|
}
|
|
34
40
|
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import mongoose from "mongoose"
|
|
2
2
|
import { dbCollation } from "../configuration/Environment"
|
|
3
|
+
import { Pagination, SearchResponse } from "../types/SearchResponse"
|
|
3
4
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
4
5
|
|
|
5
6
|
abstract class SearchFlow {
|
|
@@ -117,14 +118,14 @@ abstract class SearchFlow {
|
|
|
117
118
|
private async result(model: mongoose.Model<any>, items: []): Promise<SearchResponse<any>> {
|
|
118
119
|
var total = await this.count(model)
|
|
119
120
|
|
|
120
|
-
var paging:
|
|
121
|
+
var paging: Pagination = {}
|
|
121
122
|
paging.total = total
|
|
122
123
|
paging.page = this.page
|
|
123
124
|
paging.limit = this.limit
|
|
124
125
|
|
|
125
126
|
var searchResponse: SearchResponse<any> = {}
|
|
126
127
|
searchResponse.items = items
|
|
127
|
-
searchResponse.
|
|
128
|
+
searchResponse.pagination = paging
|
|
128
129
|
|
|
129
130
|
return searchResponse
|
|
130
131
|
}
|
|
@@ -185,6 +186,7 @@ abstract class SearchFlow {
|
|
|
185
186
|
}
|
|
186
187
|
filters.$and.push(condition)
|
|
187
188
|
} else if (key.endsWith('Like')) {
|
|
189
|
+
console.log(key)
|
|
188
190
|
var keyAux = key.replace('Like', '')
|
|
189
191
|
condition[keyAux] = {$regex: value as any, $options: 'i'}
|
|
190
192
|
filters.$and.push(condition)
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare interface SearchResponse<T> {
|
|
2
|
-
|
|
1
|
+
export declare interface SearchResponse<T> {
|
|
2
|
+
pagination?: Pagination,
|
|
3
3
|
items?: T[]
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
declare interface
|
|
6
|
+
export declare interface Pagination {
|
|
7
7
|
total?: number,
|
|
8
8
|
page?: number,
|
|
9
9
|
limit?: number
|