@oneuptime/common 7.0.2976 → 7.0.2981
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/Models/AnalyticsModels/AnalyticsBaseModel/CommonModel.ts +8 -7
- package/Models/DatabaseModels/Monitor.ts +36 -0
- package/Server/API/BaseAnalyticsAPI.ts +2 -6
- package/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.ts +23 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
- package/Server/Services/AnalyticsDatabaseService.ts +2 -2
- package/Server/Services/DatabaseService.ts +2 -2
- package/Server/Services/MonitorService.ts +9 -0
- package/Server/Services/ProjectService.ts +16 -2
- package/Server/Services/StatusPageHeaderLinkService.ts +1 -1
- package/Server/Types/AnalyticsDatabase/QueryHelper.ts +8 -7
- package/Server/Types/Database/Query.ts +6 -20
- package/Server/Types/Database/QueryHelper.ts +59 -42
- package/Server/Types/Database/QueryUtil.ts +8 -7
- package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +1 -1
- package/Tests/Types/Database/CompareBase.test.ts +6 -6
- package/Tests/Types/Database/Date.test.ts +1 -1
- package/Tests/Types/Database/EqualToOrNull.test.ts +14 -8
- package/Tests/Types/Database/InBetween.test.ts +8 -8
- package/Tests/Types/Database/NotEqual.test.ts +2 -2
- package/Types/BaseDatabase/AggregateBy.ts +1 -1
- package/Types/BaseDatabase/EqualToOrNull.ts +12 -16
- package/Types/BaseDatabase/GreaterThan.ts +8 -6
- package/Types/BaseDatabase/GreaterThanOrEqual.ts +10 -6
- package/Types/BaseDatabase/InBetween.ts +21 -23
- package/Types/BaseDatabase/Includes.ts +2 -2
- package/Types/BaseDatabase/IsNull.ts +3 -2
- package/Types/BaseDatabase/LessThan.ts +8 -6
- package/Types/BaseDatabase/LessThanOrEqual.ts +10 -6
- package/Types/BaseDatabase/NotEqual.ts +10 -17
- package/Types/BaseDatabase/NotNull.ts +3 -2
- package/Types/BaseDatabase/Query.ts +17 -6
- package/Types/BaseDatabase/QueryOperator.ts +11 -0
- package/Types/BaseDatabase/Search.ts +12 -10
- package/Types/Database/CompareBase.ts +10 -6
- package/Types/Database/Date.ts +1 -1
- package/Types/Date.ts +3 -1
- package/Types/Domain.ts +1 -1
- package/Types/JSON.ts +17 -16
- package/Types/JSONFunctions.ts +3 -2
- package/UI/Components/Date/StartAndEndDate.tsx +6 -8
- package/UI/Components/Filters/DateFilter.tsx +6 -3
- package/UI/Components/Filters/FilterViewer.tsx +3 -1
- package/UI/Components/Filters/JSONFilter.tsx +4 -1
- package/UI/Components/Filters/Types/FilterData.ts +1 -1
- package/UI/Components/HeaderAlert/HeaderModelAlert.tsx +1 -1
- package/UI/Components/ModelFilter/Filter.ts +1 -1
- package/UI/Components/ModelList/ModelList.tsx +1 -1
- package/UI/Components/ModelListModal/ModelListModal.tsx +1 -1
- package/UI/Components/ModelProgress/ModelProgress.tsx +1 -1
- package/UI/Components/ModelTable/AnalyticsModelTable.tsx +1 -1
- package/UI/Components/ModelTable/BaseModelTable.tsx +1 -1
- package/UI/Components/ModelTable/ModelTable.tsx +1 -1
- package/UI/Components/SideMenu/CountModelSideMenuItem.tsx +1 -1
- package/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.ts +1 -1
- package/UI/Utils/ModelAPI/ModelAPI.ts +1 -1
- package/UI/Utils/Realtime.ts +1 -1
- package/Utils/CronTime.ts +1 -0
- package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/CommonModel.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Monitor.js +36 -0
- package/build/dist/Models/DatabaseModels/Monitor.js.map +1 -1
- package/build/dist/Server/API/BaseAnalyticsAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +2 -2
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/MonitorService.js +7 -0
- package/build/dist/Server/Services/MonitorService.js.map +1 -1
- package/build/dist/Server/Services/ProjectService.js +15 -2
- package/build/dist/Server/Services/ProjectService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageHeaderLinkService.js.map +1 -1
- package/build/dist/Server/Types/AnalyticsDatabase/QueryHelper.js.map +1 -1
- package/build/dist/Server/Types/Database/QueryHelper.js.map +1 -1
- package/build/dist/Server/Types/Database/QueryUtil.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
- package/build/dist/Tests/Types/Database/CompareBase.test.js.map +1 -1
- package/build/dist/Tests/Types/Database/EqualToOrNull.test.js.map +1 -1
- package/build/dist/Tests/Types/Database/InBetween.test.js.map +1 -1
- package/build/dist/Tests/Types/Database/NotEqual.test.js.map +1 -1
- package/build/dist/Types/BaseDatabase/EqualToOrNull.js +4 -10
- package/build/dist/Types/BaseDatabase/EqualToOrNull.js.map +1 -1
- package/build/dist/Types/BaseDatabase/GreaterThan.js.map +1 -1
- package/build/dist/Types/BaseDatabase/GreaterThanOrEqual.js.map +1 -1
- package/build/dist/Types/BaseDatabase/InBetween.js +2 -2
- package/build/dist/Types/BaseDatabase/InBetween.js.map +1 -1
- package/build/dist/Types/BaseDatabase/Includes.js +2 -2
- package/build/dist/Types/BaseDatabase/Includes.js.map +1 -1
- package/build/dist/Types/BaseDatabase/IsNull.js +2 -2
- package/build/dist/Types/BaseDatabase/IsNull.js.map +1 -1
- package/build/dist/Types/BaseDatabase/LessThan.js.map +1 -1
- package/build/dist/Types/BaseDatabase/LessThanOrEqual.js.map +1 -1
- package/build/dist/Types/BaseDatabase/NotEqual.js +4 -11
- package/build/dist/Types/BaseDatabase/NotEqual.js.map +1 -1
- package/build/dist/Types/BaseDatabase/NotNull.js +2 -2
- package/build/dist/Types/BaseDatabase/NotNull.js.map +1 -1
- package/build/dist/Types/BaseDatabase/QueryOperator.js +7 -0
- package/build/dist/Types/BaseDatabase/QueryOperator.js.map +1 -0
- package/build/dist/Types/BaseDatabase/Search.js +2 -2
- package/build/dist/Types/BaseDatabase/Search.js.map +1 -1
- package/build/dist/Types/Database/CompareBase.js +2 -2
- package/build/dist/Types/Database/CompareBase.js.map +1 -1
- package/build/dist/Types/Date.js.map +1 -1
- package/build/dist/Types/Domain.js +1 -1
- package/build/dist/Types/Domain.js.map +1 -1
- package/build/dist/Types/JSON.js.map +1 -1
- package/build/dist/Types/JSONFunctions.js.map +1 -1
- package/build/dist/UI/Components/Date/StartAndEndDate.js.map +1 -1
- package/build/dist/UI/Components/Filters/DateFilter.js.map +1 -1
- package/build/dist/UI/Components/Filters/FilterViewer.js.map +1 -1
- package/build/dist/UI/Components/Filters/JSONFilter.js.map +1 -1
- package/build/dist/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.js.map +1 -1
- package/build/dist/UI/Utils/ModelAPI/ModelAPI.js.map +1 -1
- package/build/dist/UI/Utils/Realtime.js.map +1 -1
- package/build/dist/Utils/CronTime.js +1 -0
- package/build/dist/Utils/CronTime.js.map +1 -1
- package/package.json +2 -2
- package/UI/Utils/BaseDatabase/Query.ts +0 -25
- package/build/dist/UI/Utils/BaseDatabase/Query.js +0 -2
- package/build/dist/UI/Utils/BaseDatabase/Query.js.map +0 -1
|
@@ -9,6 +9,7 @@ import LessThan from "../../../Types/BaseDatabase/LessThan";
|
|
|
9
9
|
import LessThanOrEqual from "../../../Types/BaseDatabase/LessThanOrEqual";
|
|
10
10
|
import NotEqual from "../../../Types/BaseDatabase/NotEqual";
|
|
11
11
|
import Search from "../../../Types/BaseDatabase/Search";
|
|
12
|
+
import { CompareType } from "../../../Types/Database/CompareBase";
|
|
12
13
|
import OneUptimeDate from "../../../Types/Date";
|
|
13
14
|
import BadDataException from "../../../Types/Exception/BadDataException";
|
|
14
15
|
import { JSONArray, JSONObject, JSONValue } from "../../../Types/JSON";
|
|
@@ -21,15 +22,15 @@ export type RecordValue =
|
|
|
21
22
|
| number
|
|
22
23
|
| boolean
|
|
23
24
|
| Date
|
|
24
|
-
| Search
|
|
25
|
-
| NotEqual
|
|
26
|
-
| GreaterThan
|
|
27
|
-
| InBetween
|
|
25
|
+
| Search<string>
|
|
26
|
+
| NotEqual<CompareType>
|
|
27
|
+
| GreaterThan<CompareType>
|
|
28
|
+
| InBetween<CompareType>
|
|
28
29
|
| Includes
|
|
29
30
|
| Date
|
|
30
|
-
| LessThan
|
|
31
|
-
| LessThanOrEqual
|
|
32
|
-
| GreaterThanOrEqual
|
|
31
|
+
| LessThan<CompareType>
|
|
32
|
+
| LessThanOrEqual<CompareType>
|
|
33
|
+
| GreaterThanOrEqual<CompareType>
|
|
33
34
|
| Array<number>
|
|
34
35
|
| Array<string>
|
|
35
36
|
| Array<ObjectID>
|
|
@@ -709,6 +709,42 @@ export default class Monitor extends BaseModel {
|
|
|
709
709
|
})
|
|
710
710
|
public incomingRequestReceivedAt?: Date = undefined;
|
|
711
711
|
|
|
712
|
+
@ColumnAccessControl({
|
|
713
|
+
create: [
|
|
714
|
+
Permission.ProjectOwner,
|
|
715
|
+
Permission.ProjectAdmin,
|
|
716
|
+
Permission.ProjectMember,
|
|
717
|
+
Permission.CreateProjectMonitor,
|
|
718
|
+
],
|
|
719
|
+
read: [
|
|
720
|
+
Permission.ProjectOwner,
|
|
721
|
+
Permission.ProjectAdmin,
|
|
722
|
+
Permission.ProjectMember,
|
|
723
|
+
Permission.ReadProjectMonitor,
|
|
724
|
+
],
|
|
725
|
+
update: [
|
|
726
|
+
Permission.ProjectOwner,
|
|
727
|
+
Permission.ProjectAdmin,
|
|
728
|
+
Permission.ProjectMember,
|
|
729
|
+
Permission.CreateProjectMonitor,
|
|
730
|
+
],
|
|
731
|
+
})
|
|
732
|
+
@Index()
|
|
733
|
+
@TableColumn({
|
|
734
|
+
type: TableColumnType.Date,
|
|
735
|
+
required: false,
|
|
736
|
+
isDefaultValueColumn: false,
|
|
737
|
+
title:
|
|
738
|
+
"When was the last time we checked the heartbeat for incoming request?",
|
|
739
|
+
description:
|
|
740
|
+
"This field is for Incoming Request monitor only. When was the last time we checked the heartbeat?",
|
|
741
|
+
})
|
|
742
|
+
@Column({
|
|
743
|
+
type: ColumnType.Date,
|
|
744
|
+
nullable: true,
|
|
745
|
+
})
|
|
746
|
+
public incomingRequestMonitorHeartbeatCheckedAt?: Date = undefined;
|
|
747
|
+
|
|
712
748
|
@ColumnAccessControl({
|
|
713
749
|
create: [
|
|
714
750
|
Permission.ProjectOwner,
|
|
@@ -234,9 +234,7 @@ export default class BaseAnalyticsAPI<
|
|
|
234
234
|
let groupBy: GroupBy<AnalyticsDataModel> = {};
|
|
235
235
|
|
|
236
236
|
if (req.body) {
|
|
237
|
-
query = JSONFunctions.deserialize(
|
|
238
|
-
req.body["query"],
|
|
239
|
-
) as Query<AnalyticsDataModel>;
|
|
237
|
+
query = JSONFunctions.deserialize(req.body["query"]) as Query<any>;
|
|
240
238
|
|
|
241
239
|
select = JSONFunctions.deserialize(
|
|
242
240
|
req.body["select"],
|
|
@@ -316,9 +314,7 @@ export default class BaseAnalyticsAPI<
|
|
|
316
314
|
await this.onBeforeCount(req, res);
|
|
317
315
|
|
|
318
316
|
if (req.body) {
|
|
319
|
-
query = JSONFunctions.deserialize(
|
|
320
|
-
req.body["query"],
|
|
321
|
-
) as Query<AnalyticsDataModel>;
|
|
317
|
+
query = JSONFunctions.deserialize(req.body["query"]) as Query<any>;
|
|
322
318
|
}
|
|
323
319
|
|
|
324
320
|
const databaseProps: DatabaseCommonInteractionProps =
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1724078044172 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1724078044172";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "Monitor" ADD "incomingRequestMonitorHeartbeatCheckedAt" TIMESTAMP WITH TIME ZONE`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`CREATE INDEX "IDX_62cf90e5fbcd9f3742ed35a2bb" ON "Monitor" ("incomingRequestMonitorHeartbeatCheckedAt") `,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`DROP INDEX "public"."IDX_62cf90e5fbcd9f3742ed35a2bb"`,
|
|
18
|
+
);
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "Monitor" DROP COLUMN "incomingRequestMonitorHeartbeatCheckedAt"`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -40,6 +40,7 @@ import { MigrationName1722543640526 } from "./1722543640526-MigrationName";
|
|
|
40
40
|
import { MigrationName1722892318363 } from "./1722892318363-MigrationName";
|
|
41
41
|
import { MigrationName1723825511054 } from "./1723825511054-MigrationName";
|
|
42
42
|
import { MigrationName1723828588502 } from "./1723828588502-MigrationName";
|
|
43
|
+
import { MigrationName1724078044172 } from "./1724078044172-MigrationName";
|
|
43
44
|
|
|
44
45
|
export default [
|
|
45
46
|
InitialMigration,
|
|
@@ -84,4 +85,5 @@ export default [
|
|
|
84
85
|
MigrationName1722892318363,
|
|
85
86
|
MigrationName1723825511054,
|
|
86
87
|
MigrationName1723828588502,
|
|
88
|
+
MigrationName1724078044172,
|
|
87
89
|
];
|
|
@@ -208,8 +208,8 @@ export default class AnalyticsDatabaseService<
|
|
|
208
208
|
aggregateBy.limit = 10;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
if (!aggregateBy.
|
|
212
|
-
throw new BadDataException("
|
|
211
|
+
if (!aggregateBy.aggregationType) {
|
|
212
|
+
throw new BadDataException("aggregationType is required");
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
if (!aggregateBy.aggregationTimestampColumnName) {
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "../Types/Database/Hooks";
|
|
19
19
|
import ModelPermission from "../Types/Database/Permissions/Index";
|
|
20
20
|
import { CheckReadPermissionType } from "../Types/Database/Permissions/ReadPermission";
|
|
21
|
-
import Query
|
|
21
|
+
import Query from "../Types/Database/Query";
|
|
22
22
|
import QueryHelper from "../Types/Database/QueryHelper";
|
|
23
23
|
import RelationSelect from "../Types/Database/RelationSelect";
|
|
24
24
|
import SearchBy from "../Types/Database/SearchBy";
|
|
@@ -60,6 +60,7 @@ import API from "Common/Utils/API";
|
|
|
60
60
|
import Slug from "Common/Utils/Slug";
|
|
61
61
|
import { DataSource, Repository, SelectQueryBuilder } from "typeorm";
|
|
62
62
|
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
|
63
|
+
import { FindWhere } from "../../Types/BaseDatabase/Query";
|
|
63
64
|
|
|
64
65
|
class DatabaseService<TBaseModel extends BaseModel> extends BaseService {
|
|
65
66
|
public modelType!: { new (): TBaseModel };
|
|
@@ -691,7 +692,6 @@ class DatabaseService<TBaseModel extends BaseModel> extends BaseService {
|
|
|
691
692
|
[totalItemsColumnName]:
|
|
692
693
|
createdBy.data.getColumnValue(totalItemsColumnName),
|
|
693
694
|
} as FindWhere<TBaseModel>,
|
|
694
|
-
|
|
695
695
|
skip: 0,
|
|
696
696
|
limit: LIMIT_MAX,
|
|
697
697
|
props: {
|
|
@@ -49,6 +49,7 @@ import { SMSMessage } from "../../Types/SMS/SMS";
|
|
|
49
49
|
import { CallRequestMessage } from "../../Types/Call/CallRequest";
|
|
50
50
|
import UserNotificationSettingService from "./UserNotificationSettingService";
|
|
51
51
|
import NotificationSettingEventType from "../../Types/NotificationSetting/NotificationSettingEventType";
|
|
52
|
+
import Query from "../Types/Database/Query";
|
|
52
53
|
|
|
53
54
|
export class Service extends DatabaseService<Model> {
|
|
54
55
|
public constructor() {
|
|
@@ -126,6 +127,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
126
127
|
return { updateBy, carryForward: null };
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
public getEnabledMonitorQuery(): Query<Model> {
|
|
131
|
+
return {
|
|
132
|
+
disableActiveMonitoring: false, // do not fetch if disabled is true.
|
|
133
|
+
disableActiveMonitoringBecauseOfManualIncident: false,
|
|
134
|
+
disableActiveMonitoringBecauseOfScheduledMaintenanceEvent: false,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
129
138
|
protected override async onBeforeCreate(
|
|
130
139
|
createBy: CreateBy<Model>,
|
|
131
140
|
): Promise<OnCreate<Model>> {
|
|
@@ -48,8 +48,8 @@ import Team from "Common/Models/DatabaseModels/Team";
|
|
|
48
48
|
import TeamMember from "Common/Models/DatabaseModels/TeamMember";
|
|
49
49
|
import TeamPermission from "Common/Models/DatabaseModels/TeamPermission";
|
|
50
50
|
import User from "Common/Models/DatabaseModels/User";
|
|
51
|
-
import { In } from "typeorm";
|
|
52
51
|
import Select from "../Types/Database/Select";
|
|
52
|
+
import Query from "../Types/Database/Query";
|
|
53
53
|
|
|
54
54
|
export interface CurrentPlan {
|
|
55
55
|
plan: PlanType | null;
|
|
@@ -886,7 +886,7 @@ export class ProjectService extends DatabaseService<Model> {
|
|
|
886
886
|
findBy.props.userGlobalAccessPermission?.projectIds.length === 0
|
|
887
887
|
) {
|
|
888
888
|
findBy.props.isRoot = true;
|
|
889
|
-
findBy.query._id =
|
|
889
|
+
findBy.query._id = ObjectID.getZeroObjectID().toString(); // should not get any projects.
|
|
890
890
|
}
|
|
891
891
|
|
|
892
892
|
return { findBy, carryForward: null };
|
|
@@ -1114,6 +1114,20 @@ export class ProjectService extends DatabaseService<Model> {
|
|
|
1114
1114
|
});
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
|
+
public getActiveProjectStatusQuery(): Query<Model> {
|
|
1118
|
+
return {
|
|
1119
|
+
// get only active projects
|
|
1120
|
+
paymentProviderSubscriptionStatus: QueryHelper.equalToOrNull([
|
|
1121
|
+
SubscriptionStatus.Active,
|
|
1122
|
+
SubscriptionStatus.Trialing,
|
|
1123
|
+
]),
|
|
1124
|
+
paymentProviderMeteredSubscriptionStatus: QueryHelper.equalToOrNull([
|
|
1125
|
+
SubscriptionStatus.Active,
|
|
1126
|
+
SubscriptionStatus.Trialing,
|
|
1127
|
+
]),
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1117
1131
|
public async isSMSNotificationsEnabled(
|
|
1118
1132
|
projectId: ObjectID,
|
|
1119
1133
|
): Promise<boolean> {
|
|
@@ -192,7 +192,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
192
192
|
// get status page resource with this order.
|
|
193
193
|
const resources: Array<Model> = await this.findBy({
|
|
194
194
|
query: {
|
|
195
|
-
order: QueryHelper.greaterThanEqualTo(currentOrder),
|
|
195
|
+
order: QueryHelper.greaterThanEqualTo<number>(currentOrder),
|
|
196
196
|
statusPageId: statusPageId,
|
|
197
197
|
},
|
|
198
198
|
limit: LIMIT_MAX,
|
|
@@ -3,9 +3,10 @@ import InBetween from "Common/Types/BaseDatabase/InBetween";
|
|
|
3
3
|
import Includes from "Common/Types/BaseDatabase/Includes";
|
|
4
4
|
import LessThan from "Common/Types/BaseDatabase/LessThan";
|
|
5
5
|
import ObjectID from "Common/Types/ObjectID";
|
|
6
|
+
import { CompareType } from "../../../Types/Database/CompareBase";
|
|
6
7
|
|
|
7
8
|
export default class QueryHelper {
|
|
8
|
-
public static lessThan(value:
|
|
9
|
+
public static lessThan<T extends CompareType>(value: T): LessThan<T> {
|
|
9
10
|
return new LessThan(value);
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -13,14 +14,14 @@ export default class QueryHelper {
|
|
|
13
14
|
return new Includes(values);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
public static greaterThan(value:
|
|
17
|
-
return new GreaterThan(value);
|
|
17
|
+
public static greaterThan<T extends CompareType>(value: T): GreaterThan<T> {
|
|
18
|
+
return new GreaterThan<T>(value);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
public static inBetween(
|
|
21
|
-
startValue:
|
|
22
|
-
endValue:
|
|
23
|
-
): InBetween {
|
|
21
|
+
public static inBetween<T extends CompareType>(
|
|
22
|
+
startValue: T,
|
|
23
|
+
endValue: T,
|
|
24
|
+
): InBetween<T> {
|
|
24
25
|
return new InBetween(startValue, endValue);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import BaseModel from "Common/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import BaseQuery, {
|
|
3
|
+
OrQuery as BaseQueryOrQuery,
|
|
4
|
+
} from "../../../Types/BaseDatabase/Query";
|
|
4
5
|
|
|
5
|
-
export declare type
|
|
6
|
-
|
|
7
|
-
? Property | FindOperator<Property> | Array<Property>
|
|
8
|
-
: FindOptionsWhereProperty<Property>;
|
|
9
|
-
/**
|
|
10
|
-
* :
|
|
11
|
-
* Used for find operations.
|
|
12
|
-
*/
|
|
13
|
-
export declare type FindWhere<Entity> = {
|
|
14
|
-
[P in keyof Entity]?:
|
|
15
|
-
| FindWhereProperty<NonNullable<Entity[P]>>
|
|
16
|
-
| FindOperator<NonNullable<Entity[P]>>;
|
|
17
|
-
};
|
|
6
|
+
export declare type OrQuery<TBaseModel extends BaseModel> =
|
|
7
|
+
BaseQueryOrQuery<TBaseModel>;
|
|
18
8
|
|
|
19
|
-
declare type Query<TBaseModel extends BaseModel> =
|
|
20
|
-
|
|
21
|
-
export declare type OrQuery<TBaseModel extends BaseModel> = Array<
|
|
22
|
-
Query<TBaseModel>
|
|
23
|
-
>;
|
|
9
|
+
declare type Query<TBaseModel extends BaseModel> = BaseQuery<TBaseModel>;
|
|
24
10
|
|
|
25
11
|
export default Query;
|
|
@@ -5,9 +5,12 @@ import ObjectID from "Common/Types/ObjectID";
|
|
|
5
5
|
import Text from "Common/Types/Text";
|
|
6
6
|
import Typeof from "Common/Types/Typeof";
|
|
7
7
|
import { FindOperator, Raw } from "typeorm";
|
|
8
|
+
import { FindWhereProperty } from "../../../Types/BaseDatabase/Query";
|
|
8
9
|
|
|
9
10
|
export default class QueryHelper {
|
|
10
|
-
public static findWithSameText(
|
|
11
|
+
public static findWithSameText(
|
|
12
|
+
text: string | number,
|
|
13
|
+
): FindWhereProperty<any> {
|
|
11
14
|
let isString: boolean = false;
|
|
12
15
|
|
|
13
16
|
if (typeof text === Typeof.String) {
|
|
@@ -41,7 +44,7 @@ export default class QueryHelper {
|
|
|
41
44
|
|
|
42
45
|
public static equalToOrNull(
|
|
43
46
|
value: string | ObjectID | Array<string | ObjectID>,
|
|
44
|
-
):
|
|
47
|
+
): FindWhereProperty<any> {
|
|
45
48
|
const rid: Array<string> = [];
|
|
46
49
|
const valuesObj: Dictionary<string> = {};
|
|
47
50
|
|
|
@@ -85,7 +88,7 @@ export default class QueryHelper {
|
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
public static notEquals(value: string | ObjectID):
|
|
91
|
+
public static notEquals(value: string | ObjectID): FindWhereProperty<any> {
|
|
89
92
|
const rid: string = Text.generateRandomText(10);
|
|
90
93
|
return Raw(
|
|
91
94
|
(alias: string) => {
|
|
@@ -97,7 +100,7 @@ export default class QueryHelper {
|
|
|
97
100
|
);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
public static search(name: string):
|
|
103
|
+
public static search(name: string): FindWhereProperty<any> {
|
|
101
104
|
name = name.toLowerCase().trim();
|
|
102
105
|
const rid: string = Text.generateRandomText(10);
|
|
103
106
|
return Raw(
|
|
@@ -110,7 +113,7 @@ export default class QueryHelper {
|
|
|
110
113
|
);
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
public static all(values: Array<string | ObjectID>):
|
|
116
|
+
public static all(values: Array<string | ObjectID>): FindWhereProperty<any> {
|
|
114
117
|
values = values.map((value: string | ObjectID) => {
|
|
115
118
|
return value.toString();
|
|
116
119
|
});
|
|
@@ -134,13 +137,13 @@ export default class QueryHelper {
|
|
|
134
137
|
|
|
135
138
|
public static any(
|
|
136
139
|
values: Array<string | ObjectID | number>,
|
|
137
|
-
):
|
|
140
|
+
): FindWhereProperty<any> {
|
|
138
141
|
return this.in(values); // any and in are the same
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
private static in(
|
|
142
145
|
values: Array<string | ObjectID | number>,
|
|
143
|
-
):
|
|
146
|
+
): FindWhereProperty<any> {
|
|
144
147
|
values = values.map((value: string | ObjectID | number) => {
|
|
145
148
|
return value.toString();
|
|
146
149
|
});
|
|
@@ -162,7 +165,9 @@ export default class QueryHelper {
|
|
|
162
165
|
);
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
public static notIn(
|
|
168
|
+
public static notIn(
|
|
169
|
+
values: Array<string | ObjectID>,
|
|
170
|
+
): FindWhereProperty<any> {
|
|
166
171
|
values = values.map((value: string | ObjectID) => {
|
|
167
172
|
return value.toString();
|
|
168
173
|
});
|
|
@@ -186,7 +191,7 @@ export default class QueryHelper {
|
|
|
186
191
|
|
|
187
192
|
public static notInOrNull(
|
|
188
193
|
values: Array<string | ObjectID>,
|
|
189
|
-
):
|
|
194
|
+
): FindWhereProperty<any> {
|
|
190
195
|
values = values.map((value: string | ObjectID) => {
|
|
191
196
|
return value.toString();
|
|
192
197
|
});
|
|
@@ -220,7 +225,7 @@ export default class QueryHelper {
|
|
|
220
225
|
});
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
public static equalTo(value: string):
|
|
228
|
+
public static equalTo(value: string): FindWhereProperty<any> {
|
|
224
229
|
const rid: string = Text.generateRandomText(10);
|
|
225
230
|
return Raw(
|
|
226
231
|
(alias: string) => {
|
|
@@ -232,7 +237,9 @@ export default class QueryHelper {
|
|
|
232
237
|
);
|
|
233
238
|
}
|
|
234
239
|
|
|
235
|
-
public static greaterThanEqualTo
|
|
240
|
+
public static greaterThanEqualTo<T extends number | Date>(
|
|
241
|
+
value: T,
|
|
242
|
+
): FindWhereProperty<T> {
|
|
236
243
|
const rid: string = Text.generateRandomText(10);
|
|
237
244
|
return Raw(
|
|
238
245
|
(alias: string) => {
|
|
@@ -241,12 +248,12 @@ export default class QueryHelper {
|
|
|
241
248
|
{
|
|
242
249
|
[rid]: value,
|
|
243
250
|
},
|
|
244
|
-
)
|
|
251
|
+
) as FindWhereProperty<T>;
|
|
245
252
|
}
|
|
246
253
|
|
|
247
|
-
public static greaterThanEqualToOrNull(
|
|
248
|
-
value:
|
|
249
|
-
):
|
|
254
|
+
public static greaterThanEqualToOrNull<T extends number | Date>(
|
|
255
|
+
value: T,
|
|
256
|
+
): FindWhereProperty<T> {
|
|
250
257
|
const rid: string = Text.generateRandomText(10);
|
|
251
258
|
return Raw(
|
|
252
259
|
(alias: string) => {
|
|
@@ -255,10 +262,12 @@ export default class QueryHelper {
|
|
|
255
262
|
{
|
|
256
263
|
[rid]: value,
|
|
257
264
|
},
|
|
258
|
-
)
|
|
265
|
+
) as FindWhereProperty<T>;
|
|
259
266
|
}
|
|
260
267
|
|
|
261
|
-
public static lessThanEqualTo
|
|
268
|
+
public static lessThanEqualTo<T extends number | Date>(
|
|
269
|
+
value: T,
|
|
270
|
+
): FindWhereProperty<T> {
|
|
262
271
|
const rid: string = Text.generateRandomText(10);
|
|
263
272
|
return Raw(
|
|
264
273
|
(alias: string) => {
|
|
@@ -267,10 +276,12 @@ export default class QueryHelper {
|
|
|
267
276
|
{
|
|
268
277
|
[rid]: value,
|
|
269
278
|
},
|
|
270
|
-
)
|
|
279
|
+
) as FindWhereProperty<T>;
|
|
271
280
|
}
|
|
272
281
|
|
|
273
|
-
public static lessThanEqualToOrNull
|
|
282
|
+
public static lessThanEqualToOrNull<T extends number | Date>(
|
|
283
|
+
value: T,
|
|
284
|
+
): FindWhereProperty<T> {
|
|
274
285
|
const rid: string = Text.generateRandomText(10);
|
|
275
286
|
return Raw(
|
|
276
287
|
(alias: string) => {
|
|
@@ -279,10 +290,12 @@ export default class QueryHelper {
|
|
|
279
290
|
{
|
|
280
291
|
[rid]: value,
|
|
281
292
|
},
|
|
282
|
-
)
|
|
293
|
+
) as FindWhereProperty<T>;
|
|
283
294
|
}
|
|
284
295
|
|
|
285
|
-
public static greaterThan
|
|
296
|
+
public static greaterThan<T extends number | Date>(
|
|
297
|
+
value: T,
|
|
298
|
+
): FindWhereProperty<number | Date> {
|
|
286
299
|
const rid: string = Text.generateRandomText(10);
|
|
287
300
|
return Raw(
|
|
288
301
|
(alias: string) => {
|
|
@@ -291,10 +304,12 @@ export default class QueryHelper {
|
|
|
291
304
|
{
|
|
292
305
|
[rid]: value,
|
|
293
306
|
},
|
|
294
|
-
)
|
|
307
|
+
) as FindWhereProperty<T>;
|
|
295
308
|
}
|
|
296
309
|
|
|
297
|
-
public static greaterThanOrNull
|
|
310
|
+
public static greaterThanOrNull<T extends number | Date>(
|
|
311
|
+
value: T,
|
|
312
|
+
): FindWhereProperty<T> {
|
|
298
313
|
const rid: string = Text.generateRandomText(10);
|
|
299
314
|
return Raw(
|
|
300
315
|
(alias: string) => {
|
|
@@ -303,13 +318,13 @@ export default class QueryHelper {
|
|
|
303
318
|
{
|
|
304
319
|
[rid]: value,
|
|
305
320
|
},
|
|
306
|
-
)
|
|
321
|
+
) as FindWhereProperty<T>;
|
|
307
322
|
}
|
|
308
323
|
|
|
309
|
-
public static inBetween(
|
|
310
|
-
startValue:
|
|
311
|
-
endValue:
|
|
312
|
-
):
|
|
324
|
+
public static inBetween<T extends number | Date>(
|
|
325
|
+
startValue: T,
|
|
326
|
+
endValue: T,
|
|
327
|
+
): FindWhereProperty<T> {
|
|
313
328
|
const rid1: string = Text.generateRandomText(10);
|
|
314
329
|
const rid2: string = Text.generateRandomText(10);
|
|
315
330
|
return Raw(
|
|
@@ -320,13 +335,13 @@ export default class QueryHelper {
|
|
|
320
335
|
[rid1]: startValue,
|
|
321
336
|
[rid2]: endValue,
|
|
322
337
|
},
|
|
323
|
-
)
|
|
338
|
+
) as FindWhereProperty<T>;
|
|
324
339
|
}
|
|
325
340
|
|
|
326
|
-
public static inBetweenOrNull(
|
|
327
|
-
startValue:
|
|
328
|
-
endValue:
|
|
329
|
-
):
|
|
341
|
+
public static inBetweenOrNull<T extends number | Date>(
|
|
342
|
+
startValue: T,
|
|
343
|
+
endValue: T,
|
|
344
|
+
): FindWhereProperty<T> {
|
|
330
345
|
const rid1: string = Text.generateRandomText(10);
|
|
331
346
|
const rid2: string = Text.generateRandomText(10);
|
|
332
347
|
return Raw(
|
|
@@ -337,13 +352,13 @@ export default class QueryHelper {
|
|
|
337
352
|
[rid1]: startValue,
|
|
338
353
|
[rid2]: endValue,
|
|
339
354
|
},
|
|
340
|
-
)
|
|
355
|
+
) as FindWhereProperty<T>;
|
|
341
356
|
}
|
|
342
357
|
|
|
343
|
-
public static notInBetween(
|
|
344
|
-
startValue:
|
|
345
|
-
endValue:
|
|
346
|
-
):
|
|
358
|
+
public static notInBetween<T extends number | Date>(
|
|
359
|
+
startValue: T,
|
|
360
|
+
endValue: T,
|
|
361
|
+
): FindWhereProperty<T> {
|
|
347
362
|
const rid1: string = Text.generateRandomText(10);
|
|
348
363
|
const rid2: string = Text.generateRandomText(10);
|
|
349
364
|
return Raw(
|
|
@@ -354,10 +369,10 @@ export default class QueryHelper {
|
|
|
354
369
|
[rid1]: startValue,
|
|
355
370
|
[rid2]: endValue,
|
|
356
371
|
},
|
|
357
|
-
)
|
|
372
|
+
) as FindWhereProperty<T>;
|
|
358
373
|
}
|
|
359
374
|
|
|
360
|
-
public static queryJson(value: JSONObject):
|
|
375
|
+
public static queryJson(value: JSONObject): FindWhereProperty<any> {
|
|
361
376
|
// seed random text
|
|
362
377
|
const values: JSONObject = {};
|
|
363
378
|
|
|
@@ -407,7 +422,9 @@ export default class QueryHelper {
|
|
|
407
422
|
}, values);
|
|
408
423
|
}
|
|
409
424
|
|
|
410
|
-
public static lessThan
|
|
425
|
+
public static lessThan<T extends number | Date>(
|
|
426
|
+
value: T,
|
|
427
|
+
): FindWhereProperty<T> {
|
|
411
428
|
const rid: string = Text.generateRandomText(10);
|
|
412
429
|
return Raw(
|
|
413
430
|
(alias: string) => {
|
|
@@ -416,6 +433,6 @@ export default class QueryHelper {
|
|
|
416
433
|
{
|
|
417
434
|
[rid]: value,
|
|
418
435
|
},
|
|
419
|
-
)
|
|
436
|
+
) as FindWhereProperty<T>;
|
|
420
437
|
}
|
|
421
438
|
}
|
|
@@ -18,6 +18,7 @@ import { JSONObject } from "Common/Types/JSON";
|
|
|
18
18
|
import ObjectID from "Common/Types/ObjectID";
|
|
19
19
|
import Typeof from "Common/Types/Typeof";
|
|
20
20
|
import { FindOperator } from "typeorm/find-options/FindOperator";
|
|
21
|
+
import { CompareType } from "../../../Types/Database/CompareBase";
|
|
21
22
|
|
|
22
23
|
export default class QueryUtil {
|
|
23
24
|
public static serializeQuery<TBaseModel extends BaseModel>(
|
|
@@ -95,7 +96,7 @@ export default class QueryUtil {
|
|
|
95
96
|
tableColumnMetadata
|
|
96
97
|
) {
|
|
97
98
|
query[key] = QueryHelper.search(
|
|
98
|
-
(query[key] as Search).toString() as any,
|
|
99
|
+
(query[key] as Search<string>).toString() as any,
|
|
99
100
|
) as any;
|
|
100
101
|
} else if (
|
|
101
102
|
query[key] &&
|
|
@@ -103,7 +104,7 @@ export default class QueryUtil {
|
|
|
103
104
|
tableColumnMetadata
|
|
104
105
|
) {
|
|
105
106
|
query[key] = QueryHelper.lessThan(
|
|
106
|
-
(query[key] as LessThan).toString() as any,
|
|
107
|
+
(query[key] as LessThan<CompareType>).toString() as any,
|
|
107
108
|
) as any;
|
|
108
109
|
} else if (
|
|
109
110
|
query[key] &&
|
|
@@ -117,8 +118,8 @@ export default class QueryUtil {
|
|
|
117
118
|
tableColumnMetadata
|
|
118
119
|
) {
|
|
119
120
|
query[key] = QueryHelper.inBetween(
|
|
120
|
-
(query[key] as InBetween).startValue as any,
|
|
121
|
-
(query[key] as InBetween).endValue as any,
|
|
121
|
+
(query[key] as InBetween<CompareType>).startValue as any,
|
|
122
|
+
(query[key] as InBetween<CompareType>).endValue as any,
|
|
122
123
|
) as any;
|
|
123
124
|
} else if (
|
|
124
125
|
query[key] &&
|
|
@@ -126,7 +127,7 @@ export default class QueryUtil {
|
|
|
126
127
|
tableColumnMetadata
|
|
127
128
|
) {
|
|
128
129
|
query[key] = QueryHelper.greaterThan(
|
|
129
|
-
(query[key] as GreaterThan).toString() as any,
|
|
130
|
+
(query[key] as GreaterThan<CompareType>).toString() as any,
|
|
130
131
|
) as any;
|
|
131
132
|
} else if (
|
|
132
133
|
query[key] &&
|
|
@@ -147,7 +148,7 @@ export default class QueryUtil {
|
|
|
147
148
|
tableColumnMetadata
|
|
148
149
|
) {
|
|
149
150
|
query[key] = QueryHelper.greaterThanEqualTo(
|
|
150
|
-
(query[key] as GreaterThanOrEqual).toString() as any,
|
|
151
|
+
(query[key] as GreaterThanOrEqual<CompareType>).toString() as any,
|
|
151
152
|
) as any;
|
|
152
153
|
} else if (
|
|
153
154
|
query[key] &&
|
|
@@ -155,7 +156,7 @@ export default class QueryUtil {
|
|
|
155
156
|
tableColumnMetadata
|
|
156
157
|
) {
|
|
157
158
|
query[key] = QueryHelper.lessThanEqualTo(
|
|
158
|
-
(query[key] as LessThanOrEqual).toString() as any,
|
|
159
|
+
(query[key] as LessThanOrEqual<CompareType>).toString() as any,
|
|
159
160
|
) as any;
|
|
160
161
|
} else if (
|
|
161
162
|
query[key] &&
|
|
@@ -538,7 +538,7 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
|
|
538
538
|
const selectStatement: Statement = new Statement();
|
|
539
539
|
|
|
540
540
|
const aggregationMethod: string =
|
|
541
|
-
aggregateBy.
|
|
541
|
+
aggregateBy.aggregationType.toLocaleLowerCase();
|
|
542
542
|
const aggregationInterval: string = AggregateUtil.getAggregationInterval({
|
|
543
543
|
startDate: aggregateBy.startTimestamp!,
|
|
544
544
|
endDate: aggregateBy.endTimestamp!,
|