@saihu/common 1.1.18 → 1.1.20

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.
@@ -0,0 +1,14 @@
1
+ export declare class BaseResponseDto<T> {
2
+ code: number;
3
+ msg: string;
4
+ data: T | null;
5
+ constructor(code: number, msg: string, data?: T | null);
6
+ static success<T>(data: T): BaseResponseDto<T>;
7
+ static successWithMessage<T>(msg: string, data: T): BaseResponseDto<T>;
8
+ static error<T>(code: number, msg: string): BaseResponseDto<T>;
9
+ static readonly CODE_NOT_FOUND = 404;
10
+ static readonly CODE_UNAUTHORIZED = 401;
11
+ static readonly CODE_FORBIDDEN = 403;
12
+ static readonly CODE_BAD_REQUEST = 400;
13
+ static readonly CODE_SERVER_ERROR = 500;
14
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseResponseDto = void 0;
4
+ // src/dto/base-response.dto.ts
5
+ class BaseResponseDto {
6
+ constructor(code, msg, data = null) {
7
+ this.code = code;
8
+ this.msg = msg;
9
+ this.data = data;
10
+ }
11
+ static success(data) {
12
+ return new BaseResponseDto(0, 'success', data);
13
+ }
14
+ static successWithMessage(msg, data) {
15
+ return new BaseResponseDto(0, msg, data);
16
+ }
17
+ static error(code, msg) {
18
+ return new BaseResponseDto(code, msg, null);
19
+ }
20
+ }
21
+ exports.BaseResponseDto = BaseResponseDto;
22
+ // Common error codes
23
+ BaseResponseDto.CODE_NOT_FOUND = 404;
24
+ BaseResponseDto.CODE_UNAUTHORIZED = 401;
25
+ BaseResponseDto.CODE_FORBIDDEN = 403;
26
+ BaseResponseDto.CODE_BAD_REQUEST = 400;
27
+ BaseResponseDto.CODE_SERVER_ERROR = 500;
@@ -3,4 +3,8 @@ export declare function getTomorrowDate(): string;
3
3
  export declare function getCurrentChinaTime(): Date;
4
4
  export declare function convertUtcToChinaTime(utcTimeString: string): string;
5
5
  export declare function convertUtcToChinaTimeFormatted(utcTimeString: string, format?: string): string;
6
+ export declare function getMonthStart(month: string): Date;
7
+ export declare function getMonthEnd(month: string): Date;
8
+ export declare const getNextVersion: () => string;
9
+ export declare const getCurrentVersion: () => string;
6
10
  //# sourceMappingURL=times.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"times.d.ts","sourceRoot":"","sources":["../../src/util/times.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,eAAe,WAE9B;AAED,wBAAgB,mBAAmB,SAMlC;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,MAAM,EACrB,MAAM,GAAE,MAA8B,GACrC,MAAM,CAER"}
1
+ {"version":3,"file":"times.d.ts","sourceRoot":"","sources":["../../src/util/times.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,eAAe,WAE9B;AAED,wBAAgB,mBAAmB,SAMlC;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,MAAM,EACrB,MAAM,GAAE,MAA8B,GACrC,MAAM,CAER;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED,eAAO,MAAM,cAAc,QAAO,MAOjC,CAAC;AACF,eAAO,MAAM,iBAAiB,QAAO,MAOpC,CAAC"}
@@ -3,11 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCurrentVersion = exports.getNextVersion = void 0;
6
7
  exports.getCurrentDate = getCurrentDate;
7
8
  exports.getTomorrowDate = getTomorrowDate;
8
9
  exports.getCurrentChinaTime = getCurrentChinaTime;
9
10
  exports.convertUtcToChinaTime = convertUtcToChinaTime;
10
11
  exports.convertUtcToChinaTimeFormatted = convertUtcToChinaTimeFormatted;
12
+ exports.getMonthStart = getMonthStart;
13
+ exports.getMonthEnd = getMonthEnd;
11
14
  const dayjs_1 = __importDefault(require("dayjs"));
12
15
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
13
16
  const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
@@ -32,3 +35,27 @@ function convertUtcToChinaTime(utcTimeString) {
32
35
  function convertUtcToChinaTimeFormatted(utcTimeString, format = 'YYYY-MM-DD HH:mm:ss') {
33
36
  return dayjs_1.default.utc(utcTimeString).tz('Asia/Shanghai').format(format);
34
37
  }
38
+ function getMonthStart(month) {
39
+ return dayjs_1.default.utc(month).startOf('month').toDate();
40
+ }
41
+ function getMonthEnd(month) {
42
+ return dayjs_1.default.utc(month).endOf('month').toDate();
43
+ }
44
+ const getNextVersion = () => {
45
+ const currentUtcTime = (0, dayjs_1.default)().utc();
46
+ const cutoffTime = (0, dayjs_1.default)().utc().hour(3).minute(30).second(0);
47
+ const dateToUse = currentUtcTime.isAfter(cutoffTime)
48
+ ? currentUtcTime.add(1, 'day')
49
+ : currentUtcTime;
50
+ return dateToUse.format('YYYYMMDD');
51
+ };
52
+ exports.getNextVersion = getNextVersion;
53
+ const getCurrentVersion = () => {
54
+ const currentUtcTime = (0, dayjs_1.default)().utc();
55
+ const cutoffTime = (0, dayjs_1.default)().utc().hour(3).minute(30).second(0);
56
+ const dateToUse = currentUtcTime.isAfter(cutoffTime)
57
+ ? currentUtcTime
58
+ : currentUtcTime.subtract(1, 'day');
59
+ return dateToUse.format('YYYYMMDD');
60
+ };
61
+ exports.getCurrentVersion = getCurrentVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",