plac-micro-common 1.3.34 → 1.3.36

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.
@@ -13,10 +13,11 @@ import { OrganizationPositionEntity } from "./org_position.entity";
13
13
  import { OrganizationStaffEntity } from "./org_staff.entity";
14
14
  import { OrganizationStaffBranchEntity } from "./org_staff_branches.entity";
15
15
  import { OrganizationStaffReportingLineEntity } from "./org_staff_reporting_lines.entity";
16
+ import { OccupationEntity } from "./occupation.entity";
16
17
  import { RelationshipEntity } from "./relationship.entity";
17
18
  import { StaffEntity } from "./staffs.entity";
18
19
  import { PaymentMethodEntity } from "./payment_method.entity";
19
- export declare const CORE_ENTITIES: readonly [typeof GeoProvinceEntity, typeof GeoDistrictEntity, typeof GeoCommuneEntity, typeof GeoVillageEntity, typeof MaritalStatusEntity, typeof NationalityEntity, typeof NumberSeriesEntity, typeof OrganizationEntity, typeof OrganizationBranchEntity, typeof OrganizationChannelEntity, typeof OrganizationDepartmentEntity, typeof OrganizationPositionEntity, typeof OrganizationStaffEntity, typeof OrganizationStaffBranchEntity, typeof OrganizationStaffReportingLineEntity, typeof PaymentMethodEntity, typeof RelationshipEntity, typeof StaffEntity, typeof import("./product").CashValueEntity, typeof import("./product").PaymentModeEntity, typeof import("./product").PremiumRateConditionEntity, typeof import("./product").PremiumRateValueEntity, typeof import("./product").ProductEntity, typeof import("./product").ProductOrgEntity, typeof import("./product").ProductTypeEntity, typeof import("./product").ProductPaymentModeEntity, typeof import("./product").ProductRiderEntity, typeof import("./product").ProductTermEntity, typeof import("./product").ProductPlanEntity, typeof import("./product").PromotionEntity, typeof import("./product").PromotionOrgEntity, typeof import("./product").PromotionProductEntity, typeof import("./product").RiderEntity, typeof import("./product").TermEntity, typeof import("./finance").ExchangeRateEntity, typeof import("./finance").ExchangeRateLogEntity];
20
- export { GeoProvinceEntity, GeoDistrictEntity, GeoCommuneEntity, GeoVillageEntity, MaritalStatusEntity, NationalityEntity, NumberSeriesEntity, OrganizationEntity, OrganizationBranchEntity, OrganizationChannelEntity, OrganizationDepartmentEntity, OrganizationPositionEntity, OrganizationStaffEntity, OrganizationStaffBranchEntity, OrganizationStaffReportingLineEntity, PaymentMethodEntity, RelationshipEntity, StaffEntity, };
20
+ export declare const CORE_ENTITIES: readonly [typeof GeoProvinceEntity, typeof GeoDistrictEntity, typeof GeoCommuneEntity, typeof GeoVillageEntity, typeof MaritalStatusEntity, typeof NationalityEntity, typeof NumberSeriesEntity, typeof OrganizationEntity, typeof OrganizationBranchEntity, typeof OrganizationChannelEntity, typeof OrganizationDepartmentEntity, typeof OrganizationPositionEntity, typeof OrganizationStaffEntity, typeof OrganizationStaffBranchEntity, typeof OrganizationStaffReportingLineEntity, typeof OccupationEntity, typeof PaymentMethodEntity, typeof RelationshipEntity, typeof StaffEntity, typeof import("./product").CashValueEntity, typeof import("./product").PaymentModeEntity, typeof import("./product").PremiumRateConditionEntity, typeof import("./product").PremiumRateValueEntity, typeof import("./product").ProductEntity, typeof import("./product").ProductOrgEntity, typeof import("./product").ProductTypeEntity, typeof import("./product").ProductPaymentModeEntity, typeof import("./product").ProductRiderEntity, typeof import("./product").ProductTermEntity, typeof import("./product").ProductPlanEntity, typeof import("./product").PromotionEntity, typeof import("./product").PromotionOrgEntity, typeof import("./product").PromotionProductEntity, typeof import("./product").RiderEntity, typeof import("./product").TermEntity, typeof import("./finance").ExchangeRateEntity, typeof import("./finance").ExchangeRateLogEntity];
21
+ export { GeoProvinceEntity, GeoDistrictEntity, GeoCommuneEntity, GeoVillageEntity, MaritalStatusEntity, NationalityEntity, NumberSeriesEntity, OrganizationEntity, OrganizationBranchEntity, OrganizationChannelEntity, OrganizationDepartmentEntity, OrganizationPositionEntity, OrganizationStaffEntity, OrganizationStaffBranchEntity, OrganizationStaffReportingLineEntity, OccupationEntity, PaymentMethodEntity, RelationshipEntity, StaffEntity, };
21
22
  export * from "./product";
22
23
  export * from "./finance";
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.StaffEntity = exports.RelationshipEntity = exports.PaymentMethodEntity = exports.OrganizationStaffReportingLineEntity = exports.OrganizationStaffBranchEntity = exports.OrganizationStaffEntity = exports.OrganizationPositionEntity = exports.OrganizationDepartmentEntity = exports.OrganizationChannelEntity = exports.OrganizationBranchEntity = exports.OrganizationEntity = exports.NumberSeriesEntity = exports.NationalityEntity = exports.MaritalStatusEntity = exports.GeoVillageEntity = exports.GeoCommuneEntity = exports.GeoDistrictEntity = exports.GeoProvinceEntity = exports.CORE_ENTITIES = void 0;
17
+ exports.StaffEntity = exports.RelationshipEntity = exports.PaymentMethodEntity = exports.OccupationEntity = exports.OrganizationStaffReportingLineEntity = exports.OrganizationStaffBranchEntity = exports.OrganizationStaffEntity = exports.OrganizationPositionEntity = exports.OrganizationDepartmentEntity = exports.OrganizationChannelEntity = exports.OrganizationBranchEntity = exports.OrganizationEntity = exports.NumberSeriesEntity = exports.NationalityEntity = exports.MaritalStatusEntity = exports.GeoVillageEntity = exports.GeoCommuneEntity = exports.GeoDistrictEntity = exports.GeoProvinceEntity = exports.CORE_ENTITIES = void 0;
18
18
  const geo_province_entity_1 = require("./geo_province.entity");
19
19
  Object.defineProperty(exports, "GeoProvinceEntity", { enumerable: true, get: function () { return geo_province_entity_1.GeoProvinceEntity; } });
20
20
  const geo_district_entity_1 = require("./geo_district.entity");
@@ -45,6 +45,8 @@ const org_staff_branches_entity_1 = require("./org_staff_branches.entity");
45
45
  Object.defineProperty(exports, "OrganizationStaffBranchEntity", { enumerable: true, get: function () { return org_staff_branches_entity_1.OrganizationStaffBranchEntity; } });
46
46
  const org_staff_reporting_lines_entity_1 = require("./org_staff_reporting_lines.entity");
47
47
  Object.defineProperty(exports, "OrganizationStaffReportingLineEntity", { enumerable: true, get: function () { return org_staff_reporting_lines_entity_1.OrganizationStaffReportingLineEntity; } });
48
+ const occupation_entity_1 = require("./occupation.entity");
49
+ Object.defineProperty(exports, "OccupationEntity", { enumerable: true, get: function () { return occupation_entity_1.OccupationEntity; } });
48
50
  const relationship_entity_1 = require("./relationship.entity");
49
51
  Object.defineProperty(exports, "RelationshipEntity", { enumerable: true, get: function () { return relationship_entity_1.RelationshipEntity; } });
50
52
  const staffs_entity_1 = require("./staffs.entity");
@@ -71,6 +73,7 @@ exports.CORE_ENTITIES = [
71
73
  org_staff_entity_1.OrganizationStaffEntity,
72
74
  org_staff_branches_entity_1.OrganizationStaffBranchEntity,
73
75
  org_staff_reporting_lines_entity_1.OrganizationStaffReportingLineEntity,
76
+ occupation_entity_1.OccupationEntity,
74
77
  //
75
78
  payment_method_entity_1.PaymentMethodEntity,
76
79
  //
@@ -0,0 +1,12 @@
1
+ import { _BaseEntity } from "../_base_entity";
2
+ import { OccupationLevel } from "../../types";
3
+ export declare class OccupationEntity extends _BaseEntity {
4
+ code: string;
5
+ name?: string | null;
6
+ name_kh?: string | null;
7
+ level: OccupationLevel;
8
+ parent_id?: string | null;
9
+ is_active: boolean;
10
+ parent?: OccupationEntity | null;
11
+ children: OccupationEntity[];
12
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OccupationEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const _base_entity_1 = require("../_base_entity");
15
+ const types_1 = require("../../types");
16
+ let OccupationEntity = class OccupationEntity extends _base_entity_1._BaseEntity {
17
+ };
18
+ exports.OccupationEntity = OccupationEntity;
19
+ __decorate([
20
+ (0, typeorm_1.Column)({ type: "varchar", length: 20 }),
21
+ __metadata("design:type", String)
22
+ ], OccupationEntity.prototype, "code", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)({ type: "varchar", length: 255, nullable: true }),
25
+ __metadata("design:type", Object)
26
+ ], OccupationEntity.prototype, "name", void 0);
27
+ __decorate([
28
+ (0, typeorm_1.Column)({ type: "varchar", length: 255, nullable: true }),
29
+ __metadata("design:type", Object)
30
+ ], OccupationEntity.prototype, "name_kh", void 0);
31
+ __decorate([
32
+ (0, typeorm_1.Column)({ type: "smallint" }),
33
+ __metadata("design:type", Number)
34
+ ], OccupationEntity.prototype, "level", void 0);
35
+ __decorate([
36
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
37
+ __metadata("design:type", Object)
38
+ ], OccupationEntity.prototype, "parent_id", void 0);
39
+ __decorate([
40
+ (0, typeorm_1.Column)({ type: "boolean", default: true }),
41
+ __metadata("design:type", Boolean)
42
+ ], OccupationEntity.prototype, "is_active", void 0);
43
+ __decorate([
44
+ (0, typeorm_1.ManyToOne)(() => OccupationEntity, (occupation) => occupation.children, {
45
+ nullable: true,
46
+ onDelete: "RESTRICT",
47
+ }),
48
+ (0, typeorm_1.JoinColumn)({ name: "parent_id" }),
49
+ __metadata("design:type", Object)
50
+ ], OccupationEntity.prototype, "parent", void 0);
51
+ __decorate([
52
+ (0, typeorm_1.OneToMany)(() => OccupationEntity, (occupation) => occupation.parent),
53
+ __metadata("design:type", Array)
54
+ ], OccupationEntity.prototype, "children", void 0);
55
+ exports.OccupationEntity = OccupationEntity = __decorate([
56
+ (0, typeorm_1.Entity)({ schema: "core", name: "occupations" }),
57
+ (0, typeorm_1.Index)("ux_occupation_code", ["code"], { unique: true }),
58
+ (0, typeorm_1.Index)("idx_occupation_parent_id", ["parent_id"]),
59
+ (0, typeorm_1.Index)("idx_occupation_level", ["level"])
60
+ ], OccupationEntity);
@@ -43,3 +43,10 @@ export declare enum DocumentStorageProvider {
43
43
  Local = "local",
44
44
  S3 = "s3"
45
45
  }
46
+ export declare enum OccupationLevel {
47
+ Chapter = 1,
48
+ Division = 2,
49
+ Group = 3,
50
+ Class = 4,
51
+ SubClass = 5
52
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentStorageProvider = exports.YesNo = exports.ResetScope = exports.IdentifierType = exports.AddressType = exports.ContactType = exports.MaritalStatus = exports.Gender = void 0;
3
+ exports.OccupationLevel = exports.DocumentStorageProvider = exports.YesNo = exports.ResetScope = exports.IdentifierType = exports.AddressType = exports.ContactType = exports.MaritalStatus = exports.Gender = void 0;
4
4
  var Gender;
5
5
  (function (Gender) {
6
6
  Gender["Male"] = "M";
@@ -54,3 +54,11 @@ var DocumentStorageProvider;
54
54
  DocumentStorageProvider["Local"] = "local";
55
55
  DocumentStorageProvider["S3"] = "s3";
56
56
  })(DocumentStorageProvider || (exports.DocumentStorageProvider = DocumentStorageProvider = {}));
57
+ var OccupationLevel;
58
+ (function (OccupationLevel) {
59
+ OccupationLevel[OccupationLevel["Chapter"] = 1] = "Chapter";
60
+ OccupationLevel[OccupationLevel["Division"] = 2] = "Division";
61
+ OccupationLevel[OccupationLevel["Group"] = 3] = "Group";
62
+ OccupationLevel[OccupationLevel["Class"] = 4] = "Class";
63
+ OccupationLevel[OccupationLevel["SubClass"] = 5] = "SubClass";
64
+ })(OccupationLevel || (exports.OccupationLevel = OccupationLevel = {}));
@@ -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.34",
3
+ "version": "1.3.36",
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";