law-common 10.18.1-beta.22 → 10.18.1-beta.23

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.
@@ -16,7 +16,7 @@ export interface IBillingCreateDtoExtra {
16
16
  }
17
17
  export interface IBillingTimesheetUnchangedDto {
18
18
  id: number;
19
- amount: number;
19
+ amount?: number;
20
20
  }
21
21
  export interface IBillingTimesheetUpdateDeleteDetailDto {
22
22
  id: number;
@@ -24,7 +24,7 @@ export interface IBillingTimesheetUpdateDeleteDetailDto {
24
24
  description: string;
25
25
  date: string;
26
26
  duration: number;
27
- amount: number;
27
+ amount?: number;
28
28
  impact: BillingImpactEnum;
29
29
  amendmentPurpose: string;
30
30
  }
@@ -13,7 +13,7 @@ export interface IBillingTimesheetEntity extends IAuditColumnEntity {
13
13
  task: string;
14
14
  description?: string;
15
15
  totalDuration: number;
16
- totalAmount: number;
16
+ totalAmount?: number;
17
17
  impact: BillingImpactEnum;
18
18
  amendmentPurpose?: string;
19
19
  changedStatus: BillingTimesheetStatusEnum;
@@ -23,7 +23,7 @@ export interface IBillingTimesheetEntityCreateDto extends IEntityCreateDto<IBill
23
23
  export interface IBillingTimesheetDetail extends IAuditColumnEntity {
24
24
  timesheetId: number;
25
25
  billingId: number;
26
- totalAmount: number;
26
+ totalAmount?: number;
27
27
  changedStatus: BillingTimesheetStatusEnum;
28
28
  impact: BillingImpactEnum;
29
29
  amendmentPurpose?: string;
@@ -1,7 +1,6 @@
1
1
  import { IBaseResponse } from "../../api";
2
2
  import { ConvertToArray } from "../../misc";
3
3
  import { Modify } from "../../misc/interface/modify.interface";
4
- import { TimesheetEntityModel } from "../../model/entities/timesheet.model";
5
4
  import { EntitySearchConstraintTypeEnum } from "../enums/entity_search_constraint_type.enum";
6
5
  import { HistoryOperationEnum } from "../enums/history_operation.enum";
7
6
  import { BankEntityModel } from "../model/bank.entity.model";
@@ -16,6 +15,7 @@ import { ProjectEntityModel } from "../model/project.entity.model";
16
15
  import { ReimbursementExpenseEntityModel } from "../model/reimbursement-expense.entity.model";
17
16
  import { ReimbursementEntityModel } from "../model/reimbursement.entity.model";
18
17
  import { TaskEntityModel } from "../model/task.entity.model";
18
+ import { TimesheetEntityModel } from "../model/timesheet.entity.model";
19
19
  import { UserEntityModel } from "../model/user.entity.model";
20
20
  import { IAuditColumnEntity } from "./audit-column.entity.interface";
21
21
  import { IBankEntity } from "./bank.entity.interface";
@@ -4,7 +4,6 @@ exports.mapToIndex = mapToIndex;
4
4
  exports.getEntityIndexMap = getEntityIndexMap;
5
5
  exports.populateRelationsFor = populateRelationsFor;
6
6
  exports.parseEntities = parseEntities;
7
- const timesheet_model_1 = require("../../model/entities/timesheet.model");
8
7
  const entity_utils_interface_1 = require("../interface/entity.utils.interface");
9
8
  const bank_entity_model_1 = require("./bank.entity.model");
10
9
  const base_entity_model_1 = require("./base.entity.model");
@@ -19,6 +18,7 @@ const project_entity_model_1 = require("./project.entity.model");
19
18
  const reimbursement_expense_entity_model_1 = require("./reimbursement-expense.entity.model");
20
19
  const reimbursement_entity_model_1 = require("./reimbursement.entity.model");
21
20
  const task_entity_model_1 = require("./task.entity.model");
21
+ const timesheet_entity_model_1 = require("./timesheet.entity.model");
22
22
  const user_entity_model_1 = require("./user.entity.model");
23
23
  function mapToIndex(entityMap) {
24
24
  return Object.keys(entityMap).reduce((acc, key) => {
@@ -63,7 +63,7 @@ function parseEntities(json, baseEntity, entityMap) {
63
63
  [entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromApiEntity,
64
64
  [entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromApiEntity,
65
65
  [entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromApiEntity,
66
- [entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_model_1.TimesheetEntityModel.fromApiEntity,
66
+ [entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromApiEntity,
67
67
  };
68
68
  if (!(baseEntity in entityFromJsonMappings)) {
69
69
  throw new Error(`Unknown entity: ${baseEntity}`);
@@ -211,6 +211,20 @@ export declare function areDecimalNumbersEqual(firstValue: number, secondValue:
211
211
  */
212
212
  export declare function formatIndianNumber(amount: number | string): string;
213
213
  export declare function findDuplicateIds(ids: number[]): number[];
214
+ /**
215
+ * Converts a string or number into a number with fixed decimal precision.
216
+ *
217
+ * @param value - The input value to convert. Can be a numeric string or a number.
218
+ * @param placesAfterDecimal - Number of digits to keep after the decimal point (default: 2).
219
+ * @returns The numeric value rounded to the specified number of decimal places.
220
+ * @throws {Error} If the input cannot be converted to a valid number.
221
+ *
222
+ * @example
223
+ * getDecimalNumberFromString("42.5678"); // 42.57
224
+ * getDecimalNumberFromString(42.5678, 3); // 42.568
225
+ * getDecimalNumberFromString("100"); // 100
226
+ * getDecimalNumberFromString("abc"); // throws Error("Invalid number: abc")
227
+ */
214
228
  export declare function getDecimalNumberFromString(value: string | number, placesAfterDecimal?: number): number;
215
229
  /**
216
230
  * Recursively checks if a specified property exists in an object or its nested objects.
@@ -241,3 +255,17 @@ export declare function getDecimalNumberFromString(value: string | number, place
241
255
  * ```
242
256
  */
243
257
  export declare function hasProperty<T extends object>(obj: T | null | undefined, propName: string): boolean;
258
+ /**
259
+ * Safely converts a given value (string or number) to a number.
260
+ *
261
+ * @template T - The input type, constrained to `string | number`.
262
+ * @param value - The value to convert. Can be a number or a numeric string.
263
+ * @returns The numeric representation of the input.
264
+ * @throws {Error} If the input cannot be converted to a valid number.
265
+ *
266
+ * @example
267
+ * convertToNumberType("42"); // 42
268
+ * convertToNumberType(3.14); // 3.14
269
+ * convertToNumberType("abc"); // throws Error("Invalid number: abc")
270
+ */
271
+ export declare function convertToNumberType<T extends string | number>(value: T): number;
@@ -38,6 +38,7 @@ exports.formatIndianNumber = formatIndianNumber;
38
38
  exports.findDuplicateIds = findDuplicateIds;
39
39
  exports.getDecimalNumberFromString = getDecimalNumberFromString;
40
40
  exports.hasProperty = hasProperty;
41
+ exports.convertToNumberType = convertToNumberType;
41
42
  const util_constants_1 = require("../constants/util.constants");
42
43
  const error_key_enum_1 = require("../enums/error.key.enum");
43
44
  const exceptions_1 = require("../exceptions");
@@ -464,9 +465,30 @@ function findDuplicateIds(ids) {
464
465
  }
465
466
  return Array.from(duplicates);
466
467
  }
468
+ /**
469
+ * Converts a string or number into a number with fixed decimal precision.
470
+ *
471
+ * @param value - The input value to convert. Can be a numeric string or a number.
472
+ * @param placesAfterDecimal - Number of digits to keep after the decimal point (default: 2).
473
+ * @returns The numeric value rounded to the specified number of decimal places.
474
+ * @throws {Error} If the input cannot be converted to a valid number.
475
+ *
476
+ * @example
477
+ * getDecimalNumberFromString("42.5678"); // 42.57
478
+ * getDecimalNumberFromString(42.5678, 3); // 42.568
479
+ * getDecimalNumberFromString("100"); // 100
480
+ * getDecimalNumberFromString("abc"); // throws Error("Invalid number: abc")
481
+ */
467
482
  function getDecimalNumberFromString(value, placesAfterDecimal = 2) {
468
- // this method should internally handle if the value is number or string
469
- return Number(Number(value).toFixed(placesAfterDecimal));
483
+ if (typeof value === "number") {
484
+ // Already a number, just round it
485
+ return Number(value.toFixed(placesAfterDecimal));
486
+ }
487
+ const num = Number(value);
488
+ if (Number.isNaN(num)) {
489
+ throw new Error(`Invalid number: ${value}`);
490
+ }
491
+ return Number(num.toFixed(placesAfterDecimal));
470
492
  }
471
493
  /**
472
494
  * Recursively checks if a specified property exists in an object or its nested objects.
@@ -519,3 +541,26 @@ function hasProperty(obj, propName) {
519
541
  }
520
542
  return false;
521
543
  }
544
+ /**
545
+ * Safely converts a given value (string or number) to a number.
546
+ *
547
+ * @template T - The input type, constrained to `string | number`.
548
+ * @param value - The value to convert. Can be a number or a numeric string.
549
+ * @returns The numeric representation of the input.
550
+ * @throws {Error} If the input cannot be converted to a valid number.
551
+ *
552
+ * @example
553
+ * convertToNumberType("42"); // 42
554
+ * convertToNumberType(3.14); // 3.14
555
+ * convertToNumberType("abc"); // throws Error("Invalid number: abc")
556
+ */
557
+ function convertToNumberType(value) {
558
+ if (typeof value === "number") {
559
+ return value;
560
+ }
561
+ const num = Number(value);
562
+ if (Number.isNaN(num)) {
563
+ throw new Error(`Invalid number: ${value}`);
564
+ }
565
+ return num;
566
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "10.18.1-beta.22",
3
+ "version": "10.18.1-beta.23",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [