erpnext-queue-client 2.4.3 → 2.4.4

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.
Files changed (39) hide show
  1. package/dist/client.js +87 -105
  2. package/dist/constants.js +1 -0
  3. package/dist/dataConverter.js +4 -13
  4. package/dist/erpnext/decryptFromErpNext.server.js +1 -1
  5. package/dist/erpnext/decryptFromErpNext.server.test.js +2 -11
  6. package/dist/erpnext/doctypeResourceRequest.js +44 -37
  7. package/dist/erpnext/doctypeSubmittableResourceRequest.js +19 -33
  8. package/dist/erpnext/doctypes/address.js +40 -41
  9. package/dist/erpnext/doctypes/consolidatedCustomsInvoice.js +18 -20
  10. package/dist/erpnext/doctypes/contact.js +30 -30
  11. package/dist/erpnext/doctypes/deliveryNote.js +13 -12
  12. package/dist/erpnext/doctypes/item.d.ts +10 -10
  13. package/dist/erpnext/doctypes/item.js +64 -63
  14. package/dist/erpnext/doctypes/paymentEntry.js +42 -43
  15. package/dist/erpnext/doctypes/productBundle.js +15 -17
  16. package/dist/erpnext/doctypes/purchaseInvoice.js +45 -49
  17. package/dist/erpnext/doctypes/purchaseReceipt.js +41 -43
  18. package/dist/erpnext/doctypes/salesInvoice.js +42 -43
  19. package/dist/erpnext/doctypes/servicecase.js +103 -114
  20. package/dist/erpnext/doctypes/shipment.js +30 -35
  21. package/dist/erpnext/doctypes/stock.js +94 -109
  22. package/dist/erpnext/doctypes/tags.js +58 -77
  23. package/dist/erpnext/erpnextRequestWrapper.js +83 -80
  24. package/dist/erpnext/fileRequests.js +28 -29
  25. package/dist/erpnext/methodRequest.js +37 -43
  26. package/dist/erpnext/model/DocTypeHelpers.js +2 -3
  27. package/dist/erpnext/model/Item.d.ts +6 -6
  28. package/dist/erpnext/model/Item.js +1 -1
  29. package/dist/erpnext/model/StockEntry.d.ts +63 -21
  30. package/dist/erpnext/model/StockEntry.js +22 -21
  31. package/dist/erpnext/reports.js +81 -89
  32. package/dist/erpnext/resourceRequest.js +142 -150
  33. package/dist/index.js +43 -3
  34. package/dist/index.test.js +69 -83
  35. package/dist/utils/fernet.server.js +24 -4
  36. package/dist/utils/request.js +59 -72
  37. package/dist/utils/zodContextOptionals.js +5 -3
  38. package/dist/utils/zodUtils.js +2 -2
  39. package/package.json +1 -1
@@ -1,28 +1,18 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextProductBundle = void 0;
13
4
  const doctypeResourceRequest_1 = require("../doctypeResourceRequest");
14
5
  const methodRequest_1 = require("../methodRequest");
15
6
  const ProductBundle_1 = require("../model/ProductBundle");
16
7
  class ERPNextProductBundle {
8
+ temporalClient;
9
+ baseRequest;
10
+ getList;
11
+ getById;
12
+ updateById;
13
+ deleteById;
14
+ methodRequest;
17
15
  constructor(temporalClient) {
18
- this.getBundleInfos = (...args_1) => __awaiter(this, [...args_1], void 0, function* (priority = 5) {
19
- return yield this.methodRequest.request({
20
- methodName: "get_bundle_infos",
21
- requestMethod: "GET",
22
- responseValidationModel: ProductBundle_1.GetBundleInfosResponse,
23
- priority,
24
- });
25
- });
26
16
  this.temporalClient = temporalClient;
27
17
  this.baseRequest = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(temporalClient, "ProductBundle", ProductBundle_1.ProductBundle);
28
18
  this.methodRequest = new methodRequest_1.ERPNextMethodRequest(temporalClient);
@@ -31,5 +21,13 @@ class ERPNextProductBundle {
31
21
  this.updateById = this.baseRequest.updateById;
32
22
  this.deleteById = this.baseRequest.deleteById;
33
23
  }
24
+ getBundleInfos = async (priority = 5) => {
25
+ return await this.methodRequest.request({
26
+ methodName: "get_bundle_infos",
27
+ requestMethod: "GET",
28
+ responseValidationModel: ProductBundle_1.GetBundleInfosResponse,
29
+ priority,
30
+ });
31
+ };
34
32
  }
35
33
  exports.ERPNextProductBundle = ERPNextProductBundle;
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextPurchaseInvoice = void 0;
13
4
  const doctypeSubmittableResourceRequest_1 = require("../doctypeSubmittableResourceRequest");
14
5
  const methodRequest_1 = require("../methodRequest");
15
6
  const PurchaseInvoice_1 = require("../model/PurchaseInvoice");
16
7
  class ERPNextPurchaseInvoice {
8
+ temporalClient;
9
+ baseRequest;
10
+ methodRequest;
11
+ getList;
12
+ getById;
13
+ updateById;
14
+ deleteById;
15
+ cancel;
16
+ submit;
17
17
  constructor(temporalClient) {
18
18
  this.temporalClient = temporalClient;
19
19
  this.baseRequest = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(temporalClient, "Purchase Invoice", PurchaseInvoice_1.PurchaseInvoice);
@@ -25,54 +25,50 @@ class ERPNextPurchaseInvoice {
25
25
  this.cancel = this.baseRequest.cancel;
26
26
  this.submit = this.baseRequest.submit;
27
27
  }
28
- getByBillNo(billNo) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const draft = yield this.getList({
31
- filters: [["bill_no", "=", billNo]],
32
- });
33
- return draft;
28
+ async getByBillNo(billNo) {
29
+ const draft = await this.getList({
30
+ filters: [["bill_no", "=", billNo]],
34
31
  });
32
+ return draft;
35
33
  }
36
- createInvoiceDraftFromPurchaseOrder(purchaseOrderName) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const draft = yield this.methodRequest.request({
39
- methodName: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
40
- requestMethod: "POST",
41
- responseValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
42
- params: { source_name: purchaseOrderName },
43
- });
44
- return draft;
34
+ async createInvoiceDraftFromPurchaseOrder(purchaseOrderName) {
35
+ const draft = await this.methodRequest.request({
36
+ methodName: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
37
+ requestMethod: "POST",
38
+ responseValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
39
+ params: { source_name: purchaseOrderName },
45
40
  });
41
+ return draft;
46
42
  }
47
- createFromPurchaseOrder(purchaseOrderName_1) {
48
- return __awaiter(this, arguments, void 0, function* (purchaseOrderName, submit = false) {
49
- const receiptDraft = yield this.createInvoiceDraftFromPurchaseOrder(purchaseOrderName);
50
- const body = Object.assign(Object.assign({}, receiptDraft), (submit === true ? { docstatus: 1 } : {}));
51
- return yield this.baseRequest.create({
52
- inputValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
53
- body,
54
- });
43
+ async createFromPurchaseOrder(purchaseOrderName, submit = false) {
44
+ const receiptDraft = await this.createInvoiceDraftFromPurchaseOrder(purchaseOrderName);
45
+ const body = {
46
+ ...receiptDraft,
47
+ ...(submit === true ? { docstatus: 1 } : {}),
48
+ };
49
+ return await this.baseRequest.create({
50
+ inputValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
51
+ body,
55
52
  });
56
53
  }
57
- createInvoiceDraftFromPurchaseReceipt(purchaseReceiptName) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const draft = yield this.methodRequest.request({
60
- methodName: `erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice`,
61
- requestMethod: "POST",
62
- responseValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
63
- params: { source_name: purchaseReceiptName },
64
- });
65
- return draft;
54
+ async createInvoiceDraftFromPurchaseReceipt(purchaseReceiptName) {
55
+ const draft = await this.methodRequest.request({
56
+ methodName: `erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice`,
57
+ requestMethod: "POST",
58
+ responseValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
59
+ params: { source_name: purchaseReceiptName },
66
60
  });
61
+ return draft;
67
62
  }
68
- createFromPurchaseInvoice(purchaseInvoiceName_1) {
69
- return __awaiter(this, arguments, void 0, function* (purchaseInvoiceName, submit = false) {
70
- const receiptDraft = yield this.createInvoiceDraftFromPurchaseReceipt(purchaseInvoiceName);
71
- const body = Object.assign(Object.assign({}, receiptDraft), (submit === true ? { docstatus: 1 } : {}));
72
- return yield this.baseRequest.create({
73
- inputValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
74
- body,
75
- });
63
+ async createFromPurchaseInvoice(purchaseInvoiceName, submit = false) {
64
+ const receiptDraft = await this.createInvoiceDraftFromPurchaseReceipt(purchaseInvoiceName);
65
+ const body = {
66
+ ...receiptDraft,
67
+ ...(submit === true ? { docstatus: 1 } : {}),
68
+ };
69
+ return await this.baseRequest.create({
70
+ inputValidationModel: PurchaseInvoice_1.PurchaseInvoiceDraft,
71
+ body,
76
72
  });
77
73
  }
78
74
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextPurchaseReceipt = void 0;
13
4
  const doctypeSubmittableResourceRequest_1 = require("../doctypeSubmittableResourceRequest");
@@ -15,6 +6,15 @@ const methodRequest_1 = require("../methodRequest");
15
6
  const Receipt_1 = require("../model/Receipt");
16
7
  const ReceiptDraft_1 = require("../model/ReceiptDraft");
17
8
  class ERPNextPurchaseReceipt {
9
+ temporalClient;
10
+ baseRequest;
11
+ methodRequest;
12
+ getList;
13
+ getById;
14
+ updateById;
15
+ deleteById;
16
+ cancel;
17
+ submit;
18
18
  constructor(temporalClient) {
19
19
  this.temporalClient = temporalClient;
20
20
  this.baseRequest = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(temporalClient, "Purchase Receipt", Receipt_1.PurchaseReceipt);
@@ -26,46 +26,44 @@ class ERPNextPurchaseReceipt {
26
26
  this.cancel = this.baseRequest.cancel;
27
27
  this.submit = this.baseRequest.submit;
28
28
  }
29
- createReceiptDraftFromPurchaseOrder(purchaseOrderName) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const draft = yield this.methodRequest.request({
32
- methodName: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
33
- requestMethod: "POST",
34
- responseValidationModel: ReceiptDraft_1.ReceiptDraft,
35
- params: { source_name: purchaseOrderName },
36
- });
37
- return draft;
29
+ async createReceiptDraftFromPurchaseOrder(purchaseOrderName) {
30
+ const draft = await this.methodRequest.request({
31
+ methodName: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
32
+ requestMethod: "POST",
33
+ responseValidationModel: ReceiptDraft_1.ReceiptDraft,
34
+ params: { source_name: purchaseOrderName },
38
35
  });
36
+ return draft;
39
37
  }
40
- createFromPurchaseOrder(purchaseOrderName_1) {
41
- return __awaiter(this, arguments, void 0, function* (purchaseOrderName, submit = false) {
42
- const receiptDraft = yield this.createReceiptDraftFromPurchaseOrder(purchaseOrderName);
43
- const body = Object.assign(Object.assign({}, receiptDraft), (submit === true ? { docstatus: 1 } : {}));
44
- return yield this.baseRequest.create({
45
- inputValidationModel: ReceiptDraft_1.ReceiptDraft,
46
- body,
47
- });
38
+ async createFromPurchaseOrder(purchaseOrderName, submit = false) {
39
+ const receiptDraft = await this.createReceiptDraftFromPurchaseOrder(purchaseOrderName);
40
+ const body = {
41
+ ...receiptDraft,
42
+ ...(submit === true ? { docstatus: 1 } : {}),
43
+ };
44
+ return await this.baseRequest.create({
45
+ inputValidationModel: ReceiptDraft_1.ReceiptDraft,
46
+ body,
48
47
  });
49
48
  }
50
- createReceiptDraftFromPurchaseInvoice(purchaseInvoiceName) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const draft = yield this.methodRequest.request({
53
- methodName: `erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_purchase_receipt`,
54
- requestMethod: "POST",
55
- responseValidationModel: ReceiptDraft_1.ReceiptDraft,
56
- params: { source_name: purchaseInvoiceName },
57
- });
58
- return draft;
49
+ async createReceiptDraftFromPurchaseInvoice(purchaseInvoiceName) {
50
+ const draft = await this.methodRequest.request({
51
+ methodName: `erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_purchase_receipt`,
52
+ requestMethod: "POST",
53
+ responseValidationModel: ReceiptDraft_1.ReceiptDraft,
54
+ params: { source_name: purchaseInvoiceName },
59
55
  });
56
+ return draft;
60
57
  }
61
- createFromPurchaseInvoice(purchaseInvoiceName_1) {
62
- return __awaiter(this, arguments, void 0, function* (purchaseInvoiceName, submit = false) {
63
- const receiptDraft = yield this.createReceiptDraftFromPurchaseInvoice(purchaseInvoiceName);
64
- const body = Object.assign(Object.assign({}, receiptDraft), (submit === true ? { docstatus: 1 } : {}));
65
- return yield this.baseRequest.create({
66
- inputValidationModel: ReceiptDraft_1.ReceiptDraft,
67
- body,
68
- });
58
+ async createFromPurchaseInvoice(purchaseInvoiceName, submit = false) {
59
+ const receiptDraft = await this.createReceiptDraftFromPurchaseInvoice(purchaseInvoiceName);
60
+ const body = {
61
+ ...receiptDraft,
62
+ ...(submit === true ? { docstatus: 1 } : {}),
63
+ };
64
+ return await this.baseRequest.create({
65
+ inputValidationModel: ReceiptDraft_1.ReceiptDraft,
66
+ body,
69
67
  });
70
68
  }
71
69
  }
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextSalesInvoice = void 0;
13
4
  const doctypeSubmittableResourceRequest_1 = require("../doctypeSubmittableResourceRequest");
14
5
  const methodRequest_1 = require("../methodRequest");
15
6
  const SalesInvoice_1 = require("../model/SalesInvoice");
16
7
  class ERPNextSalesInvoice {
8
+ temporalClient;
9
+ baseRequest;
10
+ methodRequest;
11
+ getList;
12
+ getById;
13
+ create;
14
+ updateById;
15
+ deleteById;
16
+ cancel;
17
+ submit;
17
18
  constructor(temporalClient) {
18
19
  this.temporalClient = temporalClient;
19
20
  this.baseRequest = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(temporalClient, "Sales Invoice", SalesInvoice_1.SalesInvoice);
@@ -26,46 +27,44 @@ class ERPNextSalesInvoice {
26
27
  this.cancel = this.baseRequest.cancel;
27
28
  this.submit = this.baseRequest.submit;
28
29
  }
29
- createInvoiceDraftFromSalesOrder(salesOrderName) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const draft = yield this.methodRequest.request({
32
- methodName: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
33
- requestMethod: "POST",
34
- responseValidationModel: SalesInvoice_1.SalesInvoiceDraft,
35
- params: { source_name: salesOrderName },
36
- });
37
- return draft;
30
+ async createInvoiceDraftFromSalesOrder(salesOrderName) {
31
+ const draft = await this.methodRequest.request({
32
+ methodName: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
33
+ requestMethod: "POST",
34
+ responseValidationModel: SalesInvoice_1.SalesInvoiceDraft,
35
+ params: { source_name: salesOrderName },
38
36
  });
37
+ return draft;
39
38
  }
40
- createFromSalesOrder(salesOrderName_1) {
41
- return __awaiter(this, arguments, void 0, function* (salesOrderName, submit = false) {
42
- const invoiceDraft = yield this.createInvoiceDraftFromSalesOrder(salesOrderName);
43
- const body = Object.assign(Object.assign({}, invoiceDraft), (submit === true ? { docstatus: 1 } : {}));
44
- return yield this.baseRequest.create({
45
- inputValidationModel: SalesInvoice_1.SalesInvoiceDraft,
46
- body,
47
- });
39
+ async createFromSalesOrder(salesOrderName, submit = false) {
40
+ const invoiceDraft = await this.createInvoiceDraftFromSalesOrder(salesOrderName);
41
+ const body = {
42
+ ...invoiceDraft,
43
+ ...(submit === true ? { docstatus: 1 } : {}),
44
+ };
45
+ return await this.baseRequest.create({
46
+ inputValidationModel: SalesInvoice_1.SalesInvoiceDraft,
47
+ body,
48
48
  });
49
49
  }
50
- createInvoiceDraftFromDeliveryNote(deliveryNoteName) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const draft = yield this.methodRequest.request({
53
- methodName: `erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice`,
54
- requestMethod: "POST",
55
- responseValidationModel: SalesInvoice_1.SalesInvoiceDraft,
56
- params: { source_name: deliveryNoteName },
57
- });
58
- return draft;
50
+ async createInvoiceDraftFromDeliveryNote(deliveryNoteName) {
51
+ const draft = await this.methodRequest.request({
52
+ methodName: `erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice`,
53
+ requestMethod: "POST",
54
+ responseValidationModel: SalesInvoice_1.SalesInvoiceDraft,
55
+ params: { source_name: deliveryNoteName },
59
56
  });
57
+ return draft;
60
58
  }
61
- createFromDeliveryNote(deliveryNoteName_1) {
62
- return __awaiter(this, arguments, void 0, function* (deliveryNoteName, submit = false) {
63
- const invoiceDraft = yield this.createInvoiceDraftFromDeliveryNote(deliveryNoteName);
64
- const body = Object.assign(Object.assign({}, invoiceDraft), (submit === true ? { docstatus: 1 } : {}));
65
- return yield this.baseRequest.create({
66
- inputValidationModel: SalesInvoice_1.SalesInvoiceDraft,
67
- body,
68
- });
59
+ async createFromDeliveryNote(deliveryNoteName, submit = false) {
60
+ const invoiceDraft = await this.createInvoiceDraftFromDeliveryNote(deliveryNoteName);
61
+ const body = {
62
+ ...invoiceDraft,
63
+ ...(submit === true ? { docstatus: 1 } : {}),
64
+ };
65
+ return await this.baseRequest.create({
66
+ inputValidationModel: SalesInvoice_1.SalesInvoiceDraft,
67
+ body,
69
68
  });
70
69
  }
71
70
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextServicecase = void 0;
13
4
  const zod_1 = require("zod");
@@ -16,6 +7,16 @@ const doctypeResourceRequest_1 = require("../doctypeResourceRequest");
16
7
  const methodRequest_1 = require("../methodRequest");
17
8
  const Servicecase_1 = require("../model/Servicecase");
18
9
  class ERPNextServicecase {
10
+ methodRequest;
11
+ temporalClient;
12
+ baseRequest;
13
+ attachmentCollectionRequest;
14
+ internalReasonCollectionRequest;
15
+ create;
16
+ getList;
17
+ getById;
18
+ updateById;
19
+ deleteById;
19
20
  constructor(temporalClient) {
20
21
  this.methodRequest = new methodRequest_1.ERPNextMethodRequest(temporalClient);
21
22
  this.temporalClient = temporalClient;
@@ -28,124 +29,112 @@ class ERPNextServicecase {
28
29
  this.updateById = this.updateServicecase;
29
30
  this.deleteById = this.baseRequest.deleteById;
30
31
  }
31
- createServicecase(servicecase_1) {
32
- return __awaiter(this, arguments, void 0, function* (servicecase, options = { priority: 5 }) {
33
- var _a;
34
- for (const returnItem of (_a = servicecase.return_items) !== null && _a !== void 0 ? _a : []) {
35
- logger_1.lg.info("Creating attachment collection for return item", {
36
- returnItem,
37
- });
38
- const attachmentCollection = yield this.attachmentCollectionRequest.create({
39
- body: { attachments: [] },
40
- });
41
- logger_1.lg.info("Created attachment collection for return item", {
42
- attachmentCollection,
43
- });
44
- returnItem.attachments = attachmentCollection.name;
45
- logger_1.lg.info("Creating internal reasons collection for return item", {
46
- returnItem,
47
- });
48
- const internalReasonsCollection = yield this.internalReasonCollectionRequest.create({ body: {} });
49
- logger_1.lg.info("Created internal reasons collection for return item", {
50
- internalReasonsCollection,
51
- });
52
- returnItem.internal_reasons = internalReasonsCollection.name;
53
- }
54
- const newServicecase = yield this.baseRequest.create({
55
- body: servicecase,
56
- inputValidationModel: Servicecase_1.ServicecaseInput,
57
- priority: options.priority,
32
+ async createServicecase(servicecase, options = { priority: 5 }) {
33
+ for (const returnItem of servicecase.return_items ?? []) {
34
+ logger_1.lg.info("Creating attachment collection for return item", {
35
+ returnItem,
58
36
  });
59
- return newServicecase;
60
- });
61
- }
62
- updateServicecase(resourceId_1, servicecase_1) {
63
- return __awaiter(this, arguments, void 0, function* (resourceId, servicecase, options = { priority: 5 }) {
64
- var _a;
65
- for (const returnItem of (_a = servicecase.return_items) !== null && _a !== void 0 ? _a : []) {
66
- if (!returnItem.attachments) {
67
- const attachmentCollection = yield this.attachmentCollectionRequest.create({
68
- body: {
69
- attachments: [],
70
- },
71
- });
72
- returnItem.attachments = attachmentCollection.name;
73
- }
74
- if (!returnItem.internal_reasons) {
75
- const internalReasonsCollection = yield this.internalReasonCollectionRequest.create({ body: {} });
76
- returnItem.internal_reasons = internalReasonsCollection.name;
77
- }
78
- }
79
- const updatedServicecase = yield this.baseRequest.updateById({
80
- resourceId,
81
- body: servicecase,
82
- inputValidationModel: Servicecase_1.ServicecaseInput,
83
- priority: options.priority,
37
+ const attachmentCollection = await this.attachmentCollectionRequest.create({
38
+ body: { attachments: [] },
84
39
  });
85
- return updatedServicecase;
40
+ logger_1.lg.info("Created attachment collection for return item", {
41
+ attachmentCollection,
42
+ });
43
+ returnItem.attachments = attachmentCollection.name;
44
+ logger_1.lg.info("Creating internal reasons collection for return item", {
45
+ returnItem,
46
+ });
47
+ const internalReasonsCollection = await this.internalReasonCollectionRequest.create({ body: {} });
48
+ logger_1.lg.info("Created internal reasons collection for return item", {
49
+ internalReasonsCollection,
50
+ });
51
+ returnItem.internal_reasons = internalReasonsCollection.name;
52
+ }
53
+ const newServicecase = await this.baseRequest.create({
54
+ body: servicecase,
55
+ inputValidationModel: Servicecase_1.ServicecaseInput,
56
+ priority: options.priority,
86
57
  });
58
+ return newServicecase;
87
59
  }
88
- getServicecasesExtended(_a) {
89
- return __awaiter(this, arguments, void 0, function* ({ email, id, priority = 5, }) {
90
- let servicecases = [];
91
- if (email) {
92
- servicecases = yield this.methodRequest.request({
93
- requestMethod: "GET",
94
- methodName: "servicecases-extended",
95
- params: {
96
- email: email !== null && email !== void 0 ? email : "",
97
- id: id !== null && id !== void 0 ? id : "",
98
- },
99
- inputValidationModel: zod_1.z
100
- .object({
101
- email: zod_1.z.string().email(),
102
- id: zod_1.z.string().optional(),
103
- })
104
- .describe("ServicecaseExtendedInput"),
105
- responseValidationModel: Servicecase_1.ServicecaseMethodResponse,
106
- priority,
107
- });
108
- }
109
- else if (id) {
110
- servicecases = yield this.methodRequest.request({
111
- requestMethod: "GET",
112
- methodName: "servicecases-extended-name",
113
- params: {
114
- id: id,
60
+ async updateServicecase(resourceId, servicecase, options = { priority: 5 }) {
61
+ for (const returnItem of servicecase.return_items ?? []) {
62
+ if (!returnItem.attachments) {
63
+ const attachmentCollection = await this.attachmentCollectionRequest.create({
64
+ body: {
65
+ attachments: [],
115
66
  },
116
- inputValidationModel: zod_1.z
117
- .object({
118
- id: zod_1.z.string(),
119
- })
120
- .describe("ServicecaseExtendedInput"),
121
- responseValidationModel: Servicecase_1.ServicecaseMethodResponse,
122
- priority,
123
67
  });
68
+ returnItem.attachments = attachmentCollection.name;
124
69
  }
125
- else {
126
- throw new Error("Either email or id must be provided");
70
+ if (!returnItem.internal_reasons) {
71
+ const internalReasonsCollection = await this.internalReasonCollectionRequest.create({ body: {} });
72
+ returnItem.internal_reasons = internalReasonsCollection.name;
127
73
  }
128
- return servicecases;
74
+ }
75
+ const updatedServicecase = await this.baseRequest.updateById({
76
+ resourceId,
77
+ body: servicecase,
78
+ inputValidationModel: Servicecase_1.ServicecaseInput,
79
+ priority: options.priority,
129
80
  });
81
+ return updatedServicecase;
130
82
  }
131
- attachmentUpdate(resourceId_1, body_1) {
132
- return __awaiter(this, arguments, void 0, function* (resourceId, body, options = { priority: 5 }) {
133
- return yield this.attachmentCollectionRequest.updateById({
134
- resourceId,
135
- body,
136
- inputValidationModel: Servicecase_1.AttachmentCollection,
137
- priority: options.priority,
83
+ async getServicecasesExtended({ email, id, priority = 5, }) {
84
+ let servicecases = [];
85
+ if (email) {
86
+ servicecases = await this.methodRequest.request({
87
+ requestMethod: "GET",
88
+ methodName: "servicecases-extended",
89
+ params: {
90
+ email: email ?? "",
91
+ id: id ?? "",
92
+ },
93
+ inputValidationModel: zod_1.z
94
+ .object({
95
+ email: zod_1.z.string().email(),
96
+ id: zod_1.z.string().optional(),
97
+ })
98
+ .describe("ServicecaseExtendedInput"),
99
+ responseValidationModel: Servicecase_1.ServicecaseMethodResponse,
100
+ priority,
101
+ });
102
+ }
103
+ else if (id) {
104
+ servicecases = await this.methodRequest.request({
105
+ requestMethod: "GET",
106
+ methodName: "servicecases-extended-name",
107
+ params: {
108
+ id: id,
109
+ },
110
+ inputValidationModel: zod_1.z
111
+ .object({
112
+ id: zod_1.z.string(),
113
+ })
114
+ .describe("ServicecaseExtendedInput"),
115
+ responseValidationModel: Servicecase_1.ServicecaseMethodResponse,
116
+ priority,
138
117
  });
118
+ }
119
+ else {
120
+ throw new Error("Either email or id must be provided");
121
+ }
122
+ return servicecases;
123
+ }
124
+ async attachmentUpdate(resourceId, body, options = { priority: 5 }) {
125
+ return await this.attachmentCollectionRequest.updateById({
126
+ resourceId,
127
+ body,
128
+ inputValidationModel: Servicecase_1.AttachmentCollection,
129
+ priority: options.priority,
139
130
  });
140
131
  }
141
- internalReasonUpdate(resourceId_1, body_1) {
142
- return __awaiter(this, arguments, void 0, function* (resourceId, body, options = { priority: 5 }) {
143
- return yield this.internalReasonCollectionRequest.updateById({
144
- resourceId,
145
- body,
146
- inputValidationModel: Servicecase_1.InternalReasonCollection,
147
- priority: options.priority,
148
- });
132
+ async internalReasonUpdate(resourceId, body, options = { priority: 5 }) {
133
+ return await this.internalReasonCollectionRequest.updateById({
134
+ resourceId,
135
+ body,
136
+ inputValidationModel: Servicecase_1.InternalReasonCollection,
137
+ priority: options.priority,
149
138
  });
150
139
  }
151
140
  }