npm_microservice 1.0.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.
Files changed (61) hide show
  1. package/dist/config.js +95 -0
  2. package/dist/services/BaseService.js +232 -0
  3. package/dist/services/Online/CourseLessonService.js +254 -0
  4. package/dist/services/Online/CourseService.js +271 -0
  5. package/dist/services/Online/StudentService.js +262 -0
  6. package/dist/services/SettingAppService.js +249 -0
  7. package/dist/services/SettingService.js +286 -0
  8. package/dist/services/app/CategoryService.js +248 -0
  9. package/dist/services/app/NewService.js +248 -0
  10. package/dist/services/auth.service.js +122 -0
  11. package/dist/services/call_center/CategoryService.js +251 -0
  12. package/dist/services/call_center/TicketActivityService.js +251 -0
  13. package/dist/services/call_center/TicketService.js +286 -0
  14. package/dist/services/call_center/TicketTemplateService.js +251 -0
  15. package/dist/services/call_center/TicketTopicService.js +254 -0
  16. package/dist/services/crm/ContactsService.js +251 -0
  17. package/dist/services/hr/AllowanceService.js +247 -0
  18. package/dist/services/hr/AnnualLeaveService.js +247 -0
  19. package/dist/services/hr/CategoryService.js +248 -0
  20. package/dist/services/hr/DepartmentService.js +247 -0
  21. package/dist/services/hr/DeviceService.js +252 -0
  22. package/dist/services/hr/DocumentService.js +248 -0
  23. package/dist/services/hr/EmployeeExtendService.js +247 -0
  24. package/dist/services/hr/EmployeeExtendTempService.js +247 -0
  25. package/dist/services/hr/EmployeeLeaveService.js +247 -0
  26. package/dist/services/hr/EmployeeQuitService.js +247 -0
  27. package/dist/services/hr/EmployeeService.js +247 -0
  28. package/dist/services/hr/EmployeeShiftService.js +264 -0
  29. package/dist/services/hr/HolidayService.js +248 -0
  30. package/dist/services/hr/JobTitleService.js +247 -0
  31. package/dist/services/hr/PositionService.js +247 -0
  32. package/dist/services/hr/ReasonTypeService.js +247 -0
  33. package/dist/services/hr/ResignationService.js +247 -0
  34. package/dist/services/hr/SalaryService.js +248 -0
  35. package/dist/services/hr/ScheduleOnlineService.js +248 -0
  36. package/dist/services/hr/ScheduleService.js +256 -0
  37. package/dist/services/hr/SettingDocumentService.js +248 -0
  38. package/dist/services/hr/ShiftService.js +252 -0
  39. package/dist/services/hr/ShiftsCustomerCareService.js +264 -0
  40. package/dist/services/hr/TicketExtendService.js +247 -0
  41. package/dist/services/hr/TicketService.js +251 -0
  42. package/dist/services/hr/TicketTypeService.js +247 -0
  43. package/dist/services/hr/TrackingConfirmService.js +252 -0
  44. package/dist/services/hr/TrackingErrorService.js +248 -0
  45. package/dist/services/inventory/InventoryService.js +258 -0
  46. package/dist/services/inventory/LogService.js +256 -0
  47. package/dist/services/inventory/ProductService.js +254 -0
  48. package/dist/services/inventory/ProductShipmentService.js +254 -0
  49. package/dist/services/inventory/StoreService.js +254 -0
  50. package/dist/services/inventory/SupplierService.js +254 -0
  51. package/dist/services/inventory/TransactionDetailService.js +254 -0
  52. package/dist/services/inventory/TransactionService.js +254 -0
  53. package/dist/services/notification/AppService.js +249 -0
  54. package/dist/services/org/BranchRequestService.js +248 -0
  55. package/dist/services/org/BranchService.js +252 -0
  56. package/dist/services/org/BranchToMacsService.js +248 -0
  57. package/dist/services/org/BrandService.js +248 -0
  58. package/dist/services/org/CitiesService.js +248 -0
  59. package/dist/services/org/LegalEntityService.js +248 -0
  60. package/dist/services/pm/NoteService.js +249 -0
  61. package/package.json +32 -0
@@ -0,0 +1,248 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // src/config.js
7
+ var require_config = __commonJS({
8
+ "src/config.js"(exports2, module2) {
9
+ require("dotenv").config();
10
+ var Redis = require("ioredis");
11
+ var redis2 = new Redis({
12
+ host: process.env.REDIS_HOST || "128.199.195.180",
13
+ port: process.env.REDIS_PORT || 6379,
14
+ password: process.env.REDIS_PASSWORD || "WZyB5Z7BRRgvrzuGzRwB"
15
+ });
16
+ var baseUrl = process.env.API_MICROSERVICE_URL;
17
+ var configRouteService = {
18
+ BASE_URL: baseUrl,
19
+ CallCenter: {
20
+ CategoryService: `${baseUrl}/call-center/ticket-categories`,
21
+ TicketService: `${baseUrl}/call-center/ticket`,
22
+ TicketActivityService: `${baseUrl}/call-center/ticket-activities`,
23
+ TicketTemplateService: `${baseUrl}/call-center/ticket-template`,
24
+ TicketTopicService: `${baseUrl}/call-center/ticket-topics`,
25
+ CallService: `${baseUrl}/call-center/calls`
26
+ },
27
+ Inventory: {
28
+ InventoryService: `${baseUrl}/inventory/inventory-products`,
29
+ LogService: `${baseUrl}/inventory/logs`,
30
+ ProductService: `${baseUrl}/inventory/products`,
31
+ ProductShipmentService: `${baseUrl}/inventory/products_shipment`,
32
+ StoreService: `${baseUrl}/inventory/stores`,
33
+ SupplierService: `${baseUrl}/inventory/supplier`,
34
+ TransactionService: `${baseUrl}/inventory/transaction`,
35
+ TransactionDetailService: `${baseUrl}/inventory/transaction_detail`
36
+ },
37
+ App: {
38
+ CategoryService: `${baseUrl}/app/category`,
39
+ NewService: `${baseUrl}/app/news`
40
+ },
41
+ Pm: {
42
+ NoteService: `${baseUrl}/pm/notes`
43
+ },
44
+ Crm: {
45
+ ContactService: `${baseUrl}/crm/contacts`
46
+ },
47
+ Notification: {
48
+ AppService: `${baseUrl}/notification/type/app`,
49
+ MailService: `${baseUrl}/notification/type/mail`,
50
+ SmsService: `${baseUrl}/notification/type/sms`,
51
+ ZnsService: `${baseUrl}/notification/type/zns`,
52
+ NotificationContactService: `${baseUrl}/notification/notification_contact`,
53
+ NotificationEmployeeService: `${baseUrl}/notification/notification_employee`,
54
+ TemplateService: `${baseUrl}/notification/template`
55
+ },
56
+ Org: {
57
+ BranchService: `${baseUrl}/org/branch`,
58
+ BranchRequestService: `${baseUrl}/org/branch_request`,
59
+ BranchToMacsService: `${baseUrl}/org/branch_to_mac`,
60
+ BrandService: `${baseUrl}/org/brand`,
61
+ CitiesService: `${baseUrl}/org/city`,
62
+ LegalEntityService: `${baseUrl}/org/legal_entities`
63
+ },
64
+ Hr: {
65
+ AllowanceService: `${baseUrl}/hr/allowance`,
66
+ CategoryService: `${baseUrl}/hr/setting/category`,
67
+ AnnualLeaveService: `${baseUrl}/hr/annual_leave`,
68
+ EmployeeService: `${baseUrl}/hr/employees`,
69
+ JobTitleService: `${baseUrl}/hr/setting/job_title`,
70
+ DepartmentService: `${baseUrl}/hr/departments`,
71
+ DeviceService: `${baseUrl}/hr/device`,
72
+ DocumentService: `${baseUrl}/hr/documents`,
73
+ EmployeeExtendService: `${baseUrl}/hr/employees/extend`,
74
+ EmployeeExtendTempService: `${baseUrl}/hr/employees/extend/temp`,
75
+ EmployeeLeaveService: `${baseUrl}/hr/employee_leave`,
76
+ EmployeeNotificationService: `${baseUrl}/hr/notification-employee`,
77
+ EmployeeQuitService: `${baseUrl}/hr/employee_quit`,
78
+ EmployeeShiftService: `${baseUrl}/hr/employee_shift`,
79
+ HolidayService: `${baseUrl}/hr/holidays`,
80
+ PositionService: `${baseUrl}/hr/positions`,
81
+ ReasonTypeService: `${baseUrl}/hr/setting/reason_type`,
82
+ ResignationService: `${baseUrl}/hr/resignations`,
83
+ SalaryService: `${baseUrl}/hr/employee_salary`,
84
+ ScheduleService: `${baseUrl}/hr/schedule`,
85
+ ScheduleOnlineService: `${baseUrl}/hr/schedule_online`,
86
+ ShiftService: `${baseUrl}/hr/setting/shifts`,
87
+ ShiftsCustomerCareService: `${baseUrl}/hr/setting/shifts-customer-care`,
88
+ TicketService: `${baseUrl}/hr/ticket`,
89
+ TicketExtendService: `${baseUrl}/hr/ticket/extend`,
90
+ TicketTypeService: `${baseUrl}/hr/ticket-type`,
91
+ TrackingConfirmService: `${baseUrl}/hr/tracking_confirm`,
92
+ TrackingErrorService: `${baseUrl}/hr/tracking-error`,
93
+ SettingDocumentService: `${baseUrl}/hr/setting/profile`
94
+ }
95
+ };
96
+ module2.exports = {
97
+ AUTHENTICATOR_PUBLIC_KEY: process.env.AUTHENTICATOR_PUBLIC_KEY || "",
98
+ API_MICROSERVICE_URL: process.env.API_MICROSERVICE_URL || "",
99
+ API_MICROSERVICE_TOKEN: process.env.API_MICROSERVICE_TOKEN || "",
100
+ CONFIG_ROUTER_SERVICE: configRouteService,
101
+ CONFIG_REDIS: redis2
102
+ };
103
+ }
104
+ });
105
+
106
+ // src/services/BaseService.js
107
+ var require_BaseService = __commonJS({
108
+ "src/services/BaseService.js"(exports2, module2) {
109
+ var axios = require("axios");
110
+ var qs = require("qs");
111
+ var { API_MICROSERVICE_TOKEN, CONFIG_REDIS } = require_config();
112
+ var BaseService2 = class {
113
+ baseUrl = "";
114
+ headers = {};
115
+ isCache = false;
116
+ service = null;
117
+ // nhớ set ở subclass
118
+ timeCache = 300;
119
+ // 300s = 5 phút
120
+ constructor(baseUrl = "", defaultHeaders = {}) {
121
+ this.baseUrl = baseUrl;
122
+ this.setHeader();
123
+ this.http = axios.create({
124
+ baseURL: this.baseUrl,
125
+ headers: this.headers,
126
+ paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "brackets", encode: true })
127
+ });
128
+ }
129
+ // Nhận: object headers, hoặc trực tiếp token string ("Bearer x"), hoặc không truyền gì (auto từ ENV)
130
+ setHeader(headers = {}) {
131
+ var Authorization = `Bearer ${process.env.API_MICROSERVICE_TOKEN}`;
132
+ if (headers && headers.Authorization) Authorization = headers.Authorization;
133
+ if (headers && headers.authorization) Authorization = headers.authorization;
134
+ this.headers = {
135
+ ...this.headers || {},
136
+ Authorization
137
+ };
138
+ return this;
139
+ }
140
+ buildCacheKey(path, params = {}) {
141
+ const q = qs.stringify(params, { arrayFormat: "brackets", encode: true });
142
+ const full = `${path}${q ? "?" + q : ""}`;
143
+ const service = this.service || "unknown";
144
+ return `gateway.${service}.urls:${full}`;
145
+ }
146
+ async request(method, url, options = {}, cacheKey = null) {
147
+ var _a, _b, _c;
148
+ const isGet = method.toLowerCase() === "get";
149
+ if (isGet && this.isCache) {
150
+ cacheKey = cacheKey ? cacheKey : this.buildCacheKey(url, options.params);
151
+ const cached = await redis.get(cacheKey);
152
+ if (cached) {
153
+ console.log(`[CACHE HIT] ${cacheKey}`);
154
+ return JSON.parse(cached);
155
+ }
156
+ }
157
+ try {
158
+ if (method.toLowerCase() === "get") {
159
+ let q = qs.stringify(options.params || {}, {
160
+ arrayFormat: "brackets",
161
+ encode: true
162
+ });
163
+ console.log(`[HTTP GET] ${url}${q ? "?" + q : ""}`);
164
+ } else {
165
+ console.log(`[HTTP ${method.toUpperCase()}] ${url}`);
166
+ }
167
+ if (options.params) console.log("Query:", options.params);
168
+ if (options.data) console.log("Body:", options.data);
169
+ const res = await this.http.request({
170
+ method,
171
+ url,
172
+ // dùng path vì đã set baseURL
173
+ headers: this.headers,
174
+ ...options
175
+ });
176
+ const data = res.data;
177
+ if (isGet && this.isCache) {
178
+ cacheKey = cacheKey ? cacheKey : this.buildCacheKey(url, options.params);
179
+ await redis.set(cacheKey, JSON.stringify(data), "EX", this.timeCache);
180
+ console.log(`[CACHE SET] ${cacheKey} - time ${this.timeCache}s`);
181
+ }
182
+ return data;
183
+ } catch (error) {
184
+ var safeError = {
185
+ // message: error.message || "Request failed",
186
+ statusCode: ((_a = error.response) == null ? void 0 : _a.status) || 500,
187
+ ...(_b = error.response) == null ? void 0 : _b.data
188
+ };
189
+ if (safeError.statusCode == 404) {
190
+ let q = qs.stringify(options.params || {}, {
191
+ arrayFormat: "brackets",
192
+ encode: true
193
+ });
194
+ return {
195
+ statusCode: 404,
196
+ status: "error",
197
+ messag: `[HTTP GET] ${url}${q ? "?" + q : ""} not found`
198
+ };
199
+ }
200
+ console.error(
201
+ `[${method.toUpperCase()}] ${url} failed:`,
202
+ safeError,
203
+ (_c = error.response) == null ? void 0 : _c.data
204
+ );
205
+ return {
206
+ error: true,
207
+ ...safeError
208
+ };
209
+ }
210
+ }
211
+ async all(query = {}) {
212
+ if (query.order_by && Array.isArray(query.order_by)) {
213
+ query.order_by = query.order_by.slice(0, 2);
214
+ if (query.order_by[1] && !["asc", "desc"].includes(query.order_by[1])) {
215
+ query.order_by[1] = "asc";
216
+ }
217
+ }
218
+ return this.request("get", this.baseUrl, { params: query });
219
+ }
220
+ async detail(id) {
221
+ const cacheKey = this.isCache ? `gateway.${this.service}.${id}` : null;
222
+ return this.request("get", `${this.baseUrl}/${id}`);
223
+ }
224
+ async create(data) {
225
+ return this.request("post", this.baseUrl, { data });
226
+ }
227
+ async update(id, data) {
228
+ return this.request("put", `${this.baseUrl}/${id}`, { data });
229
+ }
230
+ async delete(id) {
231
+ return this.request("delete", `${this.baseUrl}/${id}`);
232
+ }
233
+ };
234
+ module2.exports = BaseService2;
235
+ }
236
+ });
237
+
238
+ // src/services/hr/CategoryService.js
239
+ var BaseService = require_BaseService();
240
+ var { CONFIG_ROUTER_SERVICE } = require_config();
241
+ var CategoryService = class extends BaseService {
242
+ constructor() {
243
+ super(CONFIG_ROUTER_SERVICE.Hr.CategoryService);
244
+ this.service = "Hr.CategoryService";
245
+ this.isCache = true;
246
+ }
247
+ };
248
+ module.exports = CategoryService;
@@ -0,0 +1,247 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // src/config.js
7
+ var require_config = __commonJS({
8
+ "src/config.js"(exports2, module2) {
9
+ require("dotenv").config();
10
+ var Redis = require("ioredis");
11
+ var redis2 = new Redis({
12
+ host: process.env.REDIS_HOST || "128.199.195.180",
13
+ port: process.env.REDIS_PORT || 6379,
14
+ password: process.env.REDIS_PASSWORD || "WZyB5Z7BRRgvrzuGzRwB"
15
+ });
16
+ var baseUrl = process.env.API_MICROSERVICE_URL;
17
+ var configRouteService = {
18
+ BASE_URL: baseUrl,
19
+ CallCenter: {
20
+ CategoryService: `${baseUrl}/call-center/ticket-categories`,
21
+ TicketService: `${baseUrl}/call-center/ticket`,
22
+ TicketActivityService: `${baseUrl}/call-center/ticket-activities`,
23
+ TicketTemplateService: `${baseUrl}/call-center/ticket-template`,
24
+ TicketTopicService: `${baseUrl}/call-center/ticket-topics`,
25
+ CallService: `${baseUrl}/call-center/calls`
26
+ },
27
+ Inventory: {
28
+ InventoryService: `${baseUrl}/inventory/inventory-products`,
29
+ LogService: `${baseUrl}/inventory/logs`,
30
+ ProductService: `${baseUrl}/inventory/products`,
31
+ ProductShipmentService: `${baseUrl}/inventory/products_shipment`,
32
+ StoreService: `${baseUrl}/inventory/stores`,
33
+ SupplierService: `${baseUrl}/inventory/supplier`,
34
+ TransactionService: `${baseUrl}/inventory/transaction`,
35
+ TransactionDetailService: `${baseUrl}/inventory/transaction_detail`
36
+ },
37
+ App: {
38
+ CategoryService: `${baseUrl}/app/category`,
39
+ NewService: `${baseUrl}/app/news`
40
+ },
41
+ Pm: {
42
+ NoteService: `${baseUrl}/pm/notes`
43
+ },
44
+ Crm: {
45
+ ContactService: `${baseUrl}/crm/contacts`
46
+ },
47
+ Notification: {
48
+ AppService: `${baseUrl}/notification/type/app`,
49
+ MailService: `${baseUrl}/notification/type/mail`,
50
+ SmsService: `${baseUrl}/notification/type/sms`,
51
+ ZnsService: `${baseUrl}/notification/type/zns`,
52
+ NotificationContactService: `${baseUrl}/notification/notification_contact`,
53
+ NotificationEmployeeService: `${baseUrl}/notification/notification_employee`,
54
+ TemplateService: `${baseUrl}/notification/template`
55
+ },
56
+ Org: {
57
+ BranchService: `${baseUrl}/org/branch`,
58
+ BranchRequestService: `${baseUrl}/org/branch_request`,
59
+ BranchToMacsService: `${baseUrl}/org/branch_to_mac`,
60
+ BrandService: `${baseUrl}/org/brand`,
61
+ CitiesService: `${baseUrl}/org/city`,
62
+ LegalEntityService: `${baseUrl}/org/legal_entities`
63
+ },
64
+ Hr: {
65
+ AllowanceService: `${baseUrl}/hr/allowance`,
66
+ CategoryService: `${baseUrl}/hr/setting/category`,
67
+ AnnualLeaveService: `${baseUrl}/hr/annual_leave`,
68
+ EmployeeService: `${baseUrl}/hr/employees`,
69
+ JobTitleService: `${baseUrl}/hr/setting/job_title`,
70
+ DepartmentService: `${baseUrl}/hr/departments`,
71
+ DeviceService: `${baseUrl}/hr/device`,
72
+ DocumentService: `${baseUrl}/hr/documents`,
73
+ EmployeeExtendService: `${baseUrl}/hr/employees/extend`,
74
+ EmployeeExtendTempService: `${baseUrl}/hr/employees/extend/temp`,
75
+ EmployeeLeaveService: `${baseUrl}/hr/employee_leave`,
76
+ EmployeeNotificationService: `${baseUrl}/hr/notification-employee`,
77
+ EmployeeQuitService: `${baseUrl}/hr/employee_quit`,
78
+ EmployeeShiftService: `${baseUrl}/hr/employee_shift`,
79
+ HolidayService: `${baseUrl}/hr/holidays`,
80
+ PositionService: `${baseUrl}/hr/positions`,
81
+ ReasonTypeService: `${baseUrl}/hr/setting/reason_type`,
82
+ ResignationService: `${baseUrl}/hr/resignations`,
83
+ SalaryService: `${baseUrl}/hr/employee_salary`,
84
+ ScheduleService: `${baseUrl}/hr/schedule`,
85
+ ScheduleOnlineService: `${baseUrl}/hr/schedule_online`,
86
+ ShiftService: `${baseUrl}/hr/setting/shifts`,
87
+ ShiftsCustomerCareService: `${baseUrl}/hr/setting/shifts-customer-care`,
88
+ TicketService: `${baseUrl}/hr/ticket`,
89
+ TicketExtendService: `${baseUrl}/hr/ticket/extend`,
90
+ TicketTypeService: `${baseUrl}/hr/ticket-type`,
91
+ TrackingConfirmService: `${baseUrl}/hr/tracking_confirm`,
92
+ TrackingErrorService: `${baseUrl}/hr/tracking-error`,
93
+ SettingDocumentService: `${baseUrl}/hr/setting/profile`
94
+ }
95
+ };
96
+ module2.exports = {
97
+ AUTHENTICATOR_PUBLIC_KEY: process.env.AUTHENTICATOR_PUBLIC_KEY || "",
98
+ API_MICROSERVICE_URL: process.env.API_MICROSERVICE_URL || "",
99
+ API_MICROSERVICE_TOKEN: process.env.API_MICROSERVICE_TOKEN || "",
100
+ CONFIG_ROUTER_SERVICE: configRouteService,
101
+ CONFIG_REDIS: redis2
102
+ };
103
+ }
104
+ });
105
+
106
+ // src/services/BaseService.js
107
+ var require_BaseService = __commonJS({
108
+ "src/services/BaseService.js"(exports2, module2) {
109
+ var axios = require("axios");
110
+ var qs = require("qs");
111
+ var { API_MICROSERVICE_TOKEN, CONFIG_REDIS } = require_config();
112
+ var BaseService2 = class {
113
+ baseUrl = "";
114
+ headers = {};
115
+ isCache = false;
116
+ service = null;
117
+ // nhớ set ở subclass
118
+ timeCache = 300;
119
+ // 300s = 5 phút
120
+ constructor(baseUrl = "", defaultHeaders = {}) {
121
+ this.baseUrl = baseUrl;
122
+ this.setHeader();
123
+ this.http = axios.create({
124
+ baseURL: this.baseUrl,
125
+ headers: this.headers,
126
+ paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "brackets", encode: true })
127
+ });
128
+ }
129
+ // Nhận: object headers, hoặc trực tiếp token string ("Bearer x"), hoặc không truyền gì (auto từ ENV)
130
+ setHeader(headers = {}) {
131
+ var Authorization = `Bearer ${process.env.API_MICROSERVICE_TOKEN}`;
132
+ if (headers && headers.Authorization) Authorization = headers.Authorization;
133
+ if (headers && headers.authorization) Authorization = headers.authorization;
134
+ this.headers = {
135
+ ...this.headers || {},
136
+ Authorization
137
+ };
138
+ return this;
139
+ }
140
+ buildCacheKey(path, params = {}) {
141
+ const q = qs.stringify(params, { arrayFormat: "brackets", encode: true });
142
+ const full = `${path}${q ? "?" + q : ""}`;
143
+ const service = this.service || "unknown";
144
+ return `gateway.${service}.urls:${full}`;
145
+ }
146
+ async request(method, url, options = {}, cacheKey = null) {
147
+ var _a, _b, _c;
148
+ const isGet = method.toLowerCase() === "get";
149
+ if (isGet && this.isCache) {
150
+ cacheKey = cacheKey ? cacheKey : this.buildCacheKey(url, options.params);
151
+ const cached = await redis.get(cacheKey);
152
+ if (cached) {
153
+ console.log(`[CACHE HIT] ${cacheKey}`);
154
+ return JSON.parse(cached);
155
+ }
156
+ }
157
+ try {
158
+ if (method.toLowerCase() === "get") {
159
+ let q = qs.stringify(options.params || {}, {
160
+ arrayFormat: "brackets",
161
+ encode: true
162
+ });
163
+ console.log(`[HTTP GET] ${url}${q ? "?" + q : ""}`);
164
+ } else {
165
+ console.log(`[HTTP ${method.toUpperCase()}] ${url}`);
166
+ }
167
+ if (options.params) console.log("Query:", options.params);
168
+ if (options.data) console.log("Body:", options.data);
169
+ const res = await this.http.request({
170
+ method,
171
+ url,
172
+ // dùng path vì đã set baseURL
173
+ headers: this.headers,
174
+ ...options
175
+ });
176
+ const data = res.data;
177
+ if (isGet && this.isCache) {
178
+ cacheKey = cacheKey ? cacheKey : this.buildCacheKey(url, options.params);
179
+ await redis.set(cacheKey, JSON.stringify(data), "EX", this.timeCache);
180
+ console.log(`[CACHE SET] ${cacheKey} - time ${this.timeCache}s`);
181
+ }
182
+ return data;
183
+ } catch (error) {
184
+ var safeError = {
185
+ // message: error.message || "Request failed",
186
+ statusCode: ((_a = error.response) == null ? void 0 : _a.status) || 500,
187
+ ...(_b = error.response) == null ? void 0 : _b.data
188
+ };
189
+ if (safeError.statusCode == 404) {
190
+ let q = qs.stringify(options.params || {}, {
191
+ arrayFormat: "brackets",
192
+ encode: true
193
+ });
194
+ return {
195
+ statusCode: 404,
196
+ status: "error",
197
+ messag: `[HTTP GET] ${url}${q ? "?" + q : ""} not found`
198
+ };
199
+ }
200
+ console.error(
201
+ `[${method.toUpperCase()}] ${url} failed:`,
202
+ safeError,
203
+ (_c = error.response) == null ? void 0 : _c.data
204
+ );
205
+ return {
206
+ error: true,
207
+ ...safeError
208
+ };
209
+ }
210
+ }
211
+ async all(query = {}) {
212
+ if (query.order_by && Array.isArray(query.order_by)) {
213
+ query.order_by = query.order_by.slice(0, 2);
214
+ if (query.order_by[1] && !["asc", "desc"].includes(query.order_by[1])) {
215
+ query.order_by[1] = "asc";
216
+ }
217
+ }
218
+ return this.request("get", this.baseUrl, { params: query });
219
+ }
220
+ async detail(id) {
221
+ const cacheKey = this.isCache ? `gateway.${this.service}.${id}` : null;
222
+ return this.request("get", `${this.baseUrl}/${id}`);
223
+ }
224
+ async create(data) {
225
+ return this.request("post", this.baseUrl, { data });
226
+ }
227
+ async update(id, data) {
228
+ return this.request("put", `${this.baseUrl}/${id}`, { data });
229
+ }
230
+ async delete(id) {
231
+ return this.request("delete", `${this.baseUrl}/${id}`);
232
+ }
233
+ };
234
+ module2.exports = BaseService2;
235
+ }
236
+ });
237
+
238
+ // src/services/hr/DepartmentService.js
239
+ var BaseService = require_BaseService();
240
+ var { CONFIG_ROUTER_SERVICE } = require_config();
241
+ var DepartmentService = class extends BaseService {
242
+ constructor() {
243
+ super(CONFIG_ROUTER_SERVICE.Hr.DepartmentService);
244
+ this.service = "DepartmentService";
245
+ }
246
+ };
247
+ module.exports = DepartmentService;