express-ext 0.2.1 → 0.2.2
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/edit.js +8 -2
- package/package.json +1 -1
- package/src/GenericController.ts +2 -2
- package/src/LowCodeController.ts +1 -1
- package/src/edit.ts +8 -4
package/lib/edit.js
CHANGED
|
@@ -43,9 +43,12 @@ function create(res, obj, insert, log, returnNumber) {
|
|
|
43
43
|
res.status(409).json(result).end();
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
else {
|
|
46
|
+
else if (Array.isArray(result)) {
|
|
47
47
|
res.status(422).json(result).end();
|
|
48
48
|
}
|
|
49
|
+
else {
|
|
50
|
+
res.status(201).json(result).end();
|
|
51
|
+
}
|
|
49
52
|
}).catch(function (err) { return http_1.handleError(err, res, log); });
|
|
50
53
|
}
|
|
51
54
|
exports.create = create;
|
|
@@ -62,9 +65,12 @@ function update(res, obj, save, log, returnNumber) {
|
|
|
62
65
|
res.status(409).json(result).end();
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
|
-
else {
|
|
68
|
+
else if (Array.isArray(result)) {
|
|
66
69
|
res.status(422).json(result).end();
|
|
67
70
|
}
|
|
71
|
+
else {
|
|
72
|
+
res.status(200).json(result).end();
|
|
73
|
+
}
|
|
68
74
|
}).catch(function (err) { return http_1.handleError(err, res, log); });
|
|
69
75
|
}
|
|
70
76
|
exports.update = update;
|
package/package.json
CHANGED
package/src/GenericController.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {buildAndCheckId, buildId} from './view';
|
|
|
8
8
|
|
|
9
9
|
export type Build<T> = (res: Response, obj: T, isCreate?: boolean, isPatch?: boolean) => void;
|
|
10
10
|
export type Validate<T> = (obj: T, patch?: boolean) => Promise<ErrorMessage[]>;
|
|
11
|
-
export type Save<T> = (obj: T, ctx?: any) => Promise<number|ErrorMessage[]>;
|
|
11
|
+
export type Save<T> = (obj: T, ctx?: any) => Promise<number|T|ErrorMessage[]>;
|
|
12
12
|
export interface GenericService<T, ID, R> {
|
|
13
13
|
metadata?(): Attributes|undefined;
|
|
14
14
|
load(id: ID, ctx?: any): Promise<T|null>;
|
|
@@ -20,7 +20,7 @@ export interface GenericService<T, ID, R> {
|
|
|
20
20
|
export class GenericController<T, ID> extends LoadController<T, ID> {
|
|
21
21
|
metadata?: Attributes;
|
|
22
22
|
returnNumber?: boolean;
|
|
23
|
-
constructor(log: Log, public service: GenericService<T, ID, number|ErrorMessage[]>, public build?: Build<T>, public validate?: Validate<T>, returnNumber?: boolean) {
|
|
23
|
+
constructor(log: Log, public service: GenericService<T, ID, number|T|ErrorMessage[]>, public build?: Build<T>, public validate?: Validate<T>, returnNumber?: boolean) {
|
|
24
24
|
super(log, service);
|
|
25
25
|
this.returnNumber = returnNumber;
|
|
26
26
|
if (service.metadata) {
|
package/src/LowCodeController.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
|
|
|
52
52
|
fields?: string;
|
|
53
53
|
excluding?: string;
|
|
54
54
|
array?: string[];
|
|
55
|
-
constructor(log: Log, public lowCodeService: Service<T, ID, number|ErrorMessage[], S>, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, config?: SearchConfig, dates?: string[], numbers?: string[]) {
|
|
55
|
+
constructor(log: Log, public lowCodeService: Service<T, ID, number|T|ErrorMessage[], S>, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, config?: SearchConfig, dates?: string[], numbers?: string[]) {
|
|
56
56
|
super(log, lowCodeService, build, validate);
|
|
57
57
|
this.search = this.search.bind(this);
|
|
58
58
|
this.config = initializeConfig(config);
|
package/src/edit.ts
CHANGED
|
@@ -62,7 +62,7 @@ export function checkId<T, ID>(obj: T, id: ID, keys?: Attribute[]): boolean {
|
|
|
62
62
|
}
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
|
-
export function create<T>(res: Response, obj: T, insert: (obj: T, ctx?: any) => Promise<number|ErrorMessage[]>, log: (msg: string, ctx?: any) => void, returnNumber?: boolean): void {
|
|
65
|
+
export function create<T>(res: Response, obj: T, insert: (obj: T, ctx?: any) => Promise<number|T|ErrorMessage[]>, log: (msg: string, ctx?: any) => void, returnNumber?: boolean): void {
|
|
66
66
|
insert(obj).then(result => {
|
|
67
67
|
if (typeof result === 'number') {
|
|
68
68
|
if (result >= 1) {
|
|
@@ -70,12 +70,14 @@ export function create<T>(res: Response, obj: T, insert: (obj: T, ctx?: any) =>
|
|
|
70
70
|
} else {
|
|
71
71
|
res.status(409).json(result).end();
|
|
72
72
|
}
|
|
73
|
-
} else {
|
|
73
|
+
} else if (Array.isArray(result)) {
|
|
74
74
|
res.status(422).json(result).end();
|
|
75
|
+
} else {
|
|
76
|
+
res.status(201).json(result).end();
|
|
75
77
|
}
|
|
76
78
|
}).catch(err => handleError(err, res, log));
|
|
77
79
|
}
|
|
78
|
-
export function update<T>(res: Response, obj: T, save: (obj: T, ctx?: any) => Promise<number|ErrorMessage[]>, log: (msg: string, ctx?: any) => void, returnNumber?: boolean): void {
|
|
80
|
+
export function update<T>(res: Response, obj: T, save: (obj: T, ctx?: any) => Promise<number|T|ErrorMessage[]>, log: (msg: string, ctx?: any) => void, returnNumber?: boolean): void {
|
|
79
81
|
save(obj).then(result => {
|
|
80
82
|
if (typeof result === 'number') {
|
|
81
83
|
if (result >= 1) {
|
|
@@ -85,8 +87,10 @@ export function update<T>(res: Response, obj: T, save: (obj: T, ctx?: any) => Pr
|
|
|
85
87
|
} else {
|
|
86
88
|
res.status(409).json(result).end();
|
|
87
89
|
}
|
|
88
|
-
} else {
|
|
90
|
+
} else if (Array.isArray(result)) {
|
|
89
91
|
res.status(422).json(result).end();
|
|
92
|
+
} else {
|
|
93
|
+
res.status(200).json(result).end();
|
|
90
94
|
}
|
|
91
95
|
}).catch(err => handleError(err, res, log));
|
|
92
96
|
}
|