@longvansoftware/service-js-client 1.0.2

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 (84) hide show
  1. package/README.md +93 -0
  2. package/dist/config/config.d.ts +26 -0
  3. package/dist/config/config.js +29 -0
  4. package/dist/src/graphql/auth/mutations.d.ts +7 -0
  5. package/dist/src/graphql/auth/mutations.js +99 -0
  6. package/dist/src/graphql/auth/queries.d.ts +1 -0
  7. package/dist/src/graphql/auth/queries.js +25 -0
  8. package/dist/src/graphql/cloud/mutations.d.ts +8 -0
  9. package/dist/src/graphql/cloud/mutations.js +115 -0
  10. package/dist/src/graphql/cloud/queries.d.ts +5 -0
  11. package/dist/src/graphql/cloud/queries.js +121 -0
  12. package/dist/src/graphql/computing/mutations.d.ts +10 -0
  13. package/dist/src/graphql/computing/mutations.js +110 -0
  14. package/dist/src/graphql/computing/queries.d.ts +3 -0
  15. package/dist/src/graphql/computing/queries.js +48 -0
  16. package/dist/src/graphql/crm/mutations.d.ts +8 -0
  17. package/dist/src/graphql/crm/mutations.js +316 -0
  18. package/dist/src/graphql/crm/queries.d.ts +7 -0
  19. package/dist/src/graphql/crm/queries.js +281 -0
  20. package/dist/src/graphql/payment/mutations.d.ts +1 -0
  21. package/dist/src/graphql/payment/mutations.js +35 -0
  22. package/dist/src/graphql/payment/queries.d.ts +2 -0
  23. package/dist/src/graphql/payment/queries.js +23 -0
  24. package/dist/src/graphql/product/mutations.d.ts +0 -0
  25. package/dist/src/graphql/product/mutations.js +1 -0
  26. package/dist/src/graphql/product/queries.d.ts +11 -0
  27. package/dist/src/graphql/product/queries.js +431 -0
  28. package/dist/src/graphql/service/mutations.d.ts +10 -0
  29. package/dist/src/graphql/service/mutations.js +284 -0
  30. package/dist/src/graphql/service/queries.d.ts +6 -0
  31. package/dist/src/graphql/service/queries.js +174 -0
  32. package/dist/src/graphql/user/mutations.d.ts +4 -0
  33. package/dist/src/graphql/user/mutations.js +118 -0
  34. package/dist/src/graphql/user/queries.d.ts +13 -0
  35. package/dist/src/graphql/user/queries.js +252 -0
  36. package/dist/src/index.d.ts +1 -0
  37. package/dist/src/index.js +5 -0
  38. package/dist/src/lib/SDK.d.ts +42 -0
  39. package/dist/src/lib/SDK.js +71 -0
  40. package/dist/src/lib/auth/index.d.ts +27 -0
  41. package/dist/src/lib/auth/index.js +72 -0
  42. package/dist/src/lib/cloud/index.d.ts +25 -0
  43. package/dist/src/lib/cloud/index.js +248 -0
  44. package/dist/src/lib/computing/index.d.ts +25 -0
  45. package/dist/src/lib/computing/index.js +254 -0
  46. package/dist/src/lib/crm/index.d.ts +21 -0
  47. package/dist/src/lib/crm/index.js +296 -0
  48. package/dist/src/lib/order/index.d.ts +452 -0
  49. package/dist/src/lib/order/index.js +1204 -0
  50. package/dist/src/lib/payment/index.d.ts +7 -0
  51. package/dist/src/lib/payment/index.js +69 -0
  52. package/dist/src/lib/product/index.d.ts +37 -0
  53. package/dist/src/lib/product/index.js +132 -0
  54. package/dist/src/lib/service/index.d.ts +94 -0
  55. package/dist/src/lib/service/index.js +348 -0
  56. package/dist/src/lib/service.d.ts +14 -0
  57. package/dist/src/lib/service.js +101 -0
  58. package/dist/src/lib/serviceSDK.d.ts +18 -0
  59. package/dist/src/lib/serviceSDK.js +187 -0
  60. package/dist/src/lib/user/index.d.ts +23 -0
  61. package/dist/src/lib/user/index.js +345 -0
  62. package/dist/src/lib/warehouse/index.d.ts +20 -0
  63. package/dist/src/lib/warehouse/index.js +48 -0
  64. package/dist/src/types/auth.d.ts +82 -0
  65. package/dist/src/types/auth.js +2 -0
  66. package/dist/src/types/cloud.d.ts +40 -0
  67. package/dist/src/types/cloud.js +2 -0
  68. package/dist/src/types/computing.d.ts +16 -0
  69. package/dist/src/types/computing.js +2 -0
  70. package/dist/src/types/crm.d.ts +291 -0
  71. package/dist/src/types/crm.js +2 -0
  72. package/dist/src/types/order.d.ts +54 -0
  73. package/dist/src/types/order.js +2 -0
  74. package/dist/src/types/product.d.ts +63 -0
  75. package/dist/src/types/product.js +2 -0
  76. package/dist/src/types/service.d.ts +29 -0
  77. package/dist/src/types/service.js +2 -0
  78. package/dist/src/types/user.d.ts +95 -0
  79. package/dist/src/types/user.js +2 -0
  80. package/dist/src/types/warehouse.d.ts +5 -0
  81. package/dist/src/types/warehouse.js +2 -0
  82. package/dist/src/utils/helpers.d.ts +4 -0
  83. package/dist/src/utils/helpers.js +41 -0
  84. package/package.json +43 -0
@@ -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;
@@ -0,0 +1,18 @@
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
+ setStoreId(storeId: string): void;
12
+ protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
13
+ protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
14
+ protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
15
+ protected restApiCallWithNoToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
16
+ protected graphqlQueryV2(query: DocumentNode, variables: any): Promise<any>;
17
+ protected graphqlMutationV2(mutation: DocumentNode, variables: any): Promise<any>;
18
+ }
@@ -0,0 +1,187 @@
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
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
20
+ class Service {
21
+ constructor(endpoint, orgId, storeId) {
22
+ this.token = null;
23
+ this.client = new client_1.ApolloClient({
24
+ link: new client_1.HttpLink({ uri: endpoint, fetch: cross_fetch_1.default }),
25
+ // uri: endpoint,
26
+ cache: new client_1.InMemoryCache(),
27
+ defaultOptions: {
28
+ query: {
29
+ fetchPolicy: "network-only",
30
+ },
31
+ },
32
+ });
33
+ this.orgId = orgId;
34
+ this.storeId = storeId;
35
+ this.endpoint = endpoint;
36
+ }
37
+ setToken(token) {
38
+ this.token = token;
39
+ }
40
+ setStoreId(storeId) {
41
+ this.storeId = storeId;
42
+ }
43
+ graphqlQuery(query, variables) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ try {
46
+ const { data, errors } = yield this.client.query({
47
+ query: (0, client_1.gql) `
48
+ ${query}
49
+ `,
50
+ variables,
51
+ context: {
52
+ method: "POST",
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ partnerId: this.orgId,
56
+ },
57
+ },
58
+ });
59
+ if (errors) {
60
+ throw new Error(`GraphQL error! errors: ${errors}`);
61
+ }
62
+ return data;
63
+ }
64
+ catch (error) {
65
+ console.log(`Error in graphqlQuery: ${error}`);
66
+ throw error;
67
+ }
68
+ });
69
+ }
70
+ graphqlMutation(mutation, variables) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ try {
73
+ const { data, errors } = yield this.client.mutate({
74
+ mutation: (0, client_1.gql) `
75
+ ${mutation}
76
+ `,
77
+ variables,
78
+ context: {
79
+ method: "POST",
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ partnerId: this.orgId,
83
+ },
84
+ },
85
+ });
86
+ if (errors) {
87
+ throw new Error(`GraphQL error! errors: ${errors}`);
88
+ }
89
+ return data;
90
+ }
91
+ catch (error) {
92
+ throw error;
93
+ }
94
+ });
95
+ }
96
+ restApiCallWithToken(path, method, data, headers) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ try {
99
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { "PartnerId": this.orgId, "Authorization": 'Bearer ' + this.token });
100
+ const response = yield (0, axios_1.default)({
101
+ url: this.endpoint + path,
102
+ method,
103
+ data,
104
+ headers: modifiedHeaders,
105
+ });
106
+ return response.data;
107
+ }
108
+ catch (error) {
109
+ throw error;
110
+ }
111
+ });
112
+ }
113
+ restApiCallWithNoToken(path, method, data, headers) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ try {
116
+ const modifiedHeaders = Object.assign(Object.assign({}, headers), { Partnerid: this.orgId });
117
+ const response = yield (0, axios_1.default)({
118
+ url: this.endpoint + path,
119
+ method,
120
+ data,
121
+ headers: modifiedHeaders,
122
+ });
123
+ return response.data;
124
+ }
125
+ catch (error) {
126
+ console.log(`Error in restApiCallWithNoToken: ${error}`);
127
+ throw error;
128
+ }
129
+ });
130
+ }
131
+ graphqlQueryV2(query, variables) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ try {
134
+ const { data, errors } = yield this.client.query({
135
+ query: (0, client_1.gql) `
136
+ ${query}
137
+ `,
138
+ variables,
139
+ context: {
140
+ method: "POST",
141
+ headers: {
142
+ "Content-Type": "application/json",
143
+ "PartnerId": this.orgId,
144
+ "Authorization": 'Bearer ' + this.token,
145
+ },
146
+ },
147
+ });
148
+ if (errors) {
149
+ throw new Error(`GraphQL error! errors: ${errors}`);
150
+ }
151
+ return data;
152
+ }
153
+ catch (error) {
154
+ console.log(`Error in graphqlQuery: ${error}`);
155
+ throw error;
156
+ }
157
+ });
158
+ }
159
+ graphqlMutationV2(mutation, variables) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ try {
162
+ const { data, errors } = yield this.client.mutate({
163
+ mutation: (0, client_1.gql) `
164
+ ${mutation}
165
+ `,
166
+ variables,
167
+ context: {
168
+ method: "POST",
169
+ headers: {
170
+ "Content-Type": "application/json",
171
+ "PartnerId": this.orgId,
172
+ "Authorization": 'Bearer ' + this.token,
173
+ },
174
+ },
175
+ });
176
+ if (errors) {
177
+ throw new Error(`GraphQL error! errors: ${errors}`);
178
+ }
179
+ return data;
180
+ }
181
+ catch (error) {
182
+ throw error;
183
+ }
184
+ });
185
+ }
186
+ }
187
+ exports.Service = Service;
@@ -0,0 +1,23 @@
1
+ import { Service } from "../serviceSDK";
2
+ import { createCompanyRequest, createCustomerRequest, dataCustomerRequest, updateCustomerRequest, customerQuery, searchCustomersResponse, employeesQuery } from "../../types/user";
3
+ export declare class UserService extends Service {
4
+ constructor(endpoint: string, orgId: string, storeId: string);
5
+ getPersonByPartyIds(partyIds: string[]): Promise<any>;
6
+ createCompany(payload: createCompanyRequest, createdBy: string): Promise<any>;
7
+ updateCompanyInfo(id: string, fieldName: string, valueUpdate: string, updatedBy: string): Promise<any>;
8
+ updateCustomer(id: string, customerItem: updateCustomerRequest, updatedBy: string): Promise<any>;
9
+ getCustomerById(id: string): Promise<any>;
10
+ searchCompany(keyword: string, limit: number): Promise<any>;
11
+ createCustomerV2(createCustomerRequest: createCustomerRequest, createdBy: string): Promise<any>;
12
+ createCustomer(dataCustomerRequest: dataCustomerRequest, createdBy: string, type: string): Promise<any>;
13
+ searchCustomer(searchParams: customerQuery): Promise<searchCustomersResponse>;
14
+ searchEmployees(searchParams: employeesQuery): Promise<any>;
15
+ getPositionsByEmployeeId(employeeId: string): Promise<any>;
16
+ getStoreChannelIdsByEmployeeId(employeeId: string): Promise<any>;
17
+ getEmployeesByStoreChannelId(): Promise<any>;
18
+ getCompanyByContactInfoId(contactId: string): Promise<any>;
19
+ getContactInfosByCompanyId(companyId: string): Promise<any>;
20
+ getProvinces(): Promise<any>;
21
+ getDistricts(provinceId: string): Promise<any>;
22
+ getWards(districtId: string): Promise<any>;
23
+ }
@@ -0,0 +1,345 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UserService = void 0;
13
+ const serviceSDK_1 = require("../serviceSDK");
14
+ const queries_1 = require("../../graphql/user/queries");
15
+ const mutations_1 = require("../../graphql/user/mutations");
16
+ class UserService extends serviceSDK_1.Service {
17
+ constructor(endpoint, orgId, storeId) {
18
+ super(endpoint, orgId, storeId);
19
+ }
20
+ getPersonByPartyIds(partyIds) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const query = queries_1.GET_PERSON_BY_IDS_QUERY;
23
+ const variables = { partyIds };
24
+ try {
25
+ const response = yield this.graphqlQuery(query, variables);
26
+ return response.getPersonByPartyIds;
27
+ }
28
+ catch (error) {
29
+ console.log(`Error in getPersonByPartyIds: ${error}`);
30
+ throw error;
31
+ }
32
+ });
33
+ }
34
+ createCompany(payload, createdBy) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const mutation = mutations_1.CREATE_COMPANY;
37
+ const variables = {
38
+ orgId: this.orgId,
39
+ createCompanyRequest: payload,
40
+ createTaxCodeRequest: null,
41
+ createdBy,
42
+ };
43
+ try {
44
+ const response = yield this.graphqlMutation(mutation, variables);
45
+ return response.createCompany;
46
+ }
47
+ catch (error) {
48
+ console.log(`Error in createCompany: ${error}`);
49
+ throw error;
50
+ }
51
+ });
52
+ }
53
+ updateCompanyInfo(id, fieldName, valueUpdate, updatedBy) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const mutation = mutations_1.UPDATE_COMPANY_INFOR;
56
+ const variables = {
57
+ orgId: this.orgId,
58
+ id,
59
+ fieldName,
60
+ valueUpdate,
61
+ updatedBy,
62
+ };
63
+ try {
64
+ const response = yield this.graphqlMutation(mutation, variables);
65
+ return response.updateCompanyInfo;
66
+ }
67
+ catch (error) {
68
+ console.log(`Error in updateCompanyInfo: ${error}`);
69
+ throw error;
70
+ }
71
+ });
72
+ }
73
+ updateCustomer(id, customerItem, updatedBy) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const mutation = mutations_1.UPDATE_CUSTOMER_V2;
76
+ const variables = {
77
+ tenantId: this.orgId,
78
+ id,
79
+ updateCustomerRequest: customerItem,
80
+ updatedBy,
81
+ };
82
+ try {
83
+ const response = yield this.graphqlMutation(mutation, variables);
84
+ return response.updateCustomerV2;
85
+ }
86
+ catch (error) {
87
+ console.log(`Error in updateCustomerV2: ${error}`);
88
+ throw error;
89
+ }
90
+ });
91
+ }
92
+ getCustomerById(id) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const query = queries_1.GET_CUSTOMER_BY_ID;
95
+ const variables = {
96
+ id,
97
+ };
98
+ try {
99
+ const response = yield this.graphqlQuery(query, variables);
100
+ return response.getCustomerById;
101
+ }
102
+ catch (error) {
103
+ console.log(`Error in getCustomerById: ${error}`);
104
+ throw error;
105
+ }
106
+ });
107
+ }
108
+ searchCompany(keyword, limit) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const query = queries_1.SEARCH_COMPANY;
111
+ const variables = {
112
+ keyword,
113
+ orgId: this.orgId,
114
+ limit,
115
+ };
116
+ try {
117
+ const response = yield this.graphqlQuery(query, variables);
118
+ return response.searchCompany;
119
+ }
120
+ catch (error) {
121
+ console.log(`Error in searchCompany: ${error}`);
122
+ throw error;
123
+ }
124
+ });
125
+ }
126
+ createCustomerV2(createCustomerRequest, createdBy) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ const mutation = mutations_1.CREATE_CUSTOMER_V2;
129
+ const variables = {
130
+ name: createCustomerRequest === null || createCustomerRequest === void 0 ? void 0 : createCustomerRequest.name,
131
+ phone: (createCustomerRequest === null || createCustomerRequest === void 0 ? void 0 : createCustomerRequest.phone) || "",
132
+ email: (createCustomerRequest === null || createCustomerRequest === void 0 ? void 0 : createCustomerRequest.email) || "",
133
+ birthDate: (createCustomerRequest === null || createCustomerRequest === void 0 ? void 0 : createCustomerRequest.birthDate) || null,
134
+ tenantId: this.orgId,
135
+ createdBy: createdBy,
136
+ };
137
+ try {
138
+ const response = yield this.graphqlMutation(mutation, variables);
139
+ return response.createCustomerV2;
140
+ }
141
+ catch (error) {
142
+ console.log(`Error in createCustomerV2: ${error}`);
143
+ throw error;
144
+ }
145
+ });
146
+ }
147
+ //PERSON/COMPANY
148
+ createCustomer(dataCustomerRequest, createdBy, type) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const dataCreateCustomer = {
151
+ name: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.name) || "",
152
+ phone: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.phone) || "",
153
+ email: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.email) || "",
154
+ birthDate: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.birthDate) || null,
155
+ };
156
+ const dataCreateCompany = {
157
+ name: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.name) || "",
158
+ phone: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.phone) || "",
159
+ email: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.email) || "",
160
+ address: (dataCustomerRequest === null || dataCustomerRequest === void 0 ? void 0 : dataCustomerRequest.address) || "",
161
+ };
162
+ if (type == "PERSON") {
163
+ const dataPERSON = yield this.createCustomerV2(dataCreateCustomer, createdBy);
164
+ return dataPERSON;
165
+ }
166
+ else if (type == "COMPANY") {
167
+ const dataCOMPANY = yield this.createCompany(dataCreateCompany, createdBy);
168
+ return dataCOMPANY;
169
+ }
170
+ });
171
+ }
172
+ searchCustomer(searchParams) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const query = queries_1.SEARCH_CUSTOMER;
175
+ const variables = {
176
+ keyword: searchParams.keyword,
177
+ type: searchParams.type,
178
+ startCreatedDate: searchParams.startCreatedDate,
179
+ endCreatedDate: searchParams.endCreatedDate,
180
+ memberLevel: searchParams.memberLevel,
181
+ partnerId: this.orgId,
182
+ currentPage: searchParams.currentPage,
183
+ pageSize: searchParams.pageSize,
184
+ };
185
+ try {
186
+ const response = yield this.graphqlQuery(query, variables);
187
+ return response.searchCustomers;
188
+ }
189
+ catch (error) {
190
+ console.log(`Error in searchCustomer: ${error}`);
191
+ throw error;
192
+ }
193
+ });
194
+ }
195
+ searchEmployees(searchParams) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const query = queries_1.SEARCH_EMPLOYEES;
198
+ const variables = {
199
+ keyword: searchParams.keyword,
200
+ partnerId: this.orgId,
201
+ positionShortName: searchParams.positionShortName,
202
+ };
203
+ try {
204
+ const response = yield this.graphqlQuery(query, variables);
205
+ return response.searchEmployees;
206
+ }
207
+ catch (error) {
208
+ console.log(`Error inseachEmployess: ${error}`);
209
+ throw error;
210
+ }
211
+ });
212
+ }
213
+ getPositionsByEmployeeId(employeeId) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ const query = queries_1.GET_POSTIONS_BY_EMPLOYEES_ID;
216
+ const variables = {
217
+ employeeId,
218
+ partnerId: this.orgId,
219
+ };
220
+ try {
221
+ const response = yield this.graphqlQuery(query, variables);
222
+ return response.getPositionsByEmployeeId;
223
+ }
224
+ catch (error) {
225
+ console.log(`Error in getPositionsByEmployeeId: ${error}`);
226
+ throw error;
227
+ }
228
+ });
229
+ }
230
+ getStoreChannelIdsByEmployeeId(employeeId) {
231
+ return __awaiter(this, void 0, void 0, function* () {
232
+ const query = queries_1.GET_STORE_CHANEL_IDS_BY_EMPLOYESS_ID;
233
+ const variables = {
234
+ employeeId,
235
+ partnerId: this.orgId,
236
+ };
237
+ try {
238
+ const response = yield this.graphqlQuery(query, variables);
239
+ return response.getStoreChannelIdsByEmployeeId;
240
+ }
241
+ catch (error) {
242
+ console.log(`Error in getStoreChannelIdsByEmployeeId: ${error}`);
243
+ throw error;
244
+ }
245
+ });
246
+ }
247
+ getEmployeesByStoreChannelId() {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ const query = queries_1.GET_EMPLOYEES_BY_STORE_CHANEL_ID;
250
+ const variables = {
251
+ storeChannelId: this.storeId,
252
+ partnerId: this.orgId,
253
+ };
254
+ try {
255
+ const response = yield this.graphqlQuery(query, variables);
256
+ return response.getEmployeesByStoreChannelId;
257
+ }
258
+ catch (error) {
259
+ console.log(`Error in getEmployeesByStoreChannelId: ${error}`);
260
+ throw error;
261
+ }
262
+ });
263
+ }
264
+ getCompanyByContactInfoId(contactId) {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ const query = queries_1.GET_COMPANY_BY_CONTACT_INFO_ID;
267
+ const variables = {
268
+ contactId,
269
+ partnerId: this.orgId,
270
+ };
271
+ try {
272
+ const response = yield this.graphqlQuery(query, variables);
273
+ return response.getCompanyByContactInfoId;
274
+ }
275
+ catch (error) {
276
+ console.log(`Error in getCompanyByContactInfoId: ${error}`);
277
+ throw error;
278
+ }
279
+ });
280
+ }
281
+ getContactInfosByCompanyId(companyId) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ const query = queries_1.GET_CONTACT_INFOS_BY_COMPANY_ID;
284
+ const variables = {
285
+ companyId,
286
+ partnerId: this.orgId,
287
+ };
288
+ try {
289
+ const response = yield this.graphqlQuery(query, variables);
290
+ return response.getContactInfosByCompanyId;
291
+ }
292
+ catch (error) {
293
+ console.log(`Error in getContactInfosByCompanyId: ${error}`);
294
+ throw error;
295
+ }
296
+ });
297
+ }
298
+ getProvinces() {
299
+ return __awaiter(this, void 0, void 0, function* () {
300
+ const query = queries_1.GET_PROVINCES;
301
+ const variables = {};
302
+ try {
303
+ const response = yield this.graphqlQuery(query, variables);
304
+ return response.getProvinces;
305
+ }
306
+ catch (error) {
307
+ console.log(`Error in getProvinces: ${error}`);
308
+ throw error;
309
+ }
310
+ });
311
+ }
312
+ getDistricts(provinceId) {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ const query = queries_1.GET_DISTRICTS;
315
+ const variables = {
316
+ provinceId,
317
+ };
318
+ try {
319
+ const response = yield this.graphqlQuery(query, variables);
320
+ return response.getDistricts;
321
+ }
322
+ catch (error) {
323
+ console.log(`Error in getDistricts: ${error}`);
324
+ throw error;
325
+ }
326
+ });
327
+ }
328
+ getWards(districtId) {
329
+ return __awaiter(this, void 0, void 0, function* () {
330
+ const query = queries_1.GET_WARDS;
331
+ const variables = {
332
+ districtId,
333
+ };
334
+ try {
335
+ const response = yield this.graphqlQuery(query, variables);
336
+ return response.getWards;
337
+ }
338
+ catch (error) {
339
+ console.log(`Error in getWards: ${error}`);
340
+ throw error;
341
+ }
342
+ });
343
+ }
344
+ }
345
+ exports.UserService = UserService;