@trafficgroup/knex-rel 0.1.20 → 0.1.21
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 +10 -0
- package/dist/constants/study.constants.js +23 -0
- package/dist/constants/study.constants.js.map +1 -0
- package/dist/dao/study/study.dao.d.ts +2 -2
- package/dist/dao/study/study.dao.js +8 -4
- package/dist/dao/study/study.dao.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/study/study.interfaces.d.ts +6 -0
- package/package.json +1 -1
- package/src/constants/study.constants.ts +22 -0
- package/src/dao/study/study.dao.ts +12 -5
- package/src/index.ts +7 -1
- package/src/interfaces/study/study.interfaces.ts +7 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Study sorting constants
|
|
3
|
+
* Shared between DAO and API controller to ensure validation consistency
|
|
4
|
+
*/
|
|
5
|
+
export declare const VALID_STUDY_SORT_FIELDS: readonly ["created_at", "name", "type", "status"];
|
|
6
|
+
export type StudySortField = (typeof VALID_STUDY_SORT_FIELDS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* Maps API sort field names to database column names with table aliases
|
|
9
|
+
*/
|
|
10
|
+
export declare const STUDY_SORT_COLUMN_MAP: Record<StudySortField, string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Study sorting constants
|
|
4
|
+
* Shared between DAO and API controller to ensure validation consistency
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.STUDY_SORT_COLUMN_MAP = exports.VALID_STUDY_SORT_FIELDS = void 0;
|
|
8
|
+
exports.VALID_STUDY_SORT_FIELDS = [
|
|
9
|
+
"created_at",
|
|
10
|
+
"name",
|
|
11
|
+
"type",
|
|
12
|
+
"status",
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Maps API sort field names to database column names with table aliases
|
|
16
|
+
*/
|
|
17
|
+
exports.STUDY_SORT_COLUMN_MAP = {
|
|
18
|
+
created_at: "s.created_at",
|
|
19
|
+
name: "s.name",
|
|
20
|
+
type: "s.type",
|
|
21
|
+
status: "s.status",
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=study.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"study.constants.js","sourceRoot":"","sources":["../../src/constants/study.constants.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEU,QAAA,uBAAuB,GAAG;IACrC,YAAY;IACZ,MAAM;IACN,MAAM;IACN,QAAQ;CACA,CAAC;AAGX;;GAEG;AACU,QAAA,qBAAqB,GAAmC;IACnE,UAAU,EAAE,cAAc;IAC1B,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,UAAU;CACnB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
2
|
-
import { IStudy } from "../../interfaces/study/study.interfaces";
|
|
2
|
+
import { IStudy, IStudyFilters } from "../../interfaces/study/study.interfaces";
|
|
3
3
|
export declare class StudyDAO implements IBaseDAO<IStudy> {
|
|
4
4
|
private _knex;
|
|
5
5
|
create(item: IStudy): Promise<IStudy>;
|
|
@@ -7,6 +7,6 @@ export declare class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
7
7
|
getByUuid(uuid: string): Promise<IStudy | null>;
|
|
8
8
|
update(id: number, item: Partial<IStudy>): Promise<IStudy | null>;
|
|
9
9
|
delete(id: number): Promise<boolean>;
|
|
10
|
-
getAll(page: number, limit: number,
|
|
10
|
+
getAll(page: number, limit: number, filters?: IStudyFilters): Promise<IDataPaginator<IStudy>>;
|
|
11
11
|
getStudiesByLocation(locationId: number): Promise<IStudy[]>;
|
|
12
12
|
}
|
|
@@ -13,6 +13,7 @@ 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");
|
|
16
17
|
const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
|
|
17
18
|
class StudyDAO {
|
|
18
19
|
constructor() {
|
|
@@ -63,18 +64,21 @@ class StudyDAO {
|
|
|
63
64
|
return result > 0;
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
getAll(page, limit,
|
|
67
|
+
getAll(page, limit, filters) {
|
|
67
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
69
|
const offset = (page - 1) * limit;
|
|
69
70
|
const query = this._knex("study as s")
|
|
70
71
|
.innerJoin("users as u", "s.createdBy", "u.id")
|
|
71
72
|
.leftJoin("locations as l", "s.locationId", "l.id")
|
|
72
73
|
.select("s.*", this._knex.raw("to_jsonb(u.*) as user"), this._knex.raw("to_jsonb(l.*) as location"));
|
|
73
|
-
if (createdBy !== undefined && createdBy !== null) {
|
|
74
|
-
query.where("s.createdBy", createdBy);
|
|
75
|
-
}
|
|
76
74
|
const [countResult] = yield query.clone().clearSelect().count("* as count");
|
|
77
75
|
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);
|
|
78
82
|
const studies = yield query.clone().limit(limit).offset(offset);
|
|
79
83
|
return {
|
|
80
84
|
success: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"study.dao.js","sourceRoot":"","sources":["../../../src/dao/study/study.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,qEAAwE;AACxE,0EAA+C;AAE/C,MAAa,QAAQ;IAArB;QACU,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IAyGpE,CAAC;IAvGO,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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,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;AA1GD,4BA0GC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ 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";
|
|
18
20
|
export { VALID_FOLDER_SORT_FIELDS, VALID_FOLDER_STATUSES, FOLDER_SORT_COLUMN_MAP, } from "./constants/folder.constants";
|
|
19
21
|
export type { FolderSortField, FolderStatus, } from "./constants/folder.constants";
|
|
20
22
|
export type { IFolderFilters } from "./dao/folder/folder.dao";
|
|
@@ -27,7 +29,7 @@ export { IFolder } from "./interfaces/folder/folder.interfaces";
|
|
|
27
29
|
export { ILocation } from "./interfaces/location/location.interfaces";
|
|
28
30
|
export { IMessage, IMessageCreate, IMessageUpdate, } from "./interfaces/message/message.interfaces";
|
|
29
31
|
export { IReportConfiguration, IReportConfigurationData, IReportConfigurationInput, ICustomClass, IValidationResult, } from "./interfaces/report-configuration/report-configuration.interfaces";
|
|
30
|
-
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
32
|
+
export { IStudy, IStudyFilters } from "./interfaces/study/study.interfaces";
|
|
31
33
|
export { ISystemConfiguration } from "./interfaces/systemConfiguration/ISystemConfiguration";
|
|
32
34
|
export { IUser } from "./interfaces/user/user.interfaces";
|
|
33
35
|
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.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;
|
|
6
|
+
exports.KnexManager = exports.FOLDER_SORT_COLUMN_MAP = exports.VALID_FOLDER_STATUSES = exports.VALID_FOLDER_SORT_FIELDS = exports.STUDY_SORT_COLUMN_MAP = exports.VALID_STUDY_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,6 +40,9 @@ 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; } });
|
|
43
46
|
var folder_constants_1 = require("./constants/folder.constants");
|
|
44
47
|
Object.defineProperty(exports, "VALID_FOLDER_SORT_FIELDS", { enumerable: true, get: function () { return folder_constants_1.VALID_FOLDER_SORT_FIELDS; } });
|
|
45
48
|
Object.defineProperty(exports, "VALID_FOLDER_STATUSES", { enumerable: true, get: function () { return folder_constants_1.VALID_FOLDER_STATUSES; } });
|
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,2GAA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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,+DAGqC;AAFnC,0HAAA,uBAAuB,OAAA;AACvB,wHAAA,qBAAqB,OAAA;AAIvB,iEAIsC;AAHpC,4HAAA,wBAAwB,OAAA;AACxB,yHAAA,qBAAqB,OAAA;AACrB,0HAAA,sBAAsB,OAAA;AAsDxB,sEAA2C;AAClC,sBADF,wBAAW,CACE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
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";
|
|
3
5
|
export interface IStudy {
|
|
4
6
|
id: number;
|
|
5
7
|
uuid: string;
|
|
@@ -15,3 +17,7 @@ export interface IStudy {
|
|
|
15
17
|
user?: IUser;
|
|
16
18
|
location?: ILocation;
|
|
17
19
|
}
|
|
20
|
+
export interface IStudyFilters {
|
|
21
|
+
sortBy?: StudySortField;
|
|
22
|
+
sortOrder?: SortOrder;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Study sorting constants
|
|
3
|
+
* Shared between DAO and API controller to ensure validation consistency
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const VALID_STUDY_SORT_FIELDS = [
|
|
7
|
+
"created_at",
|
|
8
|
+
"name",
|
|
9
|
+
"type",
|
|
10
|
+
"status",
|
|
11
|
+
] as const;
|
|
12
|
+
export type StudySortField = (typeof VALID_STUDY_SORT_FIELDS)[number];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Maps API sort field names to database column names with table aliases
|
|
16
|
+
*/
|
|
17
|
+
export const STUDY_SORT_COLUMN_MAP: Record<StudySortField, string> = {
|
|
18
|
+
created_at: "s.created_at",
|
|
19
|
+
name: "s.name",
|
|
20
|
+
type: "s.type",
|
|
21
|
+
status: "s.status",
|
|
22
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Knex } from "knex";
|
|
2
2
|
import { IBaseDAO, IDataPaginator } from "../../d.types";
|
|
3
|
-
import { IStudy } from "../../interfaces/study/study.interfaces";
|
|
3
|
+
import { IStudy, IStudyFilters } from "../../interfaces/study/study.interfaces";
|
|
4
|
+
import { STUDY_SORT_COLUMN_MAP } from "../../constants/study.constants";
|
|
4
5
|
import KnexManager from "../../KnexConnection";
|
|
5
6
|
|
|
6
7
|
export class StudyDAO implements IBaseDAO<IStudy> {
|
|
@@ -57,7 +58,7 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
57
58
|
async getAll(
|
|
58
59
|
page: number,
|
|
59
60
|
limit: number,
|
|
60
|
-
|
|
61
|
+
filters?: IStudyFilters,
|
|
61
62
|
): Promise<IDataPaginator<IStudy>> {
|
|
62
63
|
const offset = (page - 1) * limit;
|
|
63
64
|
|
|
@@ -69,12 +70,18 @@ export class StudyDAO implements IBaseDAO<IStudy> {
|
|
|
69
70
|
this._knex.raw("to_jsonb(u.*) as user"),
|
|
70
71
|
this._knex.raw("to_jsonb(l.*) as location"),
|
|
71
72
|
);
|
|
72
|
-
if (createdBy !== undefined && createdBy !== null) {
|
|
73
|
-
query.where("s.createdBy", createdBy);
|
|
74
|
-
}
|
|
75
73
|
|
|
76
74
|
const [countResult] = await query.clone().clearSelect().count("* as count");
|
|
77
75
|
const totalCount = +countResult.count;
|
|
76
|
+
|
|
77
|
+
// Apply sorting
|
|
78
|
+
const sortColumn =
|
|
79
|
+
filters?.sortBy && STUDY_SORT_COLUMN_MAP[filters.sortBy]
|
|
80
|
+
? STUDY_SORT_COLUMN_MAP[filters.sortBy]
|
|
81
|
+
: "s.created_at";
|
|
82
|
+
const sortOrder = filters?.sortOrder || "DESC";
|
|
83
|
+
query.orderBy(sortColumn, sortOrder);
|
|
84
|
+
|
|
78
85
|
const studies = await query.clone().limit(limit).offset(offset);
|
|
79
86
|
|
|
80
87
|
return {
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,12 @@ 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
|
+
|
|
26
32
|
export {
|
|
27
33
|
VALID_FOLDER_SORT_FIELDS,
|
|
28
34
|
VALID_FOLDER_STATUSES,
|
|
@@ -60,7 +66,7 @@ export {
|
|
|
60
66
|
ICustomClass,
|
|
61
67
|
IValidationResult,
|
|
62
68
|
} from "./interfaces/report-configuration/report-configuration.interfaces";
|
|
63
|
-
export { IStudy } from "./interfaces/study/study.interfaces";
|
|
69
|
+
export { IStudy, IStudyFilters } from "./interfaces/study/study.interfaces";
|
|
64
70
|
export { ISystemConfiguration } from "./interfaces/systemConfiguration/ISystemConfiguration";
|
|
65
71
|
export { IUser } from "./interfaces/user/user.interfaces";
|
|
66
72
|
export { IUserPushNotificationToken } from "./interfaces/user-push-notification-token/user-push-notification-token.interfaces";
|
|
@@ -1,5 +1,7 @@
|
|
|
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";
|
|
3
5
|
|
|
4
6
|
export interface IStudy {
|
|
5
7
|
id: number;
|
|
@@ -16,3 +18,8 @@ export interface IStudy {
|
|
|
16
18
|
user?: IUser;
|
|
17
19
|
location?: ILocation;
|
|
18
20
|
}
|
|
21
|
+
|
|
22
|
+
export interface IStudyFilters {
|
|
23
|
+
sortBy?: StudySortField;
|
|
24
|
+
sortOrder?: SortOrder;
|
|
25
|
+
}
|