@dgpholdings/greatoak-shared 1.1.28 → 1.1.29
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.
- package/dist/types/TApiUser.d.ts +3 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/time.util.d.ts +13 -0
- package/dist/utils/time.util.js +32 -1
- package/package.json +1 -1
package/dist/types/TApiUser.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ export type TUserMetric = {
|
|
|
4
4
|
appLanguage: string;
|
|
5
5
|
emailAddress?: string;
|
|
6
6
|
gender: "male" | "female" | "unmentioned";
|
|
7
|
+
createdAt: string;
|
|
8
|
+
updatedAt: string;
|
|
7
9
|
};
|
|
8
10
|
export type TApiUserUpdateReq = TUserMetric;
|
|
9
11
|
export type TApiUserUpdateRes = {
|
|
10
12
|
status: 400 | 500;
|
|
11
|
-
state: "failed" | "
|
|
13
|
+
state: "failed" | "time_restricted_error";
|
|
12
14
|
} | {
|
|
13
15
|
status: 200;
|
|
14
16
|
user: TUserMetric;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { toNumber } from "./number.util";
|
|
2
|
-
export { mmssToSecs } from "./time.util";
|
|
2
|
+
export { mmssToSecs, isUserAllowedToUpdate, getDaysAndHoursDifference, } from "./time.util";
|
|
3
3
|
export { countryToCurrencyCode } from "./billing.utils";
|
|
4
4
|
export { computeScoreFromRecord } from "./scoring.utils";
|
|
5
5
|
export { isDefined, isDefinedNumber } from "./isDefined.utils";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refineRecordEntry = exports.isDefinedNumber = exports.isDefined = exports.computeScoreFromRecord = exports.countryToCurrencyCode = exports.mmssToSecs = exports.toNumber = void 0;
|
|
3
|
+
exports.refineRecordEntry = exports.isDefinedNumber = exports.isDefined = exports.computeScoreFromRecord = exports.countryToCurrencyCode = exports.getDaysAndHoursDifference = exports.isUserAllowedToUpdate = exports.mmssToSecs = exports.toNumber = void 0;
|
|
4
4
|
var number_util_1 = require("./number.util");
|
|
5
5
|
Object.defineProperty(exports, "toNumber", { enumerable: true, get: function () { return number_util_1.toNumber; } });
|
|
6
6
|
var time_util_1 = require("./time.util");
|
|
7
7
|
Object.defineProperty(exports, "mmssToSecs", { enumerable: true, get: function () { return time_util_1.mmssToSecs; } });
|
|
8
|
+
Object.defineProperty(exports, "isUserAllowedToUpdate", { enumerable: true, get: function () { return time_util_1.isUserAllowedToUpdate; } });
|
|
9
|
+
Object.defineProperty(exports, "getDaysAndHoursDifference", { enumerable: true, get: function () { return time_util_1.getDaysAndHoursDifference; } });
|
|
8
10
|
var billing_utils_1 = require("./billing.utils");
|
|
9
11
|
Object.defineProperty(exports, "countryToCurrencyCode", { enumerable: true, get: function () { return billing_utils_1.countryToCurrencyCode; } });
|
|
10
12
|
var scoring_utils_1 = require("./scoring.utils");
|
|
@@ -1 +1,14 @@
|
|
|
1
1
|
export declare const mmssToSecs: (mmss: string) => number;
|
|
2
|
+
export declare const getDaysAndHoursDifference: ({ oldDate, newDate, }: {
|
|
3
|
+
oldDate: Date | string;
|
|
4
|
+
newDate: Date | string;
|
|
5
|
+
}) => {
|
|
6
|
+
days: number;
|
|
7
|
+
hours: number;
|
|
8
|
+
};
|
|
9
|
+
type TParam = {
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
updatedAt: Date;
|
|
12
|
+
};
|
|
13
|
+
export declare const isUserAllowedToUpdate: ({ createdAt, updatedAt }: TParam) => boolean;
|
|
14
|
+
export {};
|
package/dist/utils/time.util.js
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mmssToSecs = void 0;
|
|
3
|
+
exports.isUserAllowedToUpdate = exports.getDaysAndHoursDifference = exports.mmssToSecs = void 0;
|
|
4
4
|
const mmssToSecs = (mmss) => {
|
|
5
5
|
const [min, sec] = mmss.split(":").map(Number);
|
|
6
6
|
return (min || 0) * 60 + (sec || 0);
|
|
7
7
|
};
|
|
8
8
|
exports.mmssToSecs = mmssToSecs;
|
|
9
|
+
const getDaysAndHoursDifference = ({ oldDate, newDate, }) => {
|
|
10
|
+
const msPerDay = 1000 * 60 * 60 * 24;
|
|
11
|
+
const msPerHour = 1000 * 60 * 60;
|
|
12
|
+
const start = typeof oldDate === "string" ? new Date(oldDate) : oldDate;
|
|
13
|
+
const end = typeof newDate === "string" ? new Date(newDate) : newDate;
|
|
14
|
+
if (isNaN(start.getTime()) || isNaN(end.getTime())) {
|
|
15
|
+
throw new Error("Invalid date input");
|
|
16
|
+
}
|
|
17
|
+
const diffInMs = end.getTime() - start.getTime();
|
|
18
|
+
const fullDays = Math.floor(diffInMs / msPerDay);
|
|
19
|
+
const remainingMs = diffInMs % msPerDay;
|
|
20
|
+
const remainingHours = Math.floor(remainingMs / msPerHour);
|
|
21
|
+
return {
|
|
22
|
+
days: fullDays,
|
|
23
|
+
hours: remainingHours,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.getDaysAndHoursDifference = getDaysAndHoursDifference;
|
|
27
|
+
const isUserAllowedToUpdate = ({ createdAt, updatedAt }) => {
|
|
28
|
+
const now = new Date();
|
|
29
|
+
const sinceLastUpdated = (0, exports.getDaysAndHoursDifference)({
|
|
30
|
+
oldDate: updatedAt,
|
|
31
|
+
newDate: now,
|
|
32
|
+
});
|
|
33
|
+
const diffUserCreationAndLastUpdate = (0, exports.getDaysAndHoursDifference)({
|
|
34
|
+
oldDate: createdAt,
|
|
35
|
+
newDate: updatedAt,
|
|
36
|
+
});
|
|
37
|
+
return diffUserCreationAndLastUpdate.hours > 1 || sinceLastUpdated.hours <= 8;
|
|
38
|
+
};
|
|
39
|
+
exports.isUserAllowedToUpdate = isUserAllowedToUpdate;
|