@trafficgroup/knex-rel 0.1.21 → 0.1.22
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/constants/study.constants.d.ts +1 -1
- package/dist/constants/study.constants.js +1 -1
- package/dist/dao/study/study.dao.d.ts +8 -1
- package/dist/dao/study/study.dao.js +22 -8
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces/study/study.interfaces.d.ts +0 -6
- package/package.json +1 -1
- package/src/constants/study.constants.ts +1 -1
- package/src/dao/study/study.dao.ts +32 -11
- package/src/index.ts +9 -8
- package/src/interfaces/study/study.interfaces.ts +0 -7
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
-
import { IStudy
|
|
2
|
+
import { IStudy } from "../../interfaces/study/study.interfaces";
|
|
3
|
+
import { StudySortField } from "../../constants/study.constants";
|
|
4
|
+
import { SortOrder } from "../../constants/video.constants";
|
|
5
|
+
export interface IStudyFilters {
|
|
6
|
+
createdBy?: number | null;
|
|
7
|
+
sortBy?: StudySortField;
|
|
8
|
+
sortOrder?: SortOrder;
|
|
9
|
+
}
|
|
3
10
|
export declare class StudyDAO implements IBaseDAO<IStudy> {
|
|
4
11
|
private _knex;
|
|
5
12
|
create(item: IStudy): Promise<IStudy>;
|
|
@@ -13,8 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.StudyDAO = void 0;
|
|
16
|
-
const study_constants_1 = require("../../constants/study.constants");
|
|
17
16
|
const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
17
|
+
const study_constants_1 = require("../../constants/study.constants");
|
|
18
18
|
class StudyDAO {
|
|
19
19
|
constructor() {
|
|
20
20
|
this._knex = KnexConnection_1.default.getConnection();
|
|
@@ -71,14 +71,28 @@ class StudyDAO {
|
|
|
71
71
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
72
72
|
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
73
73
|
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"));
|
|
74
|
-
|
|
74
|
+
if (filters) {
|
|
75
|
+
if (filters.createdBy !== undefined && filters.createdBy !== null) {
|
|
76
|
+
query.where("s.createdBy", filters.createdBy);
|
|
77
|
+
}
|
|
78
|
+
if (filters.sortBy) {
|
|
79
|
+
const columnName = study_constants_1.STUDY_SORT_COLUMN_MAP[filters.sortBy];
|
|
80
|
+
const order = filters.sortOrder || "DESC";
|
|
81
|
+
query.orderBy(columnName, order);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
query.orderBy("s.created_at", "DESC");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
query.orderBy("s.created_at", "DESC");
|
|
89
|
+
}
|
|
90
|
+
const [countResult] = yield query
|
|
91
|
+
.clone()
|
|
92
|
+
.clearSelect()
|
|
93
|
+
.clearOrder()
|
|
94
|
+
.count("* as count");
|
|
75
95
|
const totalCount = +countResult.count;
|
|
76
|
-
// Apply sorting
|
|
77
|
-
const sortColumn = (filters === null || filters === void 0 ? void 0 : filters.sortBy) && study_constants_1.STUDY_SORT_COLUMN_MAP[filters.sortBy]
|
|
78
|
-
? study_constants_1.STUDY_SORT_COLUMN_MAP[filters.sortBy]
|
|
79
|
-
: "s.created_at";
|
|
80
|
-
const sortOrder = (filters === null || filters === void 0 ? void 0 : filters.sortOrder) || "DESC";
|
|
81
|
-
query.orderBy(sortColumn, sortOrder);
|
|
82
96
|
const studies = yield query.clone().limit(limit).offset(offset);
|
|
83
97
|
return {
|
|
84
98
|
success: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,
|
|
1
|
+
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAC/C,qEAGyC;AASzC,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAoHpE,CAAC;IAlHO,MAAM,CAAC,IAAY;;YACvB,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;iBAC7C,MAAM,CAAC,IAAI,CAAC;iBACZ,SAAS,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,YAAY,CAAC;QACtB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACtB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;iBACzC,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC;iBAC9C,QAAQ,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC;iBAClD,MAAM,CACL,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAC5C;iBACA,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;iBACjB,KAAK,EAAE,CAAC;YACX,OAAO,KAAK,IAAI,IAAI,CAAC;QACvB,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY;;YAC1B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;iBACzC,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC;iBAC9C,QAAQ,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC;iBAClD,MAAM,CACL,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,G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AY,EAAE,aAAa,EAAE,MAAM,CAAC;iBAC9C,QAAQ,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC;iBAClD,MAAM,CACL,KAAK,EACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAC5C;iBACA,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC;iBACjC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC;iBAC/B,KAAK,CAAC,EAAE,CAAC,CAAC;YAEb,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CACF;AArHD,4BAqHC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,12 @@ export { VideoDAO } from "./dao/video/video.dao";
|
|
|
15
15
|
export { VideoMinuteResultDAO } from "./dao/VideoMinuteResultDAO";
|
|
16
16
|
export { VALID_VIDEO_SORT_FIELDS, VALID_SORT_ORDERS, VIDEO_SORT_COLUMN_MAP, } from "./constants/video.constants";
|
|
17
17
|
export type { VideoSortField, SortOrder } from "./constants/video.constants";
|
|
18
|
-
export { VALID_STUDY_SORT_FIELDS, STUDY_SORT_COLUMN_MAP, } from "./constants/study.constants";
|
|
19
|
-
export type { StudySortField } from "./constants/study.constants";
|
|
20
18
|
export { VALID_FOLDER_SORT_FIELDS, VALID_FOLDER_STATUSES, FOLDER_SORT_COLUMN_MAP, } from "./constants/folder.constants";
|
|
21
19
|
export type { FolderSortField, FolderStatus, } from "./constants/folder.constants";
|
|
20
|
+
export { VALID_STUDY_SORT_FIELDS, STUDY_SORT_COLUMN_MAP, } from "./constants/study.constants";
|
|
21
|
+
export type { StudySortField } from "./constants/study.constants";
|
|
22
22
|
export type { IFolderFilters } from "./dao/folder/folder.dao";
|
|
23
|
+
export type { IStudyFilters } from "./dao/study/study.dao";
|
|
23
24
|
export { IDataPaginator } from "./d.types";
|
|
24
25
|
export { IAuth } from "./interfaces/auth/auth.interfaces";
|
|
25
26
|
export { IBatch } from "./interfaces/batch/batch.interfaces";
|
|
@@ -29,7 +30,7 @@ export { IFolder } from "./interfaces/folder/folder.interfaces";
|
|
|
29
30
|
export { ILocation } from "./interfaces/location/location.interfaces";
|
|
30
31
|
export { IMessage, IMessageCreate, IMessageUpdate, } from "./interfaces/message/message.interfaces";
|
|
31
32
|
export { IReportConfiguration, IReportConfigurationData, IReportConfigurationInput, ICustomClass, IValidationResult, } from "./interfaces/report-configuration/report-configuration.interfaces";
|
|
32
|
-
export { IStudy
|
|
33
|
+
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
33
34
|
export { ISystemConfiguration } from "./interfaces/systemConfiguration/ISystemConfiguration";
|
|
34
35
|
export { IUser } from "./interfaces/user/user.interfaces";
|
|
35
36
|
export { IUserPushNotificationToken } from "./interfaces/user-push-notification-token/user-push-notification-token.interfaces";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.KnexManager = exports.
|
|
6
|
+
exports.KnexManager = exports.STUDY_SORT_COLUMN_MAP = exports.VALID_STUDY_SORT_FIELDS = exports.FOLDER_SORT_COLUMN_MAP = exports.VALID_FOLDER_STATUSES = exports.VALID_FOLDER_SORT_FIELDS = exports.VIDEO_SORT_COLUMN_MAP = exports.VALID_SORT_ORDERS = exports.VALID_VIDEO_SORT_FIELDS = exports.VideoMinuteResultDAO = exports.VideoDAO = exports.ReconciliationLogDAO = exports.UserPushNotificationTokenDAO = exports.UserDAO = exports.SystemConfigurationDAO = exports.StudyDAO = exports.ReportConfigurationDAO = exports.MessageDAO = exports.LocationDAO = exports.FolderDAO = exports.ChatDAO = exports.CameraDAO = exports.BatchDAO = exports.AuthDAO = void 0;
|
|
7
7
|
// DAOs
|
|
8
8
|
var auth_dao_1 = require("./dao/auth/auth.dao");
|
|
9
9
|
Object.defineProperty(exports, "AuthDAO", { enumerable: true, get: function () { return auth_dao_1.AuthDAO; } });
|
|
@@ -40,13 +40,13 @@ var video_constants_1 = require("./constants/video.constants");
|
|
|
40
40
|
Object.defineProperty(exports, "VALID_VIDEO_SORT_FIELDS", { enumerable: true, get: function () { return video_constants_1.VALID_VIDEO_SORT_FIELDS; } });
|
|
41
41
|
Object.defineProperty(exports, "VALID_SORT_ORDERS", { enumerable: true, get: function () { return video_constants_1.VALID_SORT_ORDERS; } });
|
|
42
42
|
Object.defineProperty(exports, "VIDEO_SORT_COLUMN_MAP", { enumerable: true, get: function () { return video_constants_1.VIDEO_SORT_COLUMN_MAP; } });
|
|
43
|
-
var study_constants_1 = require("./constants/study.constants");
|
|
44
|
-
Object.defineProperty(exports, "VALID_STUDY_SORT_FIELDS", { enumerable: true, get: function () { return study_constants_1.VALID_STUDY_SORT_FIELDS; } });
|
|
45
|
-
Object.defineProperty(exports, "STUDY_SORT_COLUMN_MAP", { enumerable: true, get: function () { return study_constants_1.STUDY_SORT_COLUMN_MAP; } });
|
|
46
43
|
var folder_constants_1 = require("./constants/folder.constants");
|
|
47
44
|
Object.defineProperty(exports, "VALID_FOLDER_SORT_FIELDS", { enumerable: true, get: function () { return folder_constants_1.VALID_FOLDER_SORT_FIELDS; } });
|
|
48
45
|
Object.defineProperty(exports, "VALID_FOLDER_STATUSES", { enumerable: true, get: function () { return folder_constants_1.VALID_FOLDER_STATUSES; } });
|
|
49
46
|
Object.defineProperty(exports, "FOLDER_SORT_COLUMN_MAP", { enumerable: true, get: function () { return folder_constants_1.FOLDER_SORT_COLUMN_MAP; } });
|
|
47
|
+
var study_constants_1 = require("./constants/study.constants");
|
|
48
|
+
Object.defineProperty(exports, "VALID_STUDY_SORT_FIELDS", { enumerable: true, get: function () { return study_constants_1.VALID_STUDY_SORT_FIELDS; } });
|
|
49
|
+
Object.defineProperty(exports, "STUDY_SORT_COLUMN_MAP", { enumerable: true, get: function () { return study_constants_1.STUDY_SORT_COLUMN_MAP; } });
|
|
50
50
|
const KnexConnection_1 = __importDefault(require("./KnexConnection"));
|
|
51
51
|
exports.KnexManager = KnexConnection_1.default;
|
|
52
52
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO;AACP,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,gDAAsE;AAA7D,mGAAA,OAAO,OAAA;AAChB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,4DAA0D;AAAjD,2GAAA,WAAW,OAAA;AACpB,yDAAuD;AAA9C,yGAAA,UAAU,OAAA;AACnB,gGAA6F;AAApF,kIAAA,sBAAsB,OAAA;AAC/B,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,2FAA0F;AAAjF,gIAAA,sBAAsB,OAAA;AAC/B,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,wHAAmH;AAA1G,gJAAA,4BAA4B,OAAA;AACrC,0FAAuF;AAA9E,8HAAA,oBAAoB,OAAA;AAC7B,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,mEAAkE;AAAzD,4HAAA,oBAAoB,OAAA;AAE7B,YAAY;AACZ,+DAIqC;AAHnC,0HAAA,uBAAuB,OAAA;AACvB,oHAAA,iBAAiB,OAAA;AACjB,wHAAA,qBAAqB,OAAA;AAIvB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO;AACP,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,gDAAsE;AAA7D,mGAAA,OAAO,OAAA;AAChB,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAClB,4DAA0D;AAAjD,2GAAA,WAAW,OAAA;AACpB,yDAAuD;AAA9C,yGAAA,UAAU,OAAA;AACnB,gGAA6F;AAApF,kIAAA,sBAAsB,OAAA;AAC/B,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,2FAA0F;AAAjF,gIAAA,sBAAsB,OAAA;AAC/B,gDAA8C;AAArC,mGAAA,OAAO,OAAA;AAChB,wHAAmH;AAA1G,gJAAA,4BAA4B,OAAA;AACrC,0FAAuF;AAA9E,8HAAA,oBAAoB,OAAA;AAC7B,mDAAiD;AAAxC,qGAAA,QAAQ,OAAA;AACjB,mEAAkE;AAAzD,4HAAA,oBAAoB,OAAA;AAE7B,YAAY;AACZ,+DAIqC;AAHnC,0HAAA,uBAAuB,OAAA;AACvB,oHAAA,iBAAiB,OAAA;AACjB,wHAAA,qBAAqB,OAAA;AAIvB,iEAIsC;AAHpC,4HAAA,wBAAwB,OAAA;AACxB,yHAAA,qBAAqB,OAAA;AACrB,0HAAA,sBAAsB,OAAA;AAOxB,+DAGqC;AAFnC,0HAAA,uBAAuB,OAAA;AACvB,wHAAA,qBAAqB,OAAA;AAoDvB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { IUser } from "../user/user.interfaces";
|
|
2
2
|
import type { ILocation } from "../location/location.interfaces";
|
|
3
|
-
import type { SortOrder } from "../../constants/video.constants";
|
|
4
|
-
import type { StudySortField } from "../../constants/study.constants";
|
|
5
3
|
export interface IStudy {
|
|
6
4
|
id: number;
|
|
7
5
|
uuid: string;
|
|
@@ -17,7 +15,3 @@ export interface IStudy {
|
|
|
17
15
|
user?: IUser;
|
|
18
16
|
location?: ILocation;
|
|
19
17
|
}
|
|
20
|
-
export interface IStudyFilters {
|
|
21
|
-
sortBy?: StudySortField;
|
|
22
|
-
sortOrder?: SortOrder;
|
|
23
|
-
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Knex } from "knex";
|
|
2
2
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
-
import { IStudy
|
|
4
|
-
import { STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
|
|
3
|
+
import { IStudy } from "../../interfaces/study/study.interfaces";
|
|
5
4
|
import KnexManager from "../../KnexConnection";
|
|
5
|
+
import {
|
|
6
|
+
StudySortField,
|
|
7
|
+
STUDY_SORT_COLUMN_MAP,
|
|
8
|
+
} from "../../constants/study.constants";
|
|
9
|
+
import { SortOrder } from "../../constants/video.constants";
|
|
10
|
+
|
|
11
|
+
export interface IStudyFilters {
|
|
12
|
+
createdBy?: number | null;
|
|
13
|
+
sortBy?: StudySortField;
|
|
14
|
+
sortOrder?: SortOrder;
|
|
15
|
+
}
|
|
6
16
|
|
|
7
17
|
export class StudyDAO implements IBaseDAO<IStudy> {
|
|
8
18
|
private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
|
|
@@ -71,17 +81,28 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
71
81
|
this._knex.raw("to_jsonb(l.*) as location"),
|
|
72
82
|
);
|
|
73
83
|
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
if (filters) {
|
|
85
|
+
if (filters.createdBy !== undefined && filters.createdBy !== null) {
|
|
86
|
+
query.where("s.createdBy", filters.createdBy);
|
|
87
|
+
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
if (filters.sortBy) {
|
|
90
|
+
const columnName = STUDY_SORT_COLUMN_MAP[filters.sortBy];
|
|
91
|
+
const order = filters.sortOrder || "DESC";
|
|
92
|
+
query.orderBy(columnName, order);
|
|
93
|
+
} else {
|
|
94
|
+
query.orderBy("s.created_at", "DESC");
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
query.orderBy("s.created_at", "DESC");
|
|
98
|
+
}
|
|
84
99
|
|
|
100
|
+
const [countResult] = await query
|
|
101
|
+
.clone()
|
|
102
|
+
.clearSelect()
|
|
103
|
+
.clearOrder()
|
|
104
|
+
.count("* as count");
|
|
105
|
+
const totalCount = +countResult.count;
|
|
85
106
|
const studies = await query.clone().limit(limit).offset(offset);
|
|
86
107
|
|
|
87
108
|
return {
|
package/src/index.ts
CHANGED
|
@@ -23,12 +23,6 @@ export {
|
|
|
23
23
|
} from "./constants/video.constants";
|
|
24
24
|
export type { VideoSortField, SortOrder } from "./constants/video.constants";
|
|
25
25
|
|
|
26
|
-
export {
|
|
27
|
-
VALID_STUDY_SORT_FIELDS,
|
|
28
|
-
STUDY_SORT_COLUMN_MAP,
|
|
29
|
-
} from "./constants/study.constants";
|
|
30
|
-
export type { StudySortField } from "./constants/study.constants";
|
|
31
|
-
|
|
32
26
|
export {
|
|
33
27
|
VALID_FOLDER_SORT_FIELDS,
|
|
34
28
|
VALID_FOLDER_STATUSES,
|
|
@@ -39,8 +33,15 @@ export type {
|
|
|
39
33
|
FolderStatus,
|
|
40
34
|
} from "./constants/folder.constants";
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
export {
|
|
37
|
+
VALID_STUDY_SORT_FIELDS,
|
|
38
|
+
STUDY_SORT_COLUMN_MAP,
|
|
39
|
+
} from "./constants/study.constants";
|
|
40
|
+
export type { StudySortField } from "./constants/study.constants";
|
|
41
|
+
|
|
42
|
+
// Filters interfaces
|
|
43
43
|
export type { IFolderFilters } from "./dao/folder/folder.dao";
|
|
44
|
+
export type { IStudyFilters } from "./dao/study/study.dao";
|
|
44
45
|
|
|
45
46
|
// Interfaces
|
|
46
47
|
export { IDataPaginator } from "./d.types";
|
|
@@ -66,7 +67,7 @@ export {
|
|
|
66
67
|
ICustomClass,
|
|
67
68
|
IValidationResult,
|
|
68
69
|
} from "./interfaces/report-configuration/report-configuration.interfaces";
|
|
69
|
-
export { IStudy
|
|
70
|
+
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
70
71
|
export { ISystemConfiguration } from "./interfaces/systemConfiguration/ISystemConfiguration";
|
|
71
72
|
export { IUser } from "./interfaces/user/user.interfaces";
|
|
72
73
|
export { IUserPushNotificationToken } from "./interfaces/user-push-notification-token/user-push-notification-token.interfaces";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { IUser } from "../user/user.interfaces";
|
|
2
2
|
import type { ILocation } from "../location/location.interfaces";
|
|
3
|
-
import type { SortOrder } from "../../constants/video.constants";
|
|
4
|
-
import type { StudySortField } from "../../constants/study.constants";
|
|
5
3
|
|
|
6
4
|
export interface IStudy {
|
|
7
5
|
id: number;
|
|
@@ -18,8 +16,3 @@ export interface IStudy {
|
|
|
18
16
|
user?: IUser;
|
|
19
17
|
location?: ILocation;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
export interface IStudyFilters {
|
|
23
|
-
sortBy?: StudySortField;
|
|
24
|
-
sortOrder?: SortOrder;
|
|
25
|
-
}
|