@longvansoftware/service-js-client 2.1.4 → 2.1.6

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.
@@ -4,3 +4,4 @@ export declare const UPDATE_QUANTITY_V2: DocumentNode;
4
4
  export declare const ADD_TO_CART: DocumentNode;
5
5
  export declare const REMOVE_PRODUCT_OPTION_ORDER_LINE_ITEM: DocumentNode;
6
6
  export declare const ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE: (fields?: string[]) => DocumentNode;
7
+ export declare const UPDATE_ORDER_LINE_ITEM_PARENT_ID: DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE = exports.REMOVE_PRODUCT_OPTION_ORDER_LINE_ITEM = exports.ADD_TO_CART = exports.UPDATE_QUANTITY_V2 = exports.CREATE_ORDER = void 0;
3
+ exports.UPDATE_ORDER_LINE_ITEM_PARENT_ID = exports.ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE = exports.REMOVE_PRODUCT_OPTION_ORDER_LINE_ITEM = exports.ADD_TO_CART = exports.UPDATE_QUANTITY_V2 = exports.CREATE_ORDER = void 0;
4
4
  const graphql_tag_1 = require("graphql-tag");
5
5
  exports.CREATE_ORDER = (0, graphql_tag_1.gql) `
6
6
  mutation CreateOrder($input: CreateOrderInput!) {
@@ -370,3 +370,18 @@ const ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE = (fields = []) => {
370
370
  `;
371
371
  };
372
372
  exports.ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE = ADD_ITEM_INTO_ORDER_BY_PRODUCT_JSON_RESOURCE;
373
+ exports.UPDATE_ORDER_LINE_ITEM_PARENT_ID = (0, graphql_tag_1.gql) `
374
+ mutation UpdateOrderLineItemParentId(
375
+ $partnerId: String!
376
+ $orderLineItemChildIds: [String]!
377
+ $orderLineItemParentId: String!
378
+ $updateBy: String!
379
+ ) {
380
+ updateOrderLineItemParentId(
381
+ partnerId: $partnerId
382
+ orderLineItemChildIds: $orderLineItemChildIds
383
+ orderLineItemParentId: $orderLineItemParentId
384
+ updateBy: $updateBy
385
+ )
386
+ }
387
+ `;
@@ -17,3 +17,4 @@ export declare const GET_VAT_INFOR_BY_OWNER_PARTY_ID: DocumentNode;
17
17
  export declare const GET_TEAM_BY_USER_ID: DocumentNode;
18
18
  export declare const GET_USERS_BY_TEAM_ID: DocumentNode;
19
19
  export declare const GET_CUSTOMER_BY_ID_DYNAMIC: (fields?: string[]) => DocumentNode;
20
+ export declare const GET_CUSTOMER_BY_IDS_DYNAMIC: (fields?: string[]) => DocumentNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GET_CUSTOMER_BY_ID_DYNAMIC = exports.GET_USERS_BY_TEAM_ID = exports.GET_TEAM_BY_USER_ID = exports.GET_VAT_INFOR_BY_OWNER_PARTY_ID = exports.GET_WARDS_BY_PROVINCE_ID = exports.GET_WARDS = exports.GET_DISTRICTS = exports.GET_PROVINCES = exports.GET_CONTACT_INFOS_BY_COMPANY_ID = exports.GET_COMPANY_BY_CONTACT_INFO_ID = exports.GET_EMPLOYEES_BY_STORE_CHANEL_ID = exports.GET_STORE_CHANEL_IDS_BY_EMPLOYESS_ID = exports.GET_POSTIONS_BY_EMPLOYEES_ID = exports.SEARCH_EMPLOYEES = exports.SEARCH_CUSTOMER = exports.GET_CUSTOMER_BY_ID = exports.SEARCH_COMPANY = exports.GET_PERSON_BY_IDS_QUERY = void 0;
3
+ exports.GET_CUSTOMER_BY_IDS_DYNAMIC = exports.GET_CUSTOMER_BY_ID_DYNAMIC = exports.GET_USERS_BY_TEAM_ID = exports.GET_TEAM_BY_USER_ID = exports.GET_VAT_INFOR_BY_OWNER_PARTY_ID = exports.GET_WARDS_BY_PROVINCE_ID = exports.GET_WARDS = exports.GET_DISTRICTS = exports.GET_PROVINCES = exports.GET_CONTACT_INFOS_BY_COMPANY_ID = exports.GET_COMPANY_BY_CONTACT_INFO_ID = exports.GET_EMPLOYEES_BY_STORE_CHANEL_ID = exports.GET_STORE_CHANEL_IDS_BY_EMPLOYESS_ID = exports.GET_POSTIONS_BY_EMPLOYEES_ID = exports.SEARCH_EMPLOYEES = exports.SEARCH_CUSTOMER = exports.GET_CUSTOMER_BY_ID = exports.SEARCH_COMPANY = exports.GET_PERSON_BY_IDS_QUERY = void 0;
4
4
  const graphql_tag_1 = require("graphql-tag");
5
5
  exports.GET_PERSON_BY_IDS_QUERY = (0, graphql_tag_1.gql) `
6
6
  query GetPersonByIds($partyIds: [String!]!) {
@@ -342,3 +342,14 @@ const GET_CUSTOMER_BY_ID_DYNAMIC = (fields = []) => {
342
342
  `;
343
343
  };
344
344
  exports.GET_CUSTOMER_BY_ID_DYNAMIC = GET_CUSTOMER_BY_ID_DYNAMIC;
345
+ const GET_CUSTOMER_BY_IDS_DYNAMIC = (fields = []) => {
346
+ const fieldStr = fields.join("\n ");
347
+ const hasFields = fields.length > 0;
348
+ return (0, graphql_tag_1.gql) `query GetCustomerByIds($ids: [String]) {
349
+ getCustomerByIds(ids: $ids) {
350
+ ${hasFields ? `${fieldStr}` : ""}
351
+ }
352
+ }
353
+ `;
354
+ };
355
+ exports.GET_CUSTOMER_BY_IDS_DYNAMIC = GET_CUSTOMER_BY_IDS_DYNAMIC;
@@ -16,4 +16,5 @@ export declare class OrderGraphQLService extends Service {
16
16
  calcExchangePriceExtendResourceDetail(serviceId: string, productBaseIdNew: string, durationQuantity: string, durationUnit: string, fields: string[]): Promise<any>;
17
17
  searchOrderDynamic(params: any, fields: string[]): Promise<any>;
18
18
  addItemIntoOrderByProductJsonResource(serviceId: string, orderId: string, itemInput: any, durationQuantity: number, durationUnit: string, actorId: string, fields: string[]): Promise<any>;
19
+ updateOrderLineItemParentId(orderLineItemChildIds: string[], orderLineItemParentId: string, updateBy: string): Promise<any>;
19
20
  }
@@ -248,5 +248,24 @@ class OrderGraphQLService extends serviceSDK_1.Service {
248
248
  }
249
249
  });
250
250
  }
251
+ updateOrderLineItemParentId(orderLineItemChildIds, orderLineItemParentId, updateBy) {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ const mutation = mutations_1.UPDATE_ORDER_LINE_ITEM_PARENT_ID;
254
+ const variables = {
255
+ partnerId: this.orgId,
256
+ orderLineItemChildIds,
257
+ orderLineItemParentId,
258
+ updateBy,
259
+ };
260
+ try {
261
+ const response = yield this.graphqlMutationV2(mutation, variables);
262
+ return response.updateOrderLineItemParentId;
263
+ }
264
+ catch (error) {
265
+ console.log(`Error in addItemIntoOrderByProductJsonResource: ${error}`);
266
+ throw error;
267
+ }
268
+ });
269
+ }
251
270
  }
252
271
  exports.OrderGraphQLService = OrderGraphQLService;
@@ -0,0 +1,14 @@
1
+ import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
2
+ import { DocumentNode } from "graphql";
3
+ export declare class Service {
4
+ protected token: string | null;
5
+ protected client: ApolloClient<NormalizedCacheObject>;
6
+ protected orgId: string;
7
+ protected storeId: string;
8
+ protected endpoint: string;
9
+ constructor(endpoint: string, orgId: string, storeId: string);
10
+ setToken(token: string): void;
11
+ protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
12
+ protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
13
+ protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
14
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ // src/service.ts
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Service = void 0;
17
+ const client_1 = require("@apollo/client");
18
+ const axios_1 = __importDefault(require("axios"));
19
+ class Service {
20
+ constructor(endpoint, orgId, storeId) {
21
+ this.token = null;
22
+ this.client = new client_1.ApolloClient({
23
+ uri: endpoint,
24
+ cache: new client_1.InMemoryCache(),
25
+ defaultOptions: {
26
+ query: {
27
+ fetchPolicy: "network-only",
28
+ },
29
+ },
30
+ });
31
+ this.orgId = orgId;
32
+ this.storeId = storeId;
33
+ this.endpoint = endpoint;
34
+ }
35
+ setToken(token) {
36
+ this.token = token;
37
+ }
38
+ // setOrgId(orgId: string) {
39
+ // this.orgId = orgId;
40
+ // }
41
+ graphqlQuery(query, variables) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const { data, errors } = yield this.client.query({
45
+ query: (0, client_1.gql) `
46
+ ${query}
47
+ `,
48
+ variables,
49
+ });
50
+ if (errors) {
51
+ throw new Error(`GraphQL error! errors: ${errors}`);
52
+ }
53
+ return data;
54
+ }
55
+ catch (error) {
56
+ console.log(`Error in graphqlQuery: ${error}`);
57
+ throw error;
58
+ }
59
+ });
60
+ }
61
+ graphqlMutation(mutation, variables) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ try {
64
+ const { data, errors } = yield this.client.mutate({
65
+ mutation: (0, client_1.gql) `
66
+ ${mutation}
67
+ `,
68
+ variables,
69
+ });
70
+ if (errors) {
71
+ throw new Error(`GraphQL error! errors: ${errors}`);
72
+ }
73
+ return data;
74
+ }
75
+ catch (error) {
76
+ console.log(`Error in graphqlMutation: ${error}`);
77
+ throw error;
78
+ }
79
+ });
80
+ }
81
+ restApiCallWithToken(path, method, data, headers) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ try {
84
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { "Partner-Id": this.orgId, "X-Ecomos-Access-Token": this.token });
85
+ console.log("🚀 ~ Service ~ modifiedHeaders:", modifiedHeaders);
86
+ const response = yield (0, axios_1.default)({
87
+ url: this.endpoint + path,
88
+ method,
89
+ data,
90
+ headers: modifiedHeaders,
91
+ });
92
+ return response.data;
93
+ }
94
+ catch (error) {
95
+ console.log(`Error in restApiCallWithToken: ${error}`);
96
+ throw error;
97
+ }
98
+ });
99
+ }
100
+ }
101
+ exports.Service = Service;
@@ -34,4 +34,5 @@ export declare class UserService extends Service {
34
34
  removeUserFromTeam(teamId: string, userId: string, deletedBy: string): Promise<any>;
35
35
  updateTeamName(teamId: string, name: string, updatedBy: string): Promise<any>;
36
36
  getCustomerByIdDynamic(id: string, fields: string[]): Promise<any>;
37
+ getCustomerByIdsDynamic(ids: string[], fields: string[]): Promise<any>;
37
38
  }
@@ -557,5 +557,21 @@ class UserService extends serviceSDK_1.Service {
557
557
  }
558
558
  });
559
559
  }
560
+ getCustomerByIdsDynamic(ids, fields) {
561
+ return __awaiter(this, void 0, void 0, function* () {
562
+ const query = (0, queries_1.GET_CUSTOMER_BY_IDS_DYNAMIC)(fields);
563
+ const variables = {
564
+ ids,
565
+ };
566
+ try {
567
+ const response = yield this.graphqlQueryV2(query, variables);
568
+ return response.getCustomerByIds;
569
+ }
570
+ catch (error) {
571
+ console.log(`Error in getCustomerByIds: ${error}`);
572
+ throw error;
573
+ }
574
+ });
575
+ }
560
576
  }
561
577
  exports.UserService = UserService;
@@ -0,0 +1 @@
1
+ export declare function buildFieldString(fields: (string | Record<string, any>)[], indent?: number): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFieldString = void 0;
4
+ function buildFieldString(fields, indent = 6) {
5
+ const space = " ".repeat(indent);
6
+ return fields
7
+ .map((field) => {
8
+ if (typeof field === "string")
9
+ return `${space}${field}`;
10
+ const [key, value] = Object.entries(field)[0];
11
+ const nested = buildFieldString(value, indent + 2);
12
+ return `${space}${key} {\n${nested}\n${space}}`;
13
+ })
14
+ .join("\n");
15
+ }
16
+ exports.buildFieldString = buildFieldString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longvansoftware/service-js-client",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "files": [