@jd-data-limited/easy-fm 0.0.11 → 0.0.12
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/index.js +10 -7
- package/index.ts +12 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -147,11 +147,12 @@ class layout {
|
|
|
147
147
|
createRecord() {
|
|
148
148
|
return new Promise((resolve, reject) => {
|
|
149
149
|
// Get the layout's metadata
|
|
150
|
-
this.
|
|
150
|
+
this.getLayoutMeta().then(layout => {
|
|
151
151
|
let fields = {};
|
|
152
|
-
for (let _field of
|
|
152
|
+
for (let _field of this.metadata.fieldMetaData) {
|
|
153
153
|
fields[_field.name] = "";
|
|
154
154
|
}
|
|
155
|
+
console.log(fields);
|
|
155
156
|
resolve(new record(this, -1, 0, fields));
|
|
156
157
|
});
|
|
157
158
|
});
|
|
@@ -262,19 +263,20 @@ class record extends EventEmitter {
|
|
|
262
263
|
});
|
|
263
264
|
}));
|
|
264
265
|
}
|
|
265
|
-
commit(extraBody = {
|
|
266
|
+
commit(extraBody = {
|
|
267
|
+
fieldData: undefined
|
|
268
|
+
}) {
|
|
266
269
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
267
270
|
let data = this.toObject();
|
|
268
271
|
delete data.recordId;
|
|
269
272
|
delete data.modId;
|
|
270
273
|
if (this.recordId === -1) {
|
|
271
274
|
// This is a new record
|
|
275
|
+
extraBody.fieldData = data.fieldData;
|
|
272
276
|
this.layout.conn.apiRequest(`${this.layout.endpoint}/records`, {
|
|
273
277
|
port: 443,
|
|
274
278
|
method: "POST",
|
|
275
|
-
body: JSON.stringify(
|
|
276
|
-
fieldData: data.fieldData
|
|
277
|
-
})
|
|
279
|
+
body: JSON.stringify(extraBody)
|
|
278
280
|
})
|
|
279
281
|
.then(res => {
|
|
280
282
|
if (res.messages[0].code === "0") {
|
|
@@ -416,7 +418,7 @@ class portalItem extends record {
|
|
|
416
418
|
attachPortal(portal) {
|
|
417
419
|
this.portal = portal;
|
|
418
420
|
}
|
|
419
|
-
commit(extraBody = {}) {
|
|
421
|
+
commit(extraBody = { fieldData: undefined }) {
|
|
420
422
|
return this.portal.record.commit(extraBody);
|
|
421
423
|
}
|
|
422
424
|
toObject(fieldFilter) {
|
|
@@ -498,6 +500,7 @@ export class FMError extends Error {
|
|
|
498
500
|
super(errs.find(err => err.e === code).d || "Unknown error");
|
|
499
501
|
this.httpStatus = httpStatus;
|
|
500
502
|
this.res = res;
|
|
503
|
+
this.messages = res.messages;
|
|
501
504
|
this.code = typeof code === "string" ? parseInt(code) : code;
|
|
502
505
|
Error.captureStackTrace(this, FMError);
|
|
503
506
|
}
|
package/index.ts
CHANGED
|
@@ -181,11 +181,12 @@ class layout {
|
|
|
181
181
|
createRecord(): Promise<record | Error | void> {
|
|
182
182
|
return new Promise((resolve, reject) => {
|
|
183
183
|
// Get the layout's metadata
|
|
184
|
-
this.
|
|
184
|
+
this.getLayoutMeta().then(layout => {
|
|
185
185
|
let fields = {}
|
|
186
|
-
for (let _field of
|
|
186
|
+
for (let _field of this.metadata.fieldMetaData) {
|
|
187
187
|
fields[_field.name] = ""
|
|
188
188
|
}
|
|
189
|
+
console.log(fields)
|
|
189
190
|
resolve(new record(this, -1, 0, fields))
|
|
190
191
|
})
|
|
191
192
|
})
|
|
@@ -307,7 +308,9 @@ class record extends EventEmitter {
|
|
|
307
308
|
})
|
|
308
309
|
}
|
|
309
310
|
|
|
310
|
-
commit(extraBody = {
|
|
311
|
+
commit(extraBody = {
|
|
312
|
+
fieldData: undefined
|
|
313
|
+
}): Promise<record | FMError> {
|
|
311
314
|
return new Promise(async (resolve, reject) => {
|
|
312
315
|
let data = this.toObject()
|
|
313
316
|
delete data.recordId
|
|
@@ -315,12 +318,12 @@ class record extends EventEmitter {
|
|
|
315
318
|
|
|
316
319
|
if (this.recordId === -1) {
|
|
317
320
|
// This is a new record
|
|
321
|
+
extraBody.fieldData = data.fieldData
|
|
322
|
+
|
|
318
323
|
this.layout.conn.apiRequest(`${this.layout.endpoint}/records`, {
|
|
319
324
|
port: 443,
|
|
320
325
|
method: "POST",
|
|
321
|
-
body: JSON.stringify(
|
|
322
|
-
fieldData: data.fieldData
|
|
323
|
-
})
|
|
326
|
+
body: JSON.stringify(extraBody)
|
|
324
327
|
})
|
|
325
328
|
.then(res => {
|
|
326
329
|
if (res.messages[0].code === "0") {
|
|
@@ -482,7 +485,7 @@ class portalItem extends record {
|
|
|
482
485
|
this.portal = portal
|
|
483
486
|
}
|
|
484
487
|
|
|
485
|
-
commit(extraBody = {}) {
|
|
488
|
+
commit(extraBody = {fieldData: undefined}) {
|
|
486
489
|
return this.portal.record.commit(extraBody)
|
|
487
490
|
}
|
|
488
491
|
|
|
@@ -570,12 +573,14 @@ export class FMError extends Error {
|
|
|
570
573
|
readonly res: any
|
|
571
574
|
readonly code: number
|
|
572
575
|
readonly message: string
|
|
576
|
+
readonly messages: string
|
|
573
577
|
|
|
574
578
|
constructor(code, httpStatus, res) {
|
|
575
579
|
if (typeof code === "string") code = parseInt(code)
|
|
576
580
|
super(errs.find(err => err.e === code).d || "Unknown error");
|
|
577
581
|
this.httpStatus = httpStatus
|
|
578
582
|
this.res = res
|
|
583
|
+
this.messages = res.messages
|
|
579
584
|
this.code = typeof code === "string" ? parseInt(code) : code
|
|
580
585
|
Error.captureStackTrace(this, FMError)
|
|
581
586
|
}
|