@webtypen/webframez-core 0.2.34 → 0.2.36
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.
|
@@ -50,7 +50,7 @@ export declare class DataBuilder {
|
|
|
50
50
|
getFieldsFrontend(fields: any, payload?: any): Promise<any>;
|
|
51
51
|
getTypeFromRequest(req: any): DataBuilderType;
|
|
52
52
|
validateFields(db: any, type: any, fields: any, req: Request, errors?: any, path?: string): Promise<any>;
|
|
53
|
-
handleUnique(db: any, req: any, field: any, type: any): Promise<boolean>;
|
|
53
|
+
handleUnique(db: any, req: any, key: string, value: any, field: any, type: any): Promise<boolean>;
|
|
54
54
|
typeForFrontend(type: any, req: any): Promise<any>;
|
|
55
55
|
loadType(req: Request): Promise<{
|
|
56
56
|
status: string;
|
|
@@ -123,15 +123,15 @@ class DataBuilder {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
// Check-Unique
|
|
126
|
-
if (fields[key].unique) {
|
|
126
|
+
if (value !== null && value !== false && value !== undefined && fields[key].unique) {
|
|
127
127
|
let isUnique = false;
|
|
128
128
|
if (typeof fields[key].unique === "function") {
|
|
129
129
|
isUnique = yield fields[key].unique(req.body.data, req);
|
|
130
130
|
}
|
|
131
131
|
else if (typeof fields[key].unique === "object") {
|
|
132
|
-
isUnique = yield this.handleUnique(db, req, fields[key], type);
|
|
132
|
+
isUnique = yield this.handleUnique(db, req, key, value, fields[key], type);
|
|
133
133
|
}
|
|
134
|
-
if (isUnique) {
|
|
134
|
+
if (!isUnique) {
|
|
135
135
|
errors[fieldPath] = "Es gibt bereits einen anderen Datensatz mit diesem Wert.";
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
@@ -151,13 +151,13 @@ class DataBuilder {
|
|
|
151
151
|
return errors;
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
handleUnique(db, req, field, type) {
|
|
154
|
+
handleUnique(db, req, key, value, field, type) {
|
|
155
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
const match = typeof field.unique.match === "function"
|
|
156
|
+
const match = Object.assign({ [key]: value }, (typeof field.unique.match === "function"
|
|
157
157
|
? yield field.unique.match(req)
|
|
158
158
|
: typeof field.unique.match === "object"
|
|
159
159
|
? field.unique.match
|
|
160
|
-
: {};
|
|
160
|
+
: {}));
|
|
161
161
|
const check = yield db
|
|
162
162
|
.collection(typeof field.unique.collection === "string" && field.unique.collection.trim() !== ""
|
|
163
163
|
? field.unique.collection
|
package/package.json
CHANGED
|
@@ -168,15 +168,15 @@ export class DataBuilder {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Check-Unique
|
|
171
|
-
if (fields[key].unique) {
|
|
171
|
+
if (value !== null && value !== false && value !== undefined && fields[key].unique) {
|
|
172
172
|
let isUnique = false;
|
|
173
173
|
if (typeof fields[key].unique === "function") {
|
|
174
174
|
isUnique = await fields[key].unique(req.body.data, req);
|
|
175
175
|
} else if (typeof fields[key].unique === "object") {
|
|
176
|
-
isUnique = await this.handleUnique(db, req, fields[key], type);
|
|
176
|
+
isUnique = await this.handleUnique(db, req, key, value, fields[key], type);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
if (isUnique) {
|
|
179
|
+
if (!isUnique) {
|
|
180
180
|
errors[fieldPath] = "Es gibt bereits einen anderen Datensatz mit diesem Wert.";
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
@@ -199,13 +199,15 @@ export class DataBuilder {
|
|
|
199
199
|
return errors;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
async handleUnique(db: any, req: any, field: any, type: any) {
|
|
203
|
-
const match: any =
|
|
204
|
-
|
|
202
|
+
async handleUnique(db: any, req: any, key: string, value: any, field: any, type: any) {
|
|
203
|
+
const match: any = {
|
|
204
|
+
[key]: value,
|
|
205
|
+
...(typeof field.unique.match === "function"
|
|
205
206
|
? await field.unique.match(req)
|
|
206
207
|
: typeof field.unique.match === "object"
|
|
207
208
|
? field.unique.match
|
|
208
|
-
: {}
|
|
209
|
+
: {}),
|
|
210
|
+
};
|
|
209
211
|
const check = await db
|
|
210
212
|
.collection(
|
|
211
213
|
typeof field.unique.collection === "string" && field.unique.collection.trim() !== ""
|