@longvansoftware/storefront-js-client 0.0.1 → 0.0.3
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/README.md +93 -93
- package/dist/constants/graphql/mutations/authorizationMutations.d.ts +7 -0
- package/dist/constants/graphql/mutations/authorizationMutations.js +99 -0
- package/dist/constants/graphql/mutations/crmMutations.d.ts +8 -0
- package/dist/constants/graphql/mutations/crmMutations.js +368 -0
- package/dist/constants/graphql/mutations/userMutations.d.ts +4 -0
- package/dist/constants/graphql/mutations/userMutations.js +116 -0
- package/dist/constants/graphql/queries/crmQueries.d.ts +1 -0
- package/dist/constants/graphql/queries/crmQueries.js +45 -0
- package/dist/constants/graphql/queries/productQueries.d.ts +9 -0
- package/dist/constants/graphql/queries/productQueries.js +368 -0
- package/dist/constants/interfaces/authorization.d.ts +82 -0
- package/dist/constants/interfaces/authorization.js +2 -0
- package/dist/constants/interfaces/crm.d.ts +218 -0
- package/dist/constants/interfaces/crm.js +2 -0
- package/dist/constants/interfaces/product.d.ts +61 -0
- package/dist/constants/interfaces/product.js +2 -0
- package/dist/constants/interfaces/user.d.ts +49 -0
- package/dist/constants/interfaces/user.js +2 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +17 -0
- package/dist/modules/authorization/graphql.d.ts +15 -0
- package/dist/modules/authorization/graphql.js +116 -0
- package/dist/modules/crm/graphql.d.ts +19 -0
- package/dist/modules/crm/graphql.js +291 -0
- package/dist/modules/product/graphql.d.ts +19 -0
- package/dist/modules/product/graphql.js +180 -0
- package/dist/modules/user/graphql.d.ts +14 -0
- package/dist/modules/user/graphql.js +156 -0
- package/package.json +36 -36
|
@@ -0,0 +1,291 @@
|
|
|
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.CRMModuleGraphQL = void 0;
|
|
13
|
+
const graphql_request_1 = require("graphql-request");
|
|
14
|
+
const crmMutations_1 = require("../../constants/graphql/mutations/crmMutations");
|
|
15
|
+
const crmQueries_1 = require("../../constants/graphql/queries/crmQueries");
|
|
16
|
+
class CRMModuleGraphQL {
|
|
17
|
+
constructor(endpoint, partnerId, storeId) {
|
|
18
|
+
this.endpoint = endpoint;
|
|
19
|
+
this.partnerId = partnerId;
|
|
20
|
+
this.storeId = storeId;
|
|
21
|
+
this.client = new graphql_request_1.GraphQLClient(endpoint);
|
|
22
|
+
}
|
|
23
|
+
getClient() {
|
|
24
|
+
return this.client;
|
|
25
|
+
}
|
|
26
|
+
addOpportunity(addOpportunityRequest, performerId) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const variables = {
|
|
29
|
+
partyId: this.partnerId,
|
|
30
|
+
addOpportunityRequest,
|
|
31
|
+
performerId,
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const response = yield this.client.request(crmMutations_1.ADD_OPPORTUNITY_MUTATION, variables);
|
|
35
|
+
if (response && response.addOpportunity) {
|
|
36
|
+
return response.addOpportunity;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error("No opportunity returned from the backend");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.response &&
|
|
44
|
+
error.response.errors &&
|
|
45
|
+
error.response.errors.length > 0) {
|
|
46
|
+
const errorMessage = error.response.errors[0].message;
|
|
47
|
+
throw new Error(errorMessage);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("Unknown error occurred");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
getListOpportunity(performerId, getOpportunityRequest) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const variables = {
|
|
59
|
+
partyId: this.partnerId,
|
|
60
|
+
performerId,
|
|
61
|
+
getOpportunityRequest,
|
|
62
|
+
};
|
|
63
|
+
try {
|
|
64
|
+
const response = yield this.client.request(crmQueries_1.GET_LIST_OPPORTUNITY_QUERY, variables);
|
|
65
|
+
if (response && response.getDataOpportunity) {
|
|
66
|
+
return response.getDataOpportunity; // Trả về phần tử getDataOpportunity từ response
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error("No list opportunity returned from the backend");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.response &&
|
|
74
|
+
error.response.errors &&
|
|
75
|
+
error.response.errors.length > 0) {
|
|
76
|
+
const errorMessage = error.response.errors[0].message;
|
|
77
|
+
throw new Error(errorMessage);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error("Unknown error occurred");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
getListTodo(workEffortId) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const variables = {
|
|
88
|
+
partyId: this.partnerId,
|
|
89
|
+
workEffortId
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
const response = yield this.client.request(crmMutations_1.GET_LIST_TODO, variables);
|
|
93
|
+
if (response && response.getListTodo) {
|
|
94
|
+
return response.getListTodo; // Trả về phần tử getDataOpportunity từ response
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new Error("No list todo returned from the backend");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error.response &&
|
|
102
|
+
error.response.errors &&
|
|
103
|
+
error.response.errors.length > 0) {
|
|
104
|
+
const errorMessage = error.response.errors[0].message;
|
|
105
|
+
throw new Error(errorMessage);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error("Unknown error occurred");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
getListWorkEffortType(id) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const variables = {
|
|
116
|
+
partyId: this.partnerId,
|
|
117
|
+
id
|
|
118
|
+
};
|
|
119
|
+
try {
|
|
120
|
+
const response = yield this.client.request(crmMutations_1.GET_LIST_WORK_EFFORT_TYPE, variables);
|
|
121
|
+
if (response && response.getListWorkEffortType) {
|
|
122
|
+
return response.getListWorkEffortType; // Trả về phần tử getDataOpportunity từ response
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw new Error("No getListWorkEffortType returned from the backend");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error.response &&
|
|
130
|
+
error.response.errors &&
|
|
131
|
+
error.response.errors.length > 0) {
|
|
132
|
+
const errorMessage = error.response.errors[0].message;
|
|
133
|
+
throw new Error(errorMessage);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error("Unknown error occurred");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
updateStatusAttachmentById(performerId, attachmentId, status) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const variables = {
|
|
144
|
+
performerId,
|
|
145
|
+
attachmentId,
|
|
146
|
+
status
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
const response = yield this.client.request(crmMutations_1.UPDATE_STATUS_ATTACHMENT_BY_ID, variables);
|
|
150
|
+
if (response && response.updateStatusAttachmentById) {
|
|
151
|
+
return response.updateStatusAttachmentById; // Trả về phần tử getDataOpportunity từ response
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
throw new Error("No updateStatusAttachmentById returned from the backend");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error.response &&
|
|
159
|
+
error.response.errors &&
|
|
160
|
+
error.response.errors.length > 0) {
|
|
161
|
+
const errorMessage = error.response.errors[0].message;
|
|
162
|
+
throw new Error(errorMessage);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new Error("Unknown error occurred");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
updateWorkEffortDescription(performerId, workEffortId, description) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const variables = {
|
|
173
|
+
performerId,
|
|
174
|
+
workEffortId,
|
|
175
|
+
description
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
const response = yield this.client.request(crmMutations_1.UPDATE_WORK_EFFORT_DESCRIPTION, variables);
|
|
179
|
+
if (response && response.updateWorkEffortDescription) {
|
|
180
|
+
return response.updateWorkEffortDescription; // Trả về phần tử getDataOpportunity từ response
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
throw new Error("No updateWorkEffortDescription returned from the backend");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (error.response &&
|
|
188
|
+
error.response.errors &&
|
|
189
|
+
error.response.errors.length > 0) {
|
|
190
|
+
const errorMessage = error.response.errors[0].message;
|
|
191
|
+
throw new Error(errorMessage);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new Error("Unknown error occurred");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
updateWorkEffortName(performerId, workEffortId, name) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const variables = {
|
|
202
|
+
partyId: this.partnerId,
|
|
203
|
+
performerId,
|
|
204
|
+
workEffortId,
|
|
205
|
+
name
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
const response = yield this.client.request(crmMutations_1.UPDATE_WORK_EFFORT_NAME, variables);
|
|
209
|
+
if (response && response.updateWorkEffortName) {
|
|
210
|
+
return response.updateWorkEffortName; // Trả về phần tử getDataOpportunity từ response
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw new Error("No updateWorkEffortName returned from the backend");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
if (error.response &&
|
|
218
|
+
error.response.errors &&
|
|
219
|
+
error.response.errors.length > 0) {
|
|
220
|
+
const errorMessage = error.response.errors[0].message;
|
|
221
|
+
throw new Error(errorMessage);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new Error("Unknown error occurred");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
updateWorkEffortStatus(performerId, workEffortId, source, status) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const variables = {
|
|
232
|
+
partyId: this.partnerId,
|
|
233
|
+
performerId,
|
|
234
|
+
workEffortId,
|
|
235
|
+
source,
|
|
236
|
+
status
|
|
237
|
+
};
|
|
238
|
+
try {
|
|
239
|
+
const response = yield this.client.request(crmMutations_1.UPDATE_WORK_EFFORT_STATUS, variables);
|
|
240
|
+
if (response && response.updateWorkEffortStatus) {
|
|
241
|
+
return response.updateWorkEffortStatus; // Trả về phần tử getDataOpportunity từ response
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
throw new Error("No updateWorkEffortStatus returned from the backend");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
if (error.response &&
|
|
249
|
+
error.response.errors &&
|
|
250
|
+
error.response.errors.length > 0) {
|
|
251
|
+
const errorMessage = error.response.errors[0].message;
|
|
252
|
+
throw new Error(errorMessage);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
throw new Error("Unknown error occurred");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
addAttachmentForWorkEffort(performerId, workEffortId, attachments) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
const variables = {
|
|
263
|
+
partyId: this.partnerId,
|
|
264
|
+
performerId,
|
|
265
|
+
workEffortId,
|
|
266
|
+
attachments,
|
|
267
|
+
};
|
|
268
|
+
try {
|
|
269
|
+
const response = yield this.client.request(crmMutations_1.ADD_ATTACHMENT_FOR_WORK_EFFORT, variables);
|
|
270
|
+
if (response && response.addAttachmentForWorkEffort) {
|
|
271
|
+
return response.addAttachmentForWorkEffort; // Trả về phần tử getDataOpportunity từ response
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
throw new Error("No addAttachmentForWorkEffort returned from the backend");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error.response &&
|
|
279
|
+
error.response.errors &&
|
|
280
|
+
error.response.errors.length > 0) {
|
|
281
|
+
const errorMessage = error.response.errors[0].message;
|
|
282
|
+
throw new Error(errorMessage);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
throw new Error("Unknown error occurred");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.CRMModuleGraphQL = CRMModuleGraphQL;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GraphQLClient } from "graphql-request";
|
|
2
|
+
import { Product, Category, ProductFilterOptions, CategoryFilterOptions, Brand } from "../../constants/interfaces/product";
|
|
3
|
+
export declare class ProductModuleGraphQL {
|
|
4
|
+
private client;
|
|
5
|
+
private endpoint;
|
|
6
|
+
private partnerId;
|
|
7
|
+
private storeId;
|
|
8
|
+
constructor(endpoint: string, partnerId: string, storeId: string);
|
|
9
|
+
getClient(): GraphQLClient;
|
|
10
|
+
getProductById(productId: string): Promise<Product | null>;
|
|
11
|
+
getProductBySlug(productSlug: string): Promise<Product | null>;
|
|
12
|
+
getSimpleProducts(productFilterOptions: ProductFilterOptions): Promise<Product[] | null>;
|
|
13
|
+
getCategories(categoryFilterOptions: CategoryFilterOptions): Promise<Category[] | null>;
|
|
14
|
+
getCategoryByHandle(handle: string): Promise<Category | null>;
|
|
15
|
+
getCategoryById(categoryId: string): Promise<Category | null>;
|
|
16
|
+
getBrands(): Promise<Brand[] | null>;
|
|
17
|
+
getBrandsByCategory(categoryId: string): Promise<Brand[] | null>;
|
|
18
|
+
getBrandDetail(brandId: string): Promise<Brand | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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.ProductModuleGraphQL = void 0;
|
|
13
|
+
const graphql_request_1 = require("graphql-request");
|
|
14
|
+
const productQueries_1 = require("../../constants/graphql/queries/productQueries");
|
|
15
|
+
class ProductModuleGraphQL {
|
|
16
|
+
// Khởi tạo ProductModuleGraphQL với endpoint, partnerId, và storeId
|
|
17
|
+
constructor(endpoint, partnerId, storeId) {
|
|
18
|
+
this.endpoint = endpoint;
|
|
19
|
+
this.client = new graphql_request_1.GraphQLClient(endpoint);
|
|
20
|
+
this.partnerId = partnerId;
|
|
21
|
+
this.storeId = storeId;
|
|
22
|
+
}
|
|
23
|
+
getClient() {
|
|
24
|
+
return this.client;
|
|
25
|
+
}
|
|
26
|
+
// Phương thức để lấy thông tin sản phẩm bằng ID
|
|
27
|
+
getProductById(productId) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const variables = {
|
|
30
|
+
partnerId: this.partnerId,
|
|
31
|
+
storeChannel: this.storeId,
|
|
32
|
+
productId,
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
// Gửi yêu cầu GraphQL để lấy sản phẩm bằng ID
|
|
36
|
+
const { getProductById } = yield this.client.request(productQueries_1.GET_PRODUCT_BY_ID_QUERY, variables);
|
|
37
|
+
return getProductById;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
// Bắt lỗi nếu có lỗi xảy ra trong quá trình lấy sản phẩm
|
|
41
|
+
console.error("Error fetching product by ID:", error);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getProductBySlug(productSlug) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const variables = {
|
|
49
|
+
partnerId: this.partnerId,
|
|
50
|
+
storeChannel: this.storeId,
|
|
51
|
+
productSlug,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
// Gửi yêu cầu GraphQL để lấy sản phẩm bằng Slug
|
|
55
|
+
const { getProductBySlug } = yield this.client.request(productQueries_1.GET_PRODUCT_BY_SLUG_QUERY, variables);
|
|
56
|
+
return getProductBySlug;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// Bắt lỗi nếu có lỗi xảy ra trong quá trình lấy sản phẩm
|
|
60
|
+
console.error("Error fetching product by Slug:", error);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Phương thức để lấy danh sách các sản phẩm đơn giản dựa trên các tùy chọn bộ lọc
|
|
66
|
+
getSimpleProducts(productFilterOptions) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const variables = Object.assign({ partnerId: this.partnerId, storeChannel: this.storeId }, (productFilterOptions || {}));
|
|
69
|
+
try {
|
|
70
|
+
// Gửi yêu cầu GraphQL để lấy danh sách sản phẩm đơn giản
|
|
71
|
+
const { getSimpleProducts } = yield this.client.request(productQueries_1.GET_SIMPLE_PRODUCTS_QUERY, variables);
|
|
72
|
+
return getSimpleProducts;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
// Bắt lỗi nếu có lỗi xảy ra trong quá trình lấy danh sách sản phẩm
|
|
76
|
+
console.error("Error fetching simple products:", error);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
getCategories(categoryFilterOptions) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const variables = Object.assign({ partnerId: this.partnerId, storeChannel: this.storeId }, (categoryFilterOptions || {}));
|
|
84
|
+
try {
|
|
85
|
+
const { getCategories } = yield this.client.request(productQueries_1.GET_CATEGORIES_QUERY, variables);
|
|
86
|
+
return getCategories;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error("Error fetching categories:", error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getCategoryByHandle(handle) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const variables = {
|
|
97
|
+
partnerId: this.partnerId,
|
|
98
|
+
storeChannel: this.storeId,
|
|
99
|
+
handle,
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const { getCategoryByHandle } = yield this.client.request(productQueries_1.GET_CATEGORY_BY_HANDLE_QUERY, variables);
|
|
103
|
+
return getCategoryByHandle;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error("Error fetching category by handle:", error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getCategoryById(categoryId) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const variables = {
|
|
114
|
+
partnerId: this.partnerId,
|
|
115
|
+
storeChannel: this.storeId,
|
|
116
|
+
categoryId,
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
const { getCategoryById } = yield this.client.request(productQueries_1.GET_CATEGORY_BY_ID_QUERY, variables);
|
|
120
|
+
return getCategoryById;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error("Error fetching category by ID:", error);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getBrands() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const variables = {
|
|
131
|
+
partnerId: this.partnerId,
|
|
132
|
+
storeChannel: this.storeId,
|
|
133
|
+
enable: true,
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
const { getBrands } = yield this.client.request(productQueries_1.GET_BRANDS_QUERY, variables);
|
|
137
|
+
return getBrands;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error("Error fetching brands:", error);
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getBrandsByCategory(categoryId) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const variables = {
|
|
148
|
+
partnerId: this.partnerId,
|
|
149
|
+
storeChannel: this.storeId,
|
|
150
|
+
categoryId,
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
const { getBrandsByCategory } = yield this.client.request(productQueries_1.GET_BRANDS_BY_CATEGORY_QUERY, variables);
|
|
154
|
+
return getBrandsByCategory;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
console.error("Error fetching brands by category:", error);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
getBrandDetail(brandId) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const variables = {
|
|
165
|
+
partnerId: this.partnerId,
|
|
166
|
+
brandId,
|
|
167
|
+
storeChannel: this.storeId,
|
|
168
|
+
};
|
|
169
|
+
try {
|
|
170
|
+
const { getDetail } = yield this.client.request(productQueries_1.GET_BRAND_DETAIL_QUERY, variables);
|
|
171
|
+
return getDetail;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error("Error fetching brand detail:", error);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.ProductModuleGraphQL = ProductModuleGraphQL;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GraphQLClient } from "graphql-request";
|
|
2
|
+
import { CreateCompany, GetPersonByPartyIds, createCompanyRequest, updateCustomerRequest } from "../../constants/interfaces/user";
|
|
3
|
+
export declare class USERModuleGraphQL {
|
|
4
|
+
private client;
|
|
5
|
+
private endpoint;
|
|
6
|
+
private partnerId;
|
|
7
|
+
private storeId;
|
|
8
|
+
constructor(endpoint: string, partnerId: string, storeId: string);
|
|
9
|
+
getClient(): GraphQLClient;
|
|
10
|
+
createCompany(payload: createCompanyRequest, createdBy: string): Promise<CreateCompany>;
|
|
11
|
+
updateCompanyInfo(id: string, fieldName: string, valueUpdate: string, updatedBy: string): Promise<CreateCompany>;
|
|
12
|
+
updateCustomerV2(id: string, customerItem: updateCustomerRequest, updatedBy: string): Promise<CreateCompany>;
|
|
13
|
+
getPersonByPartyIds(partyIds: string[]): Promise<GetPersonByPartyIds>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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.USERModuleGraphQL = void 0;
|
|
13
|
+
const graphql_request_1 = require("graphql-request");
|
|
14
|
+
const userMutations_1 = require("../../constants/graphql/mutations/userMutations");
|
|
15
|
+
class USERModuleGraphQL {
|
|
16
|
+
constructor(endpoint, partnerId, storeId) {
|
|
17
|
+
this.endpoint = endpoint;
|
|
18
|
+
this.partnerId = partnerId;
|
|
19
|
+
this.storeId = storeId;
|
|
20
|
+
this.client = new graphql_request_1.GraphQLClient(endpoint);
|
|
21
|
+
}
|
|
22
|
+
getClient() {
|
|
23
|
+
return this.client;
|
|
24
|
+
}
|
|
25
|
+
createCompany(payload, createdBy) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const variables = {
|
|
28
|
+
orgId: this.partnerId,
|
|
29
|
+
createCompanyRequest: {
|
|
30
|
+
name: payload === null || payload === void 0 ? void 0 : payload.name,
|
|
31
|
+
phone: payload === null || payload === void 0 ? void 0 : payload.phone,
|
|
32
|
+
address: payload === null || payload === void 0 ? void 0 : payload.address,
|
|
33
|
+
},
|
|
34
|
+
createTaxCodeRequest: null,
|
|
35
|
+
createdBy,
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const response = yield this.client.request(userMutations_1.CREATE_COMPANY, variables);
|
|
39
|
+
if (response && response.createCompany) {
|
|
40
|
+
return response.createCompany;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error("No createCompany returned from the backend");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.response &&
|
|
48
|
+
error.response.errors &&
|
|
49
|
+
error.response.errors.length > 0) {
|
|
50
|
+
const errorMessage = error.response.errors[0].message;
|
|
51
|
+
throw new Error(errorMessage);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error("Unknown error occurred");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
updateCompanyInfo(id, fieldName, valueUpdate, updatedBy) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const variables = {
|
|
63
|
+
orgId: this.partnerId,
|
|
64
|
+
id,
|
|
65
|
+
fieldName,
|
|
66
|
+
valueUpdate,
|
|
67
|
+
updatedBy,
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const response = yield this.client.request(userMutations_1.UPDATE_COMPANY_INFOR, variables);
|
|
71
|
+
if (response && response.updateCompanyInfo) {
|
|
72
|
+
return response.updateCompanyInfo;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error("No updateCompanyInfo returned from the backend");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (error.response &&
|
|
80
|
+
error.response.errors &&
|
|
81
|
+
error.response.errors.length > 0) {
|
|
82
|
+
const errorMessage = error.response.errors[0].message;
|
|
83
|
+
throw new Error(errorMessage);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error("Unknown error occurred");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
;
|
|
92
|
+
updateCustomerV2(id, customerItem, updatedBy) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const variables = {
|
|
95
|
+
tenantId: this.partnerId,
|
|
96
|
+
id,
|
|
97
|
+
updateCustomerRequest: {
|
|
98
|
+
name: customerItem === null || customerItem === void 0 ? void 0 : customerItem.fullName,
|
|
99
|
+
phone: customerItem === null || customerItem === void 0 ? void 0 : customerItem.phone,
|
|
100
|
+
address: customerItem === null || customerItem === void 0 ? void 0 : customerItem.address
|
|
101
|
+
},
|
|
102
|
+
updatedBy,
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
const response = yield this.client.request(userMutations_1.UPDATE_CUSTOMER_V2, variables);
|
|
106
|
+
if (response && response.updateCustomerV2) {
|
|
107
|
+
return response.updateCustomerV2;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error("No updateCustomerV2 returned from the backend");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error.response &&
|
|
115
|
+
error.response.errors &&
|
|
116
|
+
error.response.errors.length > 0) {
|
|
117
|
+
const errorMessage = error.response.errors[0].message;
|
|
118
|
+
throw new Error(errorMessage);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
;
|
|
127
|
+
getPersonByPartyIds(partyIds) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const variables = {
|
|
130
|
+
partyIds
|
|
131
|
+
};
|
|
132
|
+
try {
|
|
133
|
+
const response = yield this.client.request(userMutations_1.GET_PERSON_BY_PARTY_IDS, variables);
|
|
134
|
+
if (response && response.getPersonByPartyIds) {
|
|
135
|
+
return response.getPersonByPartyIds;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
throw new Error("No getPersonByPartyIds returned from the backend");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error.response &&
|
|
143
|
+
error.response.errors &&
|
|
144
|
+
error.response.errors.length > 0) {
|
|
145
|
+
const errorMessage = error.response.errors[0].message;
|
|
146
|
+
throw new Error(errorMessage);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new Error(error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
;
|
|
155
|
+
}
|
|
156
|
+
exports.USERModuleGraphQL = USERModuleGraphQL;
|