npm_microservice 1.0.14 → 1.0.15

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/service.js CHANGED
@@ -2186,34 +2186,38 @@ var require_CategoryService4 = __commonJS({
2186
2186
  }
2187
2187
  });
2188
2188
 
2189
- // src/services/course/CourseService.js
2189
+ // src/services/online/CourseService.js
2190
2190
  var require_CourseService2 = __commonJS({
2191
- "src/services/course/CourseService.js"(exports2, module2) {
2191
+ "src/services/online/CourseService.js"(exports2, module2) {
2192
2192
  var BaseService = require_BaseService();
2193
- var { CONFIG_ROUTER_SERVICE } = require_config();
2193
+ var { CONFIG_ROUTER_SERVICE, API_MICROSERVICE_TOKEN } = require_config();
2194
2194
  var CourseService = class extends BaseService {
2195
2195
  constructor() {
2196
- super(CONFIG_ROUTER_SERVICE.Course.CourseService);
2197
- this.service = "Course.CourseService";
2196
+ super(CONFIG_ROUTER_SERVICE.CourseOnlineService, {
2197
+ Authorization: `Bearer ${API_MICROSERVICE_TOKEN}`
2198
+ });
2199
+ this.isCache = false;
2200
+ this.service = "course_online";
2198
2201
  }
2199
2202
  // có thể thêm method riêng cho user nếu cần
2200
- async detailSchedule(id, cacheOption = {}) {
2201
- const enableCache = cacheOption.isCache ?? this.isCache;
2202
- const cacheKey = enableCache ? `gateway.course_schedule.${id}` : null;
2203
- return this.request(
2204
- "get",
2205
- `${this.baseUrl}/${id}`,
2206
- {},
2207
- cacheKey,
2208
- cacheOption
2209
- );
2203
+ async detailSchedule(id) {
2204
+ let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/course/course_schedule/" + id;
2205
+ this.service = "course_schedule";
2206
+ return this.request("get", url);
2207
+ }
2208
+ async getLevel(id) {
2209
+ let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/lms/course-levels/" + id;
2210
+ this.service = "course_levels";
2211
+ return this.request("get", url);
2210
2212
  }
2211
2213
  async count(filter = {}) {
2212
2214
  let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/course/course/count";
2215
+ this.service = "course_online";
2213
2216
  return this.request("get", url, { params: filter });
2214
2217
  }
2215
2218
  async student(filter = {}) {
2216
2219
  let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/course/students";
2220
+ this.service = "course_online";
2217
2221
  return this.request("get", url, { params: filter });
2218
2222
  }
2219
2223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm_microservice",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -1,365 +0,0 @@
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({ quiet: true, override: true });
10
- var Redis = require("ioredis");
11
- var redis = 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
- Finance: {
20
- InvoicesService: `${baseUrl}/finance/invoices`,
21
- InvoicesCancelService: `${baseUrl}/finance/invoice_detail_cancel`,
22
- InvoicesDetailService: `${baseUrl}/finance/invoices-detail`,
23
- InvoicesLogsAssignService: `${baseUrl}/finance/invoices-logs-assign`,
24
- PaymentService: `${baseUrl}/finance/payments`,
25
- PaymentRequestService: `${baseUrl}/finance/payments-request`,
26
- VouchersService: `${baseUrl}/finance/vouchers`,
27
- VouchersCategoryService: `${baseUrl}/finance/vouchers-category`,
28
- WalletsService: `${baseUrl}/finance/wallets`,
29
- WalletTransactionService: `${baseUrl}/finance/wallet-transaction`
30
- },
31
- CallCenter: {
32
- CategoryService: `${baseUrl}/call-center/ticket-categories`,
33
- TicketService: `${baseUrl}/call-center/ticket`,
34
- TicketActivityService: `${baseUrl}/call-center/ticket-activities`,
35
- TicketTemplateService: `${baseUrl}/call-center/ticket-template`,
36
- TicketTopicService: `${baseUrl}/call-center/ticket-topics`,
37
- CallService: `${baseUrl}/call-center/calls`
38
- },
39
- Inventory: {
40
- InventoryService: `${baseUrl}/inventory/inventory-products`,
41
- LogService: `${baseUrl}/inventory/logs`,
42
- ProductService: `${baseUrl}/inventory/products`,
43
- ProductShipmentService: `${baseUrl}/inventory/products_shipment`,
44
- StoreService: `${baseUrl}/inventory/stores`,
45
- SupplierService: `${baseUrl}/inventory/supplier`,
46
- TransactionService: `${baseUrl}/inventory/transaction`,
47
- TransactionDetailService: `${baseUrl}/inventory/transaction_detail`
48
- },
49
- App: {
50
- CategoryService: `${baseUrl}/app/category`,
51
- NewService: `${baseUrl}/app/news`,
52
- BannerService: `${baseUrl}/app/banner`,
53
- AppTestService: `${baseUrl}/app/test`,
54
- RecommendedCourseService: `${baseUrl}/app/recommended_level`,
55
- SettingAppService: `${baseUrl}/app/setting`,
56
- TargetAppService: `${baseUrl}/app/target`
57
- },
58
- Course: {
59
- CategoryService: `${baseUrl}/course/category`,
60
- CourseService: `${baseUrl}/course/course`,
61
- CourseLessonService: `${baseUrl}/course/course_schedule`,
62
- StudentService: `${baseUrl}/course/students`
63
- },
64
- Asset: {
65
- AllocationDetailService: `${baseUrl}/asset/asset-allocation-detail`,
66
- BroadcastService: `${baseUrl}/asset/broadcast`,
67
- EntityAssetService: `${baseUrl}/asset/entity-asset`,
68
- SubAssetService: `${baseUrl}/asset/sub-asset`
69
- },
70
- Test: {
71
- TestService: `${baseUrl}/tests/tests`
72
- },
73
- Pm: {
74
- NoteService: `${baseUrl}/pm/notes`,
75
- TaskService: `${baseUrl}/pm/tasks`
76
- },
77
- Crm: {
78
- ContactService: `${baseUrl}/crm/contacts`,
79
- AccountsService: `${baseUrl}/crm/accounts`,
80
- CalendarContactService: `${baseUrl}/crm/calendar-contact`,
81
- CalendarsService: `${baseUrl}/crm/calendars`,
82
- CampaignService: `${baseUrl}/crm/campaigns`,
83
- CompanyService: `${baseUrl}/crm/company`,
84
- ContactDocumentService: `${baseUrl}/crm/contact-document`,
85
- ContactToCampaignService: `${baseUrl}/crm/contacts-campaign`,
86
- DeviceService: `${baseUrl}/crm/devices`,
87
- LeadsService: `${baseUrl}/crm/leads`,
88
- NotificationService: `${baseUrl}/crm/notifications`,
89
- NotificationContactService: `${baseUrl}/crm/notification-to-contact`,
90
- OpportunitiesService: `${baseUrl}/crm/opportunities`,
91
- SegmentsService: `${baseUrl}/crm/segments`
92
- },
93
- Notification: {
94
- AppService: `${baseUrl}/notification/type/app`,
95
- MailService: `${baseUrl}/notification/type/mail`,
96
- SmsService: `${baseUrl}/notification/type/sms`,
97
- ZnsService: `${baseUrl}/notification/type/zns`,
98
- NotificationContactService: `${baseUrl}/notification/notification_contact`,
99
- NotificationEmployeeService: `${baseUrl}/notification/notification_employee`,
100
- NotificationService: `${baseUrl}/notification`,
101
- TemplateService: `${baseUrl}/notification/template`
102
- },
103
- Org: {
104
- BranchService: `${baseUrl}/org/branch`,
105
- BranchRequestService: `${baseUrl}/org/branch_request`,
106
- BranchToMacsService: `${baseUrl}/org/branch_to_mac`,
107
- BrandService: `${baseUrl}/org/brand`,
108
- CitiesService: `${baseUrl}/org/city`,
109
- LegalEntityService: `${baseUrl}/org/legal_entities`
110
- },
111
- Lms: {
112
- AlbumService: `${baseUrl}/lms/album`,
113
- AlbumCategoryService: `${baseUrl}/lms/cate_album`,
114
- AlbumFileService: `${baseUrl}/lms/album_file`,
115
- ClassesService: `${baseUrl}/lms/classes`,
116
- ClassScheduleService: `${baseUrl}/lms/class-schedules`,
117
- CourseLessonService: `${baseUrl}/lms/course-lessons`,
118
- CoursePriceService: `${baseUrl}/lms/course-prices`,
119
- CourseProductService: `${baseUrl}/lms/course-product`,
120
- CourseService: `${baseUrl}/lms/courses`,
121
- DocumentService: `${baseUrl}/lms/documents`,
122
- DocumentCategoryService: `${baseUrl}/lms/document-categories`,
123
- LicenseService: `${baseUrl}/lms/license`,
124
- PracticeResultService: `${baseUrl}/lms/practices-result`,
125
- PracticeService: `${baseUrl}/lms/practices`,
126
- StudentAgainService: `${baseUrl}/lms/students-agains`,
127
- StudentDocumentService: `${baseUrl}/lms/students-documents`,
128
- StudentExamTimeService: `${baseUrl}/lms/student-exam-time`,
129
- StudentReviewService: `${baseUrl}/lms/students-reviews`,
130
- StudentService: `${baseUrl}/lms/students`,
131
- StudentScoreService: `${baseUrl}/lms/students-scores`,
132
- StudentSettingReviewService: `${baseUrl}/lms/setting-reviews`,
133
- StudentTrackingService: `${baseUrl}/lms/students-tracking`,
134
- StudentTrialService: `${baseUrl}/lms/students-trial`
135
- },
136
- Hr: {
137
- AllowanceService: `${baseUrl}/hr/allowance`,
138
- CategoryService: `${baseUrl}/hr/setting/category`,
139
- AnnualLeaveService: `${baseUrl}/hr/annual_leave`,
140
- EmployeeService: `${baseUrl}/hr/employees`,
141
- JobTitleService: `${baseUrl}/hr/setting/job_title`,
142
- DepartmentService: `${baseUrl}/hr/departments`,
143
- DeviceService: `${baseUrl}/hr/device`,
144
- DocumentService: `${baseUrl}/hr/documents`,
145
- EmployeeExtendService: `${baseUrl}/hr/employees/extend`,
146
- EmployeeExtendTempService: `${baseUrl}/hr/employees/extend/temp`,
147
- EmployeeLeaveService: `${baseUrl}/hr/employee_leave`,
148
- EmployeeNotificationService: `${baseUrl}/hr/notification-employee`,
149
- EmployeeQuitService: `${baseUrl}/hr/employee_quit`,
150
- EmployeeShiftService: `${baseUrl}/hr/employee_shift`,
151
- HolidayService: `${baseUrl}/hr/holidays`,
152
- PositionService: `${baseUrl}/hr/positions`,
153
- ReasonTypeService: `${baseUrl}/hr/setting/reason_type`,
154
- ResignationService: `${baseUrl}/hr/resignations`,
155
- SalaryService: `${baseUrl}/hr/employee_salary`,
156
- ScheduleService: `${baseUrl}/hr/schedule`,
157
- ScheduleOnlineService: `${baseUrl}/hr/schedule_online`,
158
- ShiftService: `${baseUrl}/hr/setting/shifts`,
159
- ShiftsCustomerCareService: `${baseUrl}/hr/setting/shifts-customer-care`,
160
- TicketService: `${baseUrl}/hr/ticket`,
161
- TicketExtendService: `${baseUrl}/hr/ticket/extend`,
162
- TicketTypeService: `${baseUrl}/hr/ticket-type`,
163
- TrackingConfirmService: `${baseUrl}/hr/tracking_confirm`,
164
- TrackingErrorService: `${baseUrl}/hr/tracking-error`,
165
- SettingDocumentService: `${baseUrl}/hr/setting/profile`
166
- },
167
- Support: {
168
- CommentService: `${baseUrl}/support/comment`
169
- }
170
- };
171
- module2.exports = {
172
- AUTHENTICATOR_PUBLIC_KEY: process.env.AUTHENTICATOR_PUBLIC_KEY || "",
173
- API_MICROSERVICE_URL: process.env.API_MICROSERVICE_URL || "",
174
- API_MICROSERVICE_TOKEN: process.env.API_MICROSERVICE_TOKEN || "",
175
- CONFIG_ROUTER_SERVICE: configRouteService,
176
- CONFIG_REDIS: redis
177
- };
178
- }
179
- });
180
-
181
- // src/services/BaseService.js
182
- var require_BaseService = __commonJS({
183
- "src/services/BaseService.js"(exports2, module2) {
184
- var axios = require("axios");
185
- var qs = require("qs");
186
- var { API_MICROSERVICE_TOKEN, CONFIG_REDIS } = require_config();
187
- var BaseService2 = class {
188
- baseUrl = "";
189
- headers = {};
190
- isCache = false;
191
- // bật/tắt cache mặc định
192
- service = null;
193
- // nhớ gán ở subclass
194
- timeCache = 300;
195
- // 300s = 5 phút
196
- constructor(baseUrl = "", defaultHeaders = {}) {
197
- this.baseUrl = baseUrl;
198
- this.setHeader(defaultHeaders);
199
- this.http = axios.create({
200
- baseURL: this.baseUrl,
201
- headers: this.headers,
202
- paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "brackets", encode: true })
203
- });
204
- }
205
- /**
206
- * Set header cho request
207
- * - headers: object { Authorization: "Bearer x" }
208
- * - string: "Bearer x"
209
- * - không truyền: dùng token từ ENV
210
- */
211
- setHeader(headers = {}) {
212
- let Authorization = `Bearer ${API_MICROSERVICE_TOKEN}`;
213
- if (typeof headers === "string") {
214
- Authorization = headers;
215
- } else if (headers && headers.Authorization) {
216
- Authorization = headers.Authorization;
217
- }
218
- this.headers = {
219
- ...this.headers || {},
220
- Authorization
221
- };
222
- return this;
223
- }
224
- buildCacheKey(path, params = {}) {
225
- const q = qs.stringify(params, { arrayFormat: "brackets", encode: true });
226
- const full = `${path}${q ? "?" + q : ""}`;
227
- const service = this.service || "unknown";
228
- return `gateway.${service}.urls:${full}`;
229
- }
230
- async request(method, url, options = {}, cacheKey = null, cacheOption = {}) {
231
- var _a, _b;
232
- const isGet = method.toLowerCase() === "get";
233
- const enableCache = cacheOption.isCache ?? this.isCache;
234
- if (isGet && enableCache) {
235
- cacheKey = cacheKey || this.buildCacheKey(url, options.params);
236
- const cached = await CONFIG_REDIS.get(cacheKey);
237
- if (cached) {
238
- console.log(`[CACHE HIT] ${cacheKey}`);
239
- return JSON.parse(cached);
240
- }
241
- }
242
- try {
243
- if (isGet) {
244
- console.log(`[HTTP GET] ${this.buildGET(url, options.params || {})}`);
245
- }
246
- const startTime = Date.now();
247
- const res = await this.http.request({
248
- method,
249
- url,
250
- headers: this.headers,
251
- ...options
252
- });
253
- const data = res.data;
254
- if (isGet && enableCache) {
255
- cacheKey = cacheKey || this.buildCacheKey(url, options.params);
256
- const ttl = cacheOption.timeCache || this.timeCache;
257
- await CONFIG_REDIS.set(cacheKey, JSON.stringify(data), "EX", ttl);
258
- console.log(`[CACHE SET] ${cacheKey} - TTL ${ttl}s`);
259
- }
260
- const duration = (Date.now() - startTime) / 1e3;
261
- if (duration > 5) {
262
- console.log(
263
- `[SLOW ${method.toUpperCase()}] ${url} - ${duration.toFixed(2)}s`
264
- );
265
- if (options.params) console.log("Query:", options.params);
266
- if (options.data) console.log("Body:", options.data);
267
- }
268
- return data;
269
- } catch (error) {
270
- const safeError = {
271
- statusCode: ((_a = error.response) == null ? void 0 : _a.status) || 500,
272
- ...(_b = error.response) == null ? void 0 : _b.data
273
- };
274
- if (safeError.statusCode === 404) {
275
- const q = qs.stringify(options.params || {}, {
276
- arrayFormat: "brackets",
277
- encode: true
278
- });
279
- return {
280
- statusCode: 404,
281
- status: "error",
282
- message: `[HTTP ${method.toUpperCase()}] ${url}${q ? "?" + q : ""} not found`
283
- };
284
- }
285
- console.error(`[${method.toUpperCase()}] ${url} failed:`, safeError);
286
- return { error: true, ...safeError };
287
- }
288
- }
289
- buildGET(url, params = {}) {
290
- const queryString = qs.stringify(params, {
291
- arrayFormat: "brackets",
292
- encode: true
293
- });
294
- return `${url}${queryString ? "?" + queryString : ""}`;
295
- }
296
- async all(query = {}, cacheOption = {}) {
297
- if (query.order_by && Array.isArray(query.order_by)) {
298
- query.order_by = query.order_by.slice(0, 2);
299
- if (query.order_by[1] && !["asc", "desc"].includes(query.order_by[1])) {
300
- query.order_by[1] = "asc";
301
- }
302
- }
303
- return this.request(
304
- "get",
305
- this.baseUrl,
306
- { params: query },
307
- null,
308
- cacheOption
309
- );
310
- }
311
- async detail(id, cacheOption = {}) {
312
- const enableCache = cacheOption.isCache ?? this.isCache;
313
- const cacheKey = enableCache ? `gateway.${this.service}.${id}` : null;
314
- return this.request(
315
- "get",
316
- `${this.baseUrl}/${id}`,
317
- {},
318
- cacheKey,
319
- cacheOption
320
- );
321
- }
322
- async create(data) {
323
- return this.request("post", this.baseUrl, { data });
324
- }
325
- async update(id, data) {
326
- return this.request("put", `${this.baseUrl}/${id}`, { data });
327
- }
328
- async delete(id) {
329
- return this.request("delete", `${this.baseUrl}/${id}`);
330
- }
331
- };
332
- module2.exports = BaseService2;
333
- }
334
- });
335
-
336
- // src/services/course/CourseService.js
337
- var BaseService = require_BaseService();
338
- var { CONFIG_ROUTER_SERVICE } = require_config();
339
- var CourseService = class extends BaseService {
340
- constructor() {
341
- super(CONFIG_ROUTER_SERVICE.Course.CourseService);
342
- this.service = "Course.CourseService";
343
- }
344
- // có thể thêm method riêng cho user nếu cần
345
- async detailSchedule(id, cacheOption = {}) {
346
- const enableCache = cacheOption.isCache ?? this.isCache;
347
- const cacheKey = enableCache ? `gateway.course_schedule.${id}` : null;
348
- return this.request(
349
- "get",
350
- `${this.baseUrl}/${id}`,
351
- {},
352
- cacheKey,
353
- cacheOption
354
- );
355
- }
356
- async count(filter = {}) {
357
- let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/course/course/count";
358
- return this.request("get", url, { params: filter });
359
- }
360
- async student(filter = {}) {
361
- let url = CONFIG_ROUTER_SERVICE.BASE_URL + "/course/students";
362
- return this.request("get", url, { params: filter });
363
- }
364
- };
365
- module.exports = CourseService;