express-ext 0.1.22 → 0.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/lib/GenericController.js
CHANGED
|
@@ -164,12 +164,12 @@ function getStatusCode(errs) {
|
|
|
164
164
|
}
|
|
165
165
|
exports.getStatusCode = getStatusCode;
|
|
166
166
|
function useBuild(c, generate) {
|
|
167
|
-
var b = new Builder(generate, c.id ? c.id : '', c.payload ? c.payload : '', c.user ? c.user : '', c.updatedBy ? c.updatedBy : '', c.updatedAt ? c.updatedAt : '', c.createdBy ? c.createdBy : '', c.createdAt ? c.createdAt : '');
|
|
167
|
+
var b = new Builder(generate, c.id ? c.id : '', c.payload ? c.payload : '', c.user ? c.user : '', c.updatedBy ? c.updatedBy : '', c.updatedAt ? c.updatedAt : '', c.createdBy ? c.createdBy : '', c.createdAt ? c.createdAt : '', c.version ? c.version : '');
|
|
168
168
|
return b.build;
|
|
169
169
|
}
|
|
170
170
|
exports.useBuild = useBuild;
|
|
171
171
|
var Builder = (function () {
|
|
172
|
-
function Builder(generate, id, payload, user, updatedBy, updatedAt, createdBy, createdAt) {
|
|
172
|
+
function Builder(generate, id, payload, user, updatedBy, updatedAt, createdBy, createdAt, version) {
|
|
173
173
|
this.generate = generate;
|
|
174
174
|
this.id = id;
|
|
175
175
|
this.payload = payload;
|
|
@@ -178,6 +178,7 @@ var Builder = (function () {
|
|
|
178
178
|
this.updatedAt = updatedAt;
|
|
179
179
|
this.createdBy = createdBy;
|
|
180
180
|
this.createdAt = createdAt;
|
|
181
|
+
this.version = version;
|
|
181
182
|
this.build = this.build.bind(this);
|
|
182
183
|
}
|
|
183
184
|
Builder.prototype.build = function (res, obj, isCreate, isPatch) {
|
|
@@ -210,6 +211,9 @@ var Builder = (function () {
|
|
|
210
211
|
o[this.createdBy] = usr;
|
|
211
212
|
}
|
|
212
213
|
}
|
|
214
|
+
if (this.version.length > 0) {
|
|
215
|
+
o[this.version] = 1;
|
|
216
|
+
}
|
|
213
217
|
}
|
|
214
218
|
else if (isPatch) {
|
|
215
219
|
var keys = Object.keys(o);
|
package/package.json
CHANGED
package/src/GenericController.ts
CHANGED
|
@@ -151,13 +151,14 @@ export interface ModelConfig {
|
|
|
151
151
|
updatedAt?: string;
|
|
152
152
|
createdBy?: string;
|
|
153
153
|
createdAt?: string;
|
|
154
|
+
version?: string;
|
|
154
155
|
}
|
|
155
156
|
export function useBuild<T>(c: ModelConfig, generate?: (() => string)): Build<T> {
|
|
156
|
-
const b = new Builder<T>(generate, c.id ? c.id : '', c.payload ? c.payload : '', c.user ? c.user : '', c.updatedBy ? c.updatedBy : '', c.updatedAt ? c.updatedAt : '', c.createdBy ? c.createdBy : '', c.createdAt ? c.createdAt : '');
|
|
157
|
+
const b = new Builder<T>(generate, c.id ? c.id : '', c.payload ? c.payload : '', c.user ? c.user : '', c.updatedBy ? c.updatedBy : '', c.updatedAt ? c.updatedAt : '', c.createdBy ? c.createdBy : '', c.createdAt ? c.createdAt : '', c.version ? c.version : '');
|
|
157
158
|
return b.build;
|
|
158
159
|
}
|
|
159
160
|
export class Builder<T> {
|
|
160
|
-
constructor(public generate: (() => string)|undefined, public id: string, public payload: string, public user: string, public updatedBy: string, public updatedAt: string, public createdBy: string, public createdAt: string) {
|
|
161
|
+
constructor(public generate: (() => string)|undefined, public id: string, public payload: string, public user: string, public updatedBy: string, public updatedAt: string, public createdBy: string, public createdAt: string, public version: string) {
|
|
161
162
|
this.build = this.build.bind(this);
|
|
162
163
|
}
|
|
163
164
|
build(res: Response, obj: T, isCreate?: boolean, isPatch?: boolean): void {
|
|
@@ -189,6 +190,9 @@ export class Builder<T> {
|
|
|
189
190
|
o[this.createdBy] = usr;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
193
|
+
if (this.version.length > 0) {
|
|
194
|
+
o[this.version] = 1;
|
|
195
|
+
}
|
|
192
196
|
} else if (isPatch) {
|
|
193
197
|
const keys = Object.keys(o);
|
|
194
198
|
if (keys.length === 0) {
|
package/src/LoadController.ts
CHANGED
|
@@ -8,13 +8,13 @@ export interface ViewService<T, ID> {
|
|
|
8
8
|
load(id: ID, ctx?: any): Promise<T|null>;
|
|
9
9
|
}
|
|
10
10
|
export type Load<T, ID> = ((id: ID, ctx?: any) => Promise<T|null>);
|
|
11
|
-
function getViewFunc<T, ID>(viewService: ViewService<T, ID> |
|
|
11
|
+
function getViewFunc<T, ID>(viewService: ViewService<T, ID> | Load<T, ID>): (id: ID, ctx?: any) => Promise<T|null> {
|
|
12
12
|
if (typeof viewService === 'function') {
|
|
13
13
|
return viewService;
|
|
14
14
|
}
|
|
15
15
|
return viewService.load;
|
|
16
16
|
}
|
|
17
|
-
function getKeysFunc<T, ID>(viewService: ViewService<T, ID> |
|
|
17
|
+
function getKeysFunc<T, ID>(viewService: ViewService<T, ID> | Load<T, ID>, keys?: Attributes|Attribute[]|string[]): Attribute[] | undefined {
|
|
18
18
|
if (keys) {
|
|
19
19
|
if (Array.isArray(keys)) {
|
|
20
20
|
if (keys.length > 0) {
|