plac-micro-common 1.3.33 → 1.3.35

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.
@@ -8,7 +8,7 @@ export declare class AppPaymentEntity extends _BaseEntity {
8
8
  payment_datetime: Date;
9
9
  payment_type: AppPaymentType;
10
10
  payment_status: AppPaymentStatus;
11
- exchange_rate_value: string;
11
+ exchange_rate_value: number;
12
12
  amount_paid_usd: number;
13
13
  amount_paid_khr: number;
14
14
  total_paid_amount: number;
@@ -52,8 +52,8 @@ __decorate([
52
52
  __metadata("design:type", String)
53
53
  ], AppPaymentEntity.prototype, "payment_status", void 0);
54
54
  __decorate([
55
- (0, typeorm_1.Column)({ type: "numeric", precision: 18, scale: 6 }),
56
- __metadata("design:type", String)
55
+ (0, typeorm_1.Column)({ type: "numeric", precision: 18, scale: 6, default: 0 }),
56
+ __metadata("design:type", Number)
57
57
  ], AppPaymentEntity.prototype, "exchange_rate_value", void 0);
58
58
  __decorate([
59
59
  (0, typeorm_1.Column)({ type: "numeric", precision: 18, scale: 2, default: 0 }),
@@ -14,4 +14,5 @@ export * from "./promotion.type";
14
14
  export * from "./staff.type";
15
15
  export * from "./quotation.type";
16
16
  export * from "./underwriting.type";
17
+ export * from "./upload.type";
17
18
  export * from "./pdf-form";
@@ -30,4 +30,5 @@ __exportStar(require("./promotion.type"), exports);
30
30
  __exportStar(require("./staff.type"), exports);
31
31
  __exportStar(require("./quotation.type"), exports);
32
32
  __exportStar(require("./underwriting.type"), exports);
33
+ __exportStar(require("./upload.type"), exports);
33
34
  __exportStar(require("./pdf-form"), exports);
@@ -0,0 +1,17 @@
1
+ export declare enum FileStorageProvider {
2
+ Local = "local",
3
+ S3 = "s3"
4
+ }
5
+ export type UploadedFileResult = {
6
+ original_file_name: string;
7
+ stored_file_name: string;
8
+ file_extension?: string | null;
9
+ mime_type: string;
10
+ file_size_bytes: number;
11
+ storage_provider: FileStorageProvider;
12
+ bucket_name?: string | null;
13
+ object_key?: string | null;
14
+ relative_path?: string | null;
15
+ public_url?: string | null;
16
+ uploaded_at: Date;
17
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileStorageProvider = void 0;
4
+ var FileStorageProvider;
5
+ (function (FileStorageProvider) {
6
+ FileStorageProvider["Local"] = "local";
7
+ FileStorageProvider["S3"] = "s3";
8
+ })(FileStorageProvider || (exports.FileStorageProvider = FileStorageProvider = {}));
@@ -2,5 +2,10 @@ export declare function delay(ms: number): Promise<unknown>;
2
2
  export declare function buildFullName(first?: string | null, last?: string | null): string | null;
3
3
  export declare function buildUserFullName(first?: string | null, last?: string | null): string | null;
4
4
  export declare function buildFullNameKh(firstKh?: string | null, lastKh?: string | null): string | null;
5
- export declare function displayDate(value?: Date | string | number | null, format?: string): string;
6
- export declare function displayDateTime(value?: Date | string | number | null, format?: string): string;
5
+ export declare function formatDate(value?: Date | string | number | null, format?: string): string;
6
+ export declare function formatDateTime(value?: Date | string | number | null, format?: string): string;
7
+ export declare function formatAmount(amount: number | string, digits?: number, options?: {
8
+ locale?: string;
9
+ }): string;
10
+ export declare function roundAmount(value: number): number;
11
+ export declare function calculateAge(dateOfBirth: Date | string, atDate?: Date | string): number;
@@ -7,8 +7,11 @@ exports.delay = delay;
7
7
  exports.buildFullName = buildFullName;
8
8
  exports.buildUserFullName = buildUserFullName;
9
9
  exports.buildFullNameKh = buildFullNameKh;
10
- exports.displayDate = displayDate;
11
- exports.displayDateTime = displayDateTime;
10
+ exports.formatDate = formatDate;
11
+ exports.formatDateTime = formatDateTime;
12
+ exports.formatAmount = formatAmount;
13
+ exports.roundAmount = roundAmount;
14
+ exports.calculateAge = calculateAge;
12
15
  const dayjs_1 = __importDefault(require("dayjs"));
13
16
  const constants_1 = require("../../constants");
14
17
  function delay(ms) {
@@ -26,7 +29,8 @@ function buildFullNameKh(firstKh, lastKh) {
26
29
  const v = `${lastKh ?? ""} ${firstKh ?? ""}`.trim();
27
30
  return v.length ? v : null;
28
31
  }
29
- function displayDate(value, format = constants_1.DISPLAY_DATE_FORMAT) {
32
+ //--- DISPLAY UTILITIES ---//
33
+ function formatDate(value, format = constants_1.DISPLAY_DATE_FORMAT) {
30
34
  if (!value)
31
35
  return "-";
32
36
  const date = (0, dayjs_1.default)(value);
@@ -34,7 +38,7 @@ function displayDate(value, format = constants_1.DISPLAY_DATE_FORMAT) {
34
38
  return "-";
35
39
  return date.format(format);
36
40
  }
37
- function displayDateTime(value, format = constants_1.DISPLAY_DATE_TIME_FORMAT) {
41
+ function formatDateTime(value, format = constants_1.DISPLAY_DATE_TIME_FORMAT) {
38
42
  if (!value)
39
43
  return "-";
40
44
  const date = (0, dayjs_1.default)(value);
@@ -42,3 +46,25 @@ function displayDateTime(value, format = constants_1.DISPLAY_DATE_TIME_FORMAT) {
42
46
  return "-";
43
47
  return date.format(format);
44
48
  }
49
+ function formatAmount(amount, digits = 0, options) {
50
+ const value = Number(amount);
51
+ if (!Number.isFinite(value))
52
+ return "0";
53
+ return new Intl.NumberFormat(options?.locale ?? "en-US", {
54
+ minimumFractionDigits: digits,
55
+ maximumFractionDigits: digits,
56
+ }).format(value);
57
+ }
58
+ //--- Amount ---//
59
+ function roundAmount(value) {
60
+ return Math.round(Number(value.toFixed(3)) * 100) / 100;
61
+ }
62
+ //--- OTHERs ---//
63
+ function calculateAge(dateOfBirth, atDate = new Date()) {
64
+ const dob = (0, dayjs_1.default)(dateOfBirth);
65
+ const at = (0, dayjs_1.default)(atDate);
66
+ if (!dob.isValid() || !at.isValid()) {
67
+ throw new Error("Invalid date of birth!");
68
+ }
69
+ return at.diff(dob, "year");
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plac-micro-common",
3
- "version": "1.3.33",
3
+ "version": "1.3.35",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
File without changes
@@ -1 +0,0 @@
1
- "use strict";