Compare commits

..

10 Commits

Author SHA1 Message Date
standardci
8157f324a0 chore(release): publish new version
- @standardnotes/auth-server@1.24.4
2022-09-07 08:37:22 +00:00
Karol Sójko
132b617aaa fix(auth): forbid users on shared subscription to send out invitations 2022-09-07 10:35:06 +02:00
standardci
25b1f3e9ea chore(release): publish new version
- @standardnotes/api-gateway@1.16.2
 - @standardnotes/auth-server@1.24.3
 - @standardnotes/domain-events-infra@1.8.3
 - @standardnotes/domain-events@2.59.1
 - @standardnotes/event-store@1.3.6
 - @standardnotes/files-server@1.5.45
 - @standardnotes/scheduler-server@1.10.22
 - @standardnotes/syncing-server@1.6.62
2022-09-06 10:30:52 +00:00
Karol Sójko
f94c8fc26e fix(api-gateway): period types on analytics report 2022-09-06 12:28:48 +02:00
Karol Sójko
d149f46cf6 fix(api-gateway): include period key in statistics measures 2022-09-06 12:16:07 +02:00
standardci
6a24ba5d56 chore(release): publish new version
- @standardnotes/api-gateway@1.16.1
 - @standardnotes/auth-server@1.24.2
 - @standardnotes/event-store@1.3.5
 - @standardnotes/files-server@1.5.44
 - @standardnotes/scheduler-server@1.10.21
 - @standardnotes/syncing-server@1.6.61
 - @standardnotes/time@1.11.0
2022-09-06 10:10:20 +00:00
Karol Sójko
db8333a858 feat(time): add converting microseconds to time structure 2022-09-06 12:08:39 +02:00
standardci
3af254d7c7 chore(release): publish new version
- @standardnotes/api-gateway@1.16.0
 - @standardnotes/auth-server@1.24.1
 - @standardnotes/domain-events-infra@1.8.2
 - @standardnotes/domain-events@2.59.0
 - @standardnotes/event-store@1.3.4
 - @standardnotes/files-server@1.5.43
 - @standardnotes/scheduler-server@1.10.20
 - @standardnotes/syncing-server@1.6.60
2022-09-06 09:28:23 +00:00
Karol Sójko
8151bb108a feat(api-gateway): add statistics measures to report generation 2022-09-06 11:26:27 +02:00
Karol Sójko
3b18769c2d chore(deps): upgrade uuid 2022-09-06 11:26:27 +02:00
31 changed files with 253 additions and 31 deletions

13
.pnp.cjs generated
View File

@@ -2607,7 +2607,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["ts-jest", "virtual:c66bf20e88479ada0172094776519a9f51acc4731d22079b60a295bcec7ea42d5545cbce58a77a50d932bf953298799135e99707486e343da6d99ba1d167bdbd#npm:28.0.5"],\
["typeorm", "virtual:31b5a94a105c89c9294c3d524a7f8929fe63ee5a2efadf21951ca4c0cfd2ecf02e8f4ef5a066bbda091f1e3a56e57c6749069a080618c96b22e51131a330fc4a#npm:0.3.7"],\
["ua-parser-js", "npm:1.0.2"],\
["uuid", "npm:8.3.2"],\
["uuid", "npm:9.0.0"],\
["winston", "npm:3.8.1"]\
],\
"linkType": "SOFT"\
@@ -2789,7 +2789,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["reflect-metadata", "npm:0.1.13"],\
["ts-jest", "virtual:c66bf20e88479ada0172094776519a9f51acc4731d22079b60a295bcec7ea42d5545cbce58a77a50d932bf953298799135e99707486e343da6d99ba1d167bdbd#npm:28.0.5"],\
["ts-node", "virtual:b442cf0427cc365d1c137f7340f9b81f9b204561afe791a8564ae9590c3a7fc4b5f793aaf8817b946f75a3cb64d03ef8790eb847f8b576b41e700da7b00c240c#npm:10.9.1"],\
["uuid", "npm:8.3.2"],\
["uuid", "npm:9.0.0"],\
["winston", "npm:3.8.1"]\
],\
"linkType": "SOFT"\
@@ -3036,7 +3036,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["ts-jest", "virtual:c66bf20e88479ada0172094776519a9f51acc4731d22079b60a295bcec7ea42d5545cbce58a77a50d932bf953298799135e99707486e343da6d99ba1d167bdbd#npm:28.0.5"],\
["typeorm", "virtual:31b5a94a105c89c9294c3d524a7f8929fe63ee5a2efadf21951ca4c0cfd2ecf02e8f4ef5a066bbda091f1e3a56e57c6749069a080618c96b22e51131a330fc4a#npm:0.3.7"],\
["ua-parser-js", "npm:1.0.2"],\
["uuid", "npm:8.3.2"],\
["uuid", "npm:9.0.0"],\
["winston", "npm:3.8.1"]\
],\
"linkType": "SOFT"\
@@ -12779,6 +12779,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["uuid", "npm:8.3.2"]\
],\
"linkType": "HARD"\
}],\
["npm:9.0.0", {\
"packageLocation": "./.yarn/cache/uuid-npm-9.0.0-46c41e3e43-8dd2c83c43.zip/node_modules/uuid/",\
"packageDependencies": [\
["uuid", "npm:9.0.0"]\
],\
"linkType": "HARD"\
}]\
]],\
["v8-compile-cache", [\

Binary file not shown.

View File

@@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.16.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.1...@standardnotes/api-gateway@1.16.2) (2022-09-06)
### Bug Fixes
* **api-gateway:** include period key in statistics measures ([d149f46](https://github.com/standardnotes/api-gateway/commit/d149f46cf6456201dd8690977f64ed32a75f3459))
* **api-gateway:** period types on analytics report ([f94c8fc](https://github.com/standardnotes/api-gateway/commit/f94c8fc26e684a07101cc5282ebb9cda3c8c6961))
## [1.16.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.16.0...@standardnotes/api-gateway@1.16.1) (2022-09-06)
**Note:** Version bump only for package @standardnotes/api-gateway
# [1.16.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.15.12...@standardnotes/api-gateway@1.16.0) (2022-09-06)
### Features
* **api-gateway:** add statistics measures to report generation ([8151bb1](https://github.com/standardnotes/api-gateway/commit/8151bb108affb2b5cfa1ab365f99a9f0170a7795))
## [1.15.12](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.15.11...@standardnotes/api-gateway@1.15.12) (2022-09-06)
**Note:** Version bump only for package @standardnotes/api-gateway

View File

@@ -12,7 +12,13 @@ import {
DailyAnalyticsReportGeneratedEvent,
DomainEventService,
} from '@standardnotes/domain-events'
import { AnalyticsActivity, AnalyticsStoreInterface, Period, StatisticsStoreInterface } from '@standardnotes/analytics'
import {
AnalyticsActivity,
AnalyticsStoreInterface,
Period,
StatisticsMeasure,
StatisticsStoreInterface,
} from '@standardnotes/analytics'
const requestReport = async (
analyticsStore: AnalyticsStoreInterface,
@@ -60,7 +66,6 @@ const requestReport = async (
const yesterdayActivityStatistics = []
const yesterdayActivityNames = [
AnalyticsActivity.EditingItems,
AnalyticsActivity.LimitedDiscountOfferPurchased,
AnalyticsActivity.GeneralActivity,
AnalyticsActivity.PaymentFailed,
@@ -79,6 +84,24 @@ const requestReport = async (
})
}
const statisticMeasureNames = [
StatisticsMeasure.Income,
StatisticsMeasure.Refunds,
StatisticsMeasure.RegistrationLength,
StatisticsMeasure.SubscriptionLength,
]
const statisticMeasures = []
for (const statisticMeasureName of statisticMeasureNames) {
for (const period of [Period.Yesterday, Period.ThisMonth]) {
statisticMeasures.push({
name: statisticMeasureName,
period,
totalValue: await statisticsStore.getMeasureTotal(statisticMeasureName, period),
average: await statisticsStore.getMeasureAverage(statisticMeasureName, period),
})
}
}
const event: DailyAnalyticsReportGeneratedEvent = {
type: 'DAILY_ANALYTICS_REPORT_GENERATED',
createdAt: new Date(),
@@ -95,6 +118,7 @@ const requestReport = async (
outOfSyncIncidents: await statisticsStore.getYesterdayOutOfSyncIncidents(),
activityStatistics: yesterdayActivityStatistics,
activityStatisticsOverTime: analyticsOverTime,
statisticMeasures,
},
}

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.15.12",
"version": "1.16.2",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.24.4](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.3...@standardnotes/auth-server@1.24.4) (2022-09-07)
### Bug Fixes
* **auth:** forbid users on shared subscription to send out invitations ([132b617](https://github.com/standardnotes/server/commit/132b617aaa8a703877fd7e8d23711fb1ec234524))
## [1.24.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.2...@standardnotes/auth-server@1.24.3) (2022-09-06)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.24.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.1...@standardnotes/auth-server@1.24.2) (2022-09-06)
**Note:** Version bump only for package @standardnotes/auth-server
## [1.24.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.24.0...@standardnotes/auth-server@1.24.1) (2022-09-06)
**Note:** Version bump only for package @standardnotes/auth-server
# [1.24.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.23.2...@standardnotes/auth-server@1.24.0) (2022-09-06)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.24.0",
"version": "1.24.4",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
@@ -63,7 +63,7 @@
"reflect-metadata": "0.1.13",
"typeorm": "^0.3.6",
"ua-parser-js": "1.0.2",
"uuid": "8.3.2",
"uuid": "^9.0.0",
"winston": "^3.8.1"
},
"devDependencies": {

View File

@@ -9,6 +9,7 @@ import { InviteToSharedSubscription } from './InviteToSharedSubscription'
import { UserSubscriptionRepositoryInterface } from '../../Subscription/UserSubscriptionRepositoryInterface'
import { UserSubscription } from '../../Subscription/UserSubscription'
import { RoleName } from '@standardnotes/common'
import { UserSubscriptionType } from '../../Subscription/UserSubscriptionType'
describe('InviteToSharedSubscription', () => {
let userSubscriptionRepository: UserSubscriptionRepositoryInterface
@@ -28,9 +29,10 @@ describe('InviteToSharedSubscription', () => {
beforeEach(() => {
userSubscriptionRepository = {} as jest.Mocked<UserSubscriptionRepositoryInterface>
userSubscriptionRepository.findOneByUserUuid = jest
.fn()
.mockReturnValue({ subscriptionId: 2 } as jest.Mocked<UserSubscription>)
userSubscriptionRepository.findOneByUserUuid = jest.fn().mockReturnValue({
subscriptionId: 2,
subscriptionType: UserSubscriptionType.Regular,
} as jest.Mocked<UserSubscription>)
timer = {} as jest.Mocked<TimerInterface>
timer.getTimestampInMicroseconds = jest.fn().mockReturnValue(1)
@@ -159,4 +161,24 @@ describe('InviteToSharedSubscription', () => {
})
expect(domainEventPublisher.publish).toHaveBeenCalled()
})
it('should not create an inivitation for sharing the subscription if the inviter is on a shared subscription', async () => {
userSubscriptionRepository.findOneByUserUuid = jest.fn().mockReturnValue({
subscriptionId: 2,
subscriptionType: UserSubscriptionType.Shared,
} as jest.Mocked<UserSubscription>)
await createUseCase().execute({
inviteeIdentifier: 'invitee@test.te',
inviterUuid: '1-2-3',
inviterEmail: 'inviter@test.te',
inviterRoles: [RoleName.ProUser],
})
expect(sharedSubscriptionInvitationRepository.save).not.toHaveBeenCalled()
expect(domainEventFactory.createSharedSubscriptionInvitationCreatedEvent).not.toHaveBeenCalled()
expect(domainEventPublisher.publish).not.toHaveBeenCalled()
})
})

View File

@@ -11,6 +11,7 @@ import { InviterIdentifierType } from '../../SharedSubscription/InviterIdentifie
import { SharedSubscriptionInvitation } from '../../SharedSubscription/SharedSubscriptionInvitation'
import { SharedSubscriptionInvitationRepositoryInterface } from '../../SharedSubscription/SharedSubscriptionInvitationRepositoryInterface'
import { UserSubscriptionRepositoryInterface } from '../../Subscription/UserSubscriptionRepositoryInterface'
import { UserSubscriptionType } from '../../Subscription/UserSubscriptionType'
import { UseCaseInterface } from '../UseCaseInterface'
import { InviteToSharedSubscriptionDTO } from './InviteToSharedSubscriptionDTO'
@@ -35,18 +36,18 @@ export class InviteToSharedSubscription implements UseCaseInterface {
}
}
const numberOfUsedInvites = await this.sharedSubscriptionInvitationRepository.countByInviterEmailAndStatus(
dto.inviterEmail,
[InvitationStatus.Sent, InvitationStatus.Accepted],
)
if (numberOfUsedInvites >= this.MAX_NUMBER_OF_INVITES) {
const inviterUserSubscription = await this.userSubscriptionRepository.findOneByUserUuid(dto.inviterUuid)
if (inviterUserSubscription === null || inviterUserSubscription.subscriptionType === UserSubscriptionType.Shared) {
return {
success: false,
}
}
const inviterUserSubscription = await this.userSubscriptionRepository.findOneByUserUuid(dto.inviterUuid)
if (inviterUserSubscription === null) {
const numberOfUsedInvites = await this.sharedSubscriptionInvitationRepository.countByInviterEmailAndStatus(
dto.inviterEmail,
[InvitationStatus.Sent, InvitationStatus.Accepted],
)
if (numberOfUsedInvites >= this.MAX_NUMBER_OF_INVITES) {
return {
success: false,
}

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.8.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.2...@standardnotes/domain-events-infra@1.8.3) (2022-09-06)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.1...@standardnotes/domain-events-infra@1.8.2) (2022-09-06)
**Note:** Version bump only for package @standardnotes/domain-events-infra
## [1.8.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.8.0...@standardnotes/domain-events-infra@1.8.1) (2022-09-06)
**Note:** Version bump only for package @standardnotes/domain-events-infra

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events-infra",
"version": "1.8.1",
"version": "1.8.3",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,19 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.59.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.59.0...@standardnotes/domain-events@2.59.1) (2022-09-06)
### Bug Fixes
* **api-gateway:** include period key in statistics measures ([d149f46](https://github.com/standardnotes/server/commit/d149f46cf6456201dd8690977f64ed32a75f3459))
* **api-gateway:** period types on analytics report ([f94c8fc](https://github.com/standardnotes/server/commit/f94c8fc26e684a07101cc5282ebb9cda3c8c6961))
# [2.59.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.58.0...@standardnotes/domain-events@2.59.0) (2022-09-06)
### Features
* **api-gateway:** add statistics measures to report generation ([8151bb1](https://github.com/standardnotes/server/commit/8151bb108affb2b5cfa1ab365f99a9f0170a7795))
# [2.58.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events@2.57.0...@standardnotes/domain-events@2.58.0) (2022-09-06)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events",
"version": "2.58.0",
"version": "2.59.1",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -12,6 +12,12 @@ export interface DailyAnalyticsReportGeneratedEventPayload {
retention: number
totalCount: number
}>
statisticMeasures: Array<{
name: string
totalValue: number
average: number
period: number
}>
activityStatisticsOverTime: Array<{
name: string
period: number

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.3.6](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.5...@standardnotes/event-store@1.3.6) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.5](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.4...@standardnotes/event-store@1.3.5) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.4](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.3...@standardnotes/event-store@1.3.4) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store
## [1.3.3](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.3.2...@standardnotes/event-store@1.3.3) (2022-09-06)
**Note:** Version bump only for package @standardnotes/event-store

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/event-store",
"version": "1.3.3",
"version": "1.3.6",
"description": "Event Store Service",
"private": true,
"main": "dist/src/index.js",

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.5.45](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.44...@standardnotes/files-server@1.5.45) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.44](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.43...@standardnotes/files-server@1.5.44) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.43](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.42...@standardnotes/files-server@1.5.43) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server
## [1.5.42](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.5.41...@standardnotes/files-server@1.5.42) (2022-09-06)
**Note:** Version bump only for package @standardnotes/files-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/files-server",
"version": "1.5.42",
"version": "1.5.45",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
@@ -71,6 +71,6 @@
"nodemon": "^2.0.19",
"npm-check-updates": "^16.0.1",
"ts-jest": "^28.0.5",
"uuid": "^8.3.2"
"uuid": "^9.0.0"
}
}

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.10.22](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.21...@standardnotes/scheduler-server@1.10.22) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.21](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.20...@standardnotes/scheduler-server@1.10.21) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.20](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.19...@standardnotes/scheduler-server@1.10.20) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.10.19](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.10.18...@standardnotes/scheduler-server@1.10.19) (2022-09-06)
**Note:** Version bump only for package @standardnotes/scheduler-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/scheduler-server",
"version": "1.10.19",
"version": "1.10.22",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.6.62](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.61...@standardnotes/syncing-server@1.6.62) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.61](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.60...@standardnotes/syncing-server@1.6.61) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.60](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.59...@standardnotes/syncing-server@1.6.60) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server
## [1.6.59](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.6.58...@standardnotes/syncing-server@1.6.59) (2022-09-06)
**Note:** Version bump only for package @standardnotes/syncing-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.6.59",
"version": "1.6.62",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
@@ -52,7 +52,7 @@
"reflect-metadata": "0.1.13",
"typeorm": "^0.3.6",
"ua-parser-js": "1.0.2",
"uuid": "8.3.2",
"uuid": "^9.0.0",
"winston": "^3.8.1"
},
"devDependencies": {

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.11.0](https://github.com/standardnotes/server/compare/@standardnotes/time@1.10.0...@standardnotes/time@1.11.0) (2022-09-06)
### Features
* **time:** add converting microseconds to time structure ([db8333a](https://github.com/standardnotes/server/commit/db8333a858ba0fa6750116967355d26e72b8c16d))
# [1.10.0](https://github.com/standardnotes/server/compare/@standardnotes/time@1.9.1...@standardnotes/time@1.10.0) (2022-09-05)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/time",
"version": "1.10.0",
"version": "1.11.0",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -1,4 +1,7 @@
export enum Time {
MicrosecondsInADay = 86_400_000_000,
MicrosecondsInAnHour = 3_600_000_000,
MicrosecondsInAMinute = 60_000_000,
MicrosecondsInASecond = 1_000_000,
MicrosecondsInAMillisecond = 1_000,
}

View File

@@ -0,0 +1,6 @@
export type TimeStructure = {
days: number
hours: number
minutes: number
seconds: number
}

View File

@@ -108,4 +108,13 @@ describe('Timer', () => {
it('should format date', () => {
expect(createTimer().formatDate(new Date('2021-03-29T08:00:05.233123Z'), 'YYYY-MM-DD')).toEqual('2021-03-29')
})
it('should convert microseconds to time structure', () => {
expect(createTimer().convertMicrosecondsToTimeStructure(1821050982073)).toEqual({
days: 21,
hours: 1,
minutes: 50,
seconds: 50,
})
})
})

View File

@@ -3,12 +3,33 @@ import * as utc from 'dayjs/plugin/utc'
import * as microtime from 'microtime'
import { Time } from './Time'
import { TimerInterface } from './TimerInterface'
import { TimeStructure } from './TimeStructure'
export class Timer implements TimerInterface {
constructor() {
dayjs.extend(utc)
}
convertMicrosecondsToTimeStructure(microseconds: number): TimeStructure {
const days = Math.floor(microseconds / Time.MicrosecondsInADay)
const hoursLeftOver = microseconds % Time.MicrosecondsInADay
const hours = Math.floor(hoursLeftOver / Time.MicrosecondsInAnHour)
const minutesLeftOver = microseconds % Time.MicrosecondsInAnHour
const minutes = Math.floor(minutesLeftOver / Time.MicrosecondsInAMinute)
const secondsLeftOver = microseconds % Time.MicrosecondsInAMinute
const seconds = Math.floor(secondsLeftOver / Time.MicrosecondsInASecond)
return {
days,
hours,
minutes,
seconds,
}
}
formatDate(date: Date, format: string): string {
return dayjs.utc(date).format(format)
}

View File

@@ -1,3 +1,5 @@
import { TimeStructure } from './TimeStructure'
export interface TimerInterface {
getTimestampInMicroseconds(): number
getTimestampInSeconds(): number
@@ -17,6 +19,7 @@ export interface TimerInterface {
convertMicrosecondsToSeconds(microseconds: number): number
convertMicrosecondsToStringDate(microseconds: number): string
convertMicrosecondsToDate(microseconds: number): Date
convertMicrosecondsToTimeStructure(microseconds: number): TimeStructure
formatDate(date: Date, format: string): string
dateWasNDaysAgo(date: Date): number
}

View File

@@ -1,3 +1,4 @@
export * from './Time/Time'
export * from './Time/Timer'
export * from './Time/TimerInterface'
export * from './Time/TimeStructure'

View File

@@ -1869,7 +1869,7 @@ __metadata:
ts-jest: ^28.0.5
typeorm: ^0.3.6
ua-parser-js: 1.0.2
uuid: 8.3.2
uuid: ^9.0.0
winston: ^3.8.1
languageName: unknown
linkType: soft
@@ -2048,7 +2048,7 @@ __metadata:
reflect-metadata: ^0.1.13
ts-jest: ^28.0.5
ts-node: ^10.9.1
uuid: ^8.3.2
uuid: ^9.0.0
winston: ^3.8.1
languageName: unknown
linkType: soft
@@ -2275,7 +2275,7 @@ __metadata:
ts-jest: ^28.0.5
typeorm: ^0.3.6
ua-parser-js: 1.0.2
uuid: 8.3.2
uuid: ^9.0.0
winston: ^3.8.1
languageName: unknown
linkType: soft
@@ -10429,7 +10429,7 @@ __metadata:
languageName: node
linkType: hard
"uuid@npm:8.3.2, uuid@npm:^8.3.2":
"uuid@npm:^8.3.2":
version: 8.3.2
resolution: "uuid@npm:8.3.2"
bin:
@@ -10438,6 +10438,15 @@ __metadata:
languageName: node
linkType: hard
"uuid@npm:^9.0.0":
version: 9.0.0
resolution: "uuid@npm:9.0.0"
bin:
uuid: dist/bin/uuid
checksum: 8dd2c83c43ddc7e1c71e36b60aea40030a6505139af6bee0f382ebcd1a56f6cd3028f7f06ffb07f8cf6ced320b76aea275284b224b002b289f89fe89c389b028
languageName: node
linkType: hard
"v8-compile-cache-lib@npm:^3.0.1":
version: 3.0.1
resolution: "v8-compile-cache-lib@npm:3.0.1"