dt-common-device 3.0.7 → 3.0.8

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.
@@ -1,7 +1,8 @@
1
1
  import { InternalEventSubscription } from "../events";
2
- import { IConfig } from "./config.types";
2
+ import { IConfig, ILogger } from "./config.types";
3
3
  export declare function initialize(cfg: IConfig): Promise<void>;
4
4
  export declare function getConfig(): IConfig;
5
+ export declare function getLogger(): ILogger;
5
6
  export declare function getEventSubscription(): InternalEventSubscription | null;
6
7
  export declare function checkRequiredEnv(): void;
7
8
  export declare function ensureAuditInitialized(): void;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initialize = initialize;
7
7
  exports.getConfig = getConfig;
8
+ exports.getLogger = getLogger;
8
9
  exports.getEventSubscription = getEventSubscription;
9
10
  exports.checkRequiredEnv = checkRequiredEnv;
10
11
  exports.ensureAuditInitialized = ensureAuditInitialized;
@@ -82,6 +83,10 @@ function getConfig() {
82
83
  }
83
84
  return config;
84
85
  }
86
+ // Direct logger export for easier usage
87
+ function getLogger() {
88
+ return getConfig().LOGGER;
89
+ }
85
90
  function getEventSubscription() {
86
91
  return eventSubscription;
87
92
  }
@@ -1,8 +1,10 @@
1
1
  import { ISchedule } from "../interfaces/ISchedule";
2
2
  export declare class ScheduleRepository {
3
3
  private readonly axiosInstance;
4
+ private readonly logger;
4
5
  constructor();
5
6
  getSchedule(scheduleId: string): Promise<any>;
6
7
  getScheduleByZone(zoneId: string): Promise<any>;
7
8
  setSchedule(scheduleId: string, schedule: ISchedule): Promise<any>;
9
+ deleteSchedule(scheduleId: string): Promise<any>;
8
10
  }
@@ -49,6 +49,7 @@ let ScheduleRepository = (() => {
49
49
  let _classThis;
50
50
  var ScheduleRepository = _classThis = class {
51
51
  constructor() {
52
+ this.logger = (0, config_1.getLogger)();
52
53
  this.axiosInstance = (0, http_utils_1.getDeviceServiceAxiosInstance)();
53
54
  }
54
55
  async getSchedule(scheduleId) {
@@ -57,7 +58,7 @@ let ScheduleRepository = (() => {
57
58
  return response.data;
58
59
  }
59
60
  catch (error) {
60
- (0, config_1.getConfig)().LOGGER.error(`Failed to get schedule ${scheduleId}:`, error);
61
+ this.logger.error(`Failed to get schedule ${scheduleId}:`, error);
61
62
  const errorMessage = error.response?.data?.message || error.message || "Unknown error";
62
63
  throw new Error(`Failed to get schedule: ${errorMessage}`);
63
64
  }
@@ -68,7 +69,7 @@ let ScheduleRepository = (() => {
68
69
  return response.data;
69
70
  }
70
71
  catch (error) {
71
- (0, config_1.getConfig)().LOGGER.error(`Failed to get schedule by zone ${zoneId}:`, error);
72
+ this.logger.error(`Failed to get schedule by zone ${zoneId}:`, error);
72
73
  const errorMessage = error.response?.data?.message || error.message || "Unknown error";
73
74
  throw new Error(`Failed to get schedule: ${errorMessage}`);
74
75
  }
@@ -79,11 +80,21 @@ let ScheduleRepository = (() => {
79
80
  return response.data;
80
81
  }
81
82
  catch (error) {
82
- (0, config_1.getConfig)().LOGGER.error(`Failed to update schedule ${scheduleId}:`, error);
83
+ this.logger.error(`Failed to update schedule ${scheduleId}:`, error);
83
84
  const errorMessage = error.response?.data?.message || error.message || "Unknown error";
84
85
  throw new Error(`Failed to update schedule: ${errorMessage}`);
85
86
  }
86
87
  }
88
+ async deleteSchedule(scheduleId) {
89
+ try {
90
+ const response = await this.axiosInstance.delete(`/devices/schedules/${scheduleId}`);
91
+ return response.data;
92
+ }
93
+ catch (error) {
94
+ this.logger.error(`Failed to delete schedule from DB ${scheduleId}:`, error);
95
+ throw new Error(`Failed to delete schedule from DB: ${error.message}`);
96
+ }
97
+ }
87
98
  };
88
99
  __setFunctionName(_classThis, "ScheduleRepository");
89
100
  (() => {
@@ -5,4 +5,5 @@ export declare class LocalScheduleService {
5
5
  getSchedule(scheduleId: string): Promise<any>;
6
6
  setSchedule(scheduleId: string, schedule: ISchedule): Promise<any>;
7
7
  getScheduleByZone(zoneId: string): Promise<any>;
8
+ deleteSchedule(scheduleId: string): Promise<any>;
8
9
  }
@@ -19,5 +19,8 @@ class LocalScheduleService {
19
19
  async getScheduleByZone(zoneId) {
20
20
  return await this.scheduleRepository.getScheduleByZone(zoneId);
21
21
  }
22
+ async deleteSchedule(scheduleId) {
23
+ return await this.scheduleRepository.deleteSchedule(scheduleId);
24
+ }
22
25
  }
23
26
  exports.LocalScheduleService = LocalScheduleService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ import { connectDatabase } from "../db/db";
3
3
  import dotenv from "dotenv";
4
4
  import { InternalEventSubscription } from "../events";
5
5
  import { validateServiceUrl } from "../utils/http.utils";
6
- import { IConfig } from "./config.types";
6
+ import { IConfig, ILogger } from "./config.types";
7
7
 
8
8
  dotenv.config();
9
9
 
@@ -86,6 +86,11 @@ export function getConfig(): IConfig {
86
86
  return config;
87
87
  }
88
88
 
89
+ // Direct logger export for easier usage
90
+ export function getLogger(): ILogger {
91
+ return getConfig().LOGGER;
92
+ }
93
+
89
94
  export function getEventSubscription(): InternalEventSubscription | null {
90
95
  return eventSubscription;
91
96
  }
@@ -1,11 +1,12 @@
1
1
  import { Service } from "typedi";
2
- import { getConfig } from "../../../config/config";
2
+ import { getLogger } from "../../../config/config";
3
3
  import { ISchedule } from "../interfaces/ISchedule";
4
4
  import { getDeviceServiceAxiosInstance } from "../../../utils/http.utils";
5
5
 
6
6
  @Service()
7
7
  export class ScheduleRepository {
8
8
  private readonly axiosInstance;
9
+ private readonly logger = getLogger();
9
10
 
10
11
  constructor() {
11
12
  this.axiosInstance = getDeviceServiceAxiosInstance();
@@ -18,7 +19,7 @@ export class ScheduleRepository {
18
19
  );
19
20
  return response.data;
20
21
  } catch (error: any) {
21
- getConfig().LOGGER.error(`Failed to get schedule ${scheduleId}:`, error);
22
+ this.logger.error(`Failed to get schedule ${scheduleId}:`, error);
22
23
  const errorMessage =
23
24
  error.response?.data?.message || error.message || "Unknown error";
24
25
  throw new Error(`Failed to get schedule: ${errorMessage}`);
@@ -32,10 +33,7 @@ export class ScheduleRepository {
32
33
  );
33
34
  return response.data;
34
35
  } catch (error: any) {
35
- getConfig().LOGGER.error(
36
- `Failed to get schedule by zone ${zoneId}:`,
37
- error
38
- );
36
+ this.logger.error(`Failed to get schedule by zone ${zoneId}:`, error);
39
37
  const errorMessage =
40
38
  error.response?.data?.message || error.message || "Unknown error";
41
39
  throw new Error(`Failed to get schedule: ${errorMessage}`);
@@ -50,13 +48,25 @@ export class ScheduleRepository {
50
48
  );
51
49
  return response.data;
52
50
  } catch (error: any) {
53
- getConfig().LOGGER.error(
54
- `Failed to update schedule ${scheduleId}:`,
55
- error
56
- );
51
+ this.logger.error(`Failed to update schedule ${scheduleId}:`, error);
57
52
  const errorMessage =
58
53
  error.response?.data?.message || error.message || "Unknown error";
59
54
  throw new Error(`Failed to update schedule: ${errorMessage}`);
60
55
  }
61
56
  }
57
+
58
+ async deleteSchedule(scheduleId: string) {
59
+ try {
60
+ const response = await this.axiosInstance.delete(
61
+ `/devices/schedules/${scheduleId}`
62
+ );
63
+ return response.data;
64
+ } catch (error: any) {
65
+ this.logger.error(
66
+ `Failed to delete schedule from DB ${scheduleId}:`,
67
+ error
68
+ );
69
+ throw new Error(`Failed to delete schedule from DB: ${error.message}`);
70
+ }
71
+ }
62
72
  }
@@ -19,4 +19,8 @@ export class LocalScheduleService {
19
19
  async getScheduleByZone(zoneId: string) {
20
20
  return await this.scheduleRepository.getScheduleByZone(zoneId);
21
21
  }
22
+
23
+ async deleteSchedule(scheduleId: string) {
24
+ return await this.scheduleRepository.deleteSchedule(scheduleId);
25
+ }
22
26
  }