@longvansoftware/service-js-client 1.20.9 → 2.1.0
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/dist/src/graphql/orderGraphQL/queries.d.ts +1 -0
- package/dist/src/graphql/orderGraphQL/queries.js +11 -1
- package/dist/src/graphql/user/queries.d.ts +19 -17
- package/dist/src/graphql/user/queries.js +12 -1
- package/dist/src/lib/orderGraphQL/index.d.ts +1 -0
- package/dist/src/lib/orderGraphQL/index.js +17 -0
- package/dist/src/lib/service.d.ts +14 -0
- package/dist/src/lib/service.js +101 -0
- package/dist/src/lib/user/index.d.ts +1 -0
- package/dist/src/lib/user/index.js +19 -3
- package/dist/src/utils/build-field-string.d.ts +1 -0
- package/dist/src/utils/build-field-string.js +16 -0
- package/package.json +1 -1
|
@@ -6,3 +6,4 @@ export declare const GET_ORDER_LINE_ITEM_BY_SERVICE_ID: DocumentNode;
|
|
|
6
6
|
export declare const GET_ORDER_BY_SERVICE_ID: DocumentNode;
|
|
7
7
|
export declare const FIND_ORDER_BY_OWNER_PARTYID: DocumentNode;
|
|
8
8
|
export declare const CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
9
|
+
export declare const SEARCH_ORDER_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = exports.FIND_ORDER_BY_OWNER_PARTYID = exports.GET_ORDER_BY_SERVICE_ID = exports.GET_ORDER_LINE_ITEM_BY_SERVICE_ID = exports.GET_QUANTITY_ORDER_LINEITEMS = exports.GET_ORDER_DETAIL_DYNAMIC = exports.GET_ORDER_DETAIL = void 0;
|
|
3
|
+
exports.SEARCH_ORDER_DYNAMIC = exports.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = exports.FIND_ORDER_BY_OWNER_PARTYID = exports.GET_ORDER_BY_SERVICE_ID = exports.GET_ORDER_LINE_ITEM_BY_SERVICE_ID = exports.GET_QUANTITY_ORDER_LINEITEMS = exports.GET_ORDER_DETAIL_DYNAMIC = exports.GET_ORDER_DETAIL = void 0;
|
|
4
4
|
const graphql_tag_1 = require("graphql-tag");
|
|
5
5
|
exports.GET_ORDER_DETAIL = (0, graphql_tag_1.gql) `
|
|
6
6
|
query getOrderDetail($orderId: String!) {
|
|
@@ -458,3 +458,13 @@ const CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = (fields = []) => {
|
|
|
458
458
|
`;
|
|
459
459
|
};
|
|
460
460
|
exports.CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC = CALC_EXCHANGE_PRICE_EXTEND_RESOURCE_DETAIL_DYNAMIC;
|
|
461
|
+
const SEARCH_ORDER_DYNAMIC = (fields = []) => {
|
|
462
|
+
const fieldStr = fields.join("\n ");
|
|
463
|
+
const hasFields = fields.length > 0;
|
|
464
|
+
return (0, graphql_tag_1.gql) `
|
|
465
|
+
query searchOrder($filter: OrderFilter) {
|
|
466
|
+
searchOrder(filter: $filter) ${hasFields ? `{ ${fieldStr} }` : ""}
|
|
467
|
+
}
|
|
468
|
+
`;
|
|
469
|
+
};
|
|
470
|
+
exports.SEARCH_ORDER_DYNAMIC = SEARCH_ORDER_DYNAMIC;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
1
|
+
import { DocumentNode } from "graphql";
|
|
2
|
+
export declare const GET_PERSON_BY_IDS_QUERY: DocumentNode;
|
|
3
|
+
export declare const SEARCH_COMPANY: DocumentNode;
|
|
4
|
+
export declare const GET_CUSTOMER_BY_ID: DocumentNode;
|
|
5
|
+
export declare const SEARCH_CUSTOMER: DocumentNode;
|
|
6
|
+
export declare const SEARCH_EMPLOYEES: DocumentNode;
|
|
7
|
+
export declare const GET_POSTIONS_BY_EMPLOYEES_ID: DocumentNode;
|
|
8
|
+
export declare const GET_STORE_CHANEL_IDS_BY_EMPLOYESS_ID: DocumentNode;
|
|
9
|
+
export declare const GET_EMPLOYEES_BY_STORE_CHANEL_ID: DocumentNode;
|
|
10
|
+
export declare const GET_COMPANY_BY_CONTACT_INFO_ID: DocumentNode;
|
|
11
|
+
export declare const GET_CONTACT_INFOS_BY_COMPANY_ID: DocumentNode;
|
|
12
|
+
export declare const GET_PROVINCES: DocumentNode;
|
|
13
|
+
export declare const GET_DISTRICTS: DocumentNode;
|
|
14
|
+
export declare const GET_WARDS: DocumentNode;
|
|
15
|
+
export declare const GET_WARDS_BY_PROVINCE_ID: DocumentNode;
|
|
16
|
+
export declare const GET_VAT_INFOR_BY_OWNER_PARTY_ID: DocumentNode;
|
|
17
|
+
export declare const GET_TEAM_BY_USER_ID: DocumentNode;
|
|
18
|
+
export declare const GET_USERS_BY_TEAM_ID: DocumentNode;
|
|
19
|
+
export declare const GET_CUSTOMER_BY_ID_DYNAMIC: (fields?: string[]) => DocumentNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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_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!]!) {
|
|
@@ -331,3 +331,14 @@ exports.GET_USERS_BY_TEAM_ID = (0, graphql_tag_1.gql) `
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
`;
|
|
334
|
+
const GET_CUSTOMER_BY_ID_DYNAMIC = (fields = []) => {
|
|
335
|
+
const fieldStr = fields.join("\n ");
|
|
336
|
+
const hasFields = fields.length > 0;
|
|
337
|
+
return (0, graphql_tag_1.gql) `query GetCustomerById($id: String!) {
|
|
338
|
+
getCustomerById(id: $id) {
|
|
339
|
+
${hasFields ? `${fieldStr}` : ""}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
`;
|
|
343
|
+
};
|
|
344
|
+
exports.GET_CUSTOMER_BY_ID_DYNAMIC = GET_CUSTOMER_BY_ID_DYNAMIC;
|
|
@@ -14,4 +14,5 @@ export declare class OrderGraphQLService extends Service {
|
|
|
14
14
|
removeProductOptionOrderLineItem(orderLineItemId: string, optionId: string, updateBy: string): Promise<any>;
|
|
15
15
|
findOrderByOwnerPartyId(ownerPartyId: string): Promise<any>;
|
|
16
16
|
calcExchangePriceExtendResourceDetail(serviceId: string, productBaseIdNew: string, durationQuantity: string, durationUnit: string, fields: string[]): Promise<any>;
|
|
17
|
+
searchOrderDynamic(params: any, fields: string[]): Promise<any>;
|
|
17
18
|
}
|
|
@@ -209,5 +209,22 @@ class OrderGraphQLService extends serviceSDK_1.Service {
|
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
+
searchOrderDynamic(params, fields) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
console.log("🚀 ~ OrderGraphQLService ~ searchOrderDynamic ~ params:", params);
|
|
215
|
+
const query = (0, queries_1.SEARCH_ORDER_DYNAMIC)(fields);
|
|
216
|
+
const variables = {
|
|
217
|
+
filter: params,
|
|
218
|
+
};
|
|
219
|
+
try {
|
|
220
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
221
|
+
return response.searchOrder;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.log(`Error in searchOrderDynamic: ${error}`);
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
212
229
|
}
|
|
213
230
|
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;
|
|
@@ -33,4 +33,5 @@ export declare class UserService extends Service {
|
|
|
33
33
|
addUserToTeam(teamId: string, userId: string, createdBy: string): Promise<any>;
|
|
34
34
|
removeUserFromTeam(teamId: string, userId: string, deletedBy: string): Promise<any>;
|
|
35
35
|
updateTeamName(teamId: string, name: string, updatedBy: string): Promise<any>;
|
|
36
|
+
getCustomerByIdDynamic(id: string, fields: string[]): Promise<any>;
|
|
36
37
|
}
|
|
@@ -305,7 +305,7 @@ class UserService extends serviceSDK_1.Service {
|
|
|
305
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
306
|
const query = queries_1.GET_PROVINCES;
|
|
307
307
|
const variables = {
|
|
308
|
-
version
|
|
308
|
+
version,
|
|
309
309
|
};
|
|
310
310
|
try {
|
|
311
311
|
const response = yield this.graphqlQueryV2(query, variables);
|
|
@@ -338,7 +338,7 @@ class UserService extends serviceSDK_1.Service {
|
|
|
338
338
|
const query = queries_1.GET_WARDS;
|
|
339
339
|
const variables = {
|
|
340
340
|
districtId,
|
|
341
|
-
version
|
|
341
|
+
version,
|
|
342
342
|
};
|
|
343
343
|
try {
|
|
344
344
|
const response = yield this.graphqlQueryV2(query, variables);
|
|
@@ -354,7 +354,7 @@ class UserService extends serviceSDK_1.Service {
|
|
|
354
354
|
return __awaiter(this, void 0, void 0, function* () {
|
|
355
355
|
const query = queries_1.GET_WARDS_BY_PROVINCE_ID;
|
|
356
356
|
const variables = {
|
|
357
|
-
provinceId
|
|
357
|
+
provinceId,
|
|
358
358
|
};
|
|
359
359
|
try {
|
|
360
360
|
const response = yield this.graphqlQueryV2(query, variables);
|
|
@@ -541,5 +541,21 @@ class UserService extends serviceSDK_1.Service {
|
|
|
541
541
|
}
|
|
542
542
|
});
|
|
543
543
|
}
|
|
544
|
+
getCustomerByIdDynamic(id, fields) {
|
|
545
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
546
|
+
const query = (0, queries_1.GET_CUSTOMER_BY_ID_DYNAMIC)(fields);
|
|
547
|
+
const variables = {
|
|
548
|
+
id,
|
|
549
|
+
};
|
|
550
|
+
try {
|
|
551
|
+
const response = yield this.graphqlQueryV2(query, variables);
|
|
552
|
+
return response.getCustomerById;
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
console.log(`Error in getCustomerById: ${error}`);
|
|
556
|
+
throw error;
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
544
560
|
}
|
|
545
561
|
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;
|