@intellias/menu 1.0.0

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.
Files changed (174) hide show
  1. package/Menu.ts +625 -0
  2. package/README.md +121 -0
  3. package/assets/icons/arrow-down.svg +13 -0
  4. package/assets/icons/arrow-left.svg +3 -0
  5. package/assets/icons/arrow-submenu.svg +8 -0
  6. package/assets/icons/close.svg +3 -0
  7. package/assets/icons/delete.svg +13 -0
  8. package/assets/icons/faq-new.svg +4 -0
  9. package/assets/icons/kudos.svg +14 -0
  10. package/assets/icons/loading-spinner.svg +40 -0
  11. package/assets/icons/notification.svg +11 -0
  12. package/assets/icons/notifications/assessment.svg +10 -0
  13. package/assets/icons/notifications/buddy_program.svg +8 -0
  14. package/assets/icons/notifications/compensation_packages.svg +10 -0
  15. package/assets/icons/notifications/dsat.svg +8 -0
  16. package/assets/icons/notifications/feedback.svg +7 -0
  17. package/assets/icons/notifications/kudos.svg +4 -0
  18. package/assets/icons/notifications/overtime_requests.svg +15 -0
  19. package/assets/icons/notifications/pdu_program.svg +4 -0
  20. package/assets/icons/notifications/profile_update.svg +6 -0
  21. package/assets/icons/notifications/recommendation_program.svg +7 -0
  22. package/assets/icons/notifications/reminders.svg +4 -0
  23. package/assets/icons/notifications/sick_leaves.svg +5 -0
  24. package/assets/icons/notifications/smarts.svg +4 -0
  25. package/assets/icons/notifications/survey.svg +8 -0
  26. package/assets/icons/notifications/unpaid_leave.svg +4 -0
  27. package/assets/icons/notifications/vacations.svg +4 -0
  28. package/assets/icons/pause.svg +13 -0
  29. package/assets/icons/play.svg +13 -0
  30. package/assets/icons/smart.svg +14 -0
  31. package/assets/icons/smarts-kudos.svg +11 -0
  32. package/assets/icons/spinner-solid.svg +1 -0
  33. package/assets/icons/vacation.svg +14 -0
  34. package/assets/icons/visibility.svg +1 -0
  35. package/assets/intems-logo.svg +3 -0
  36. package/babel.config.js +6 -0
  37. package/buses/eventBus.ts +19 -0
  38. package/buses/events/GiveKudosEvent.ts +7 -0
  39. package/components/buttons/action-button/ActionButton.scss +133 -0
  40. package/components/buttons/action-button/ActionButton.ts +57 -0
  41. package/components/buttons/action-button/ActionButton.vue +50 -0
  42. package/components/buttons/secondary-button/SecondaryButton.scss +48 -0
  43. package/components/buttons/secondary-button/SecondaryButton.ts +28 -0
  44. package/components/buttons/secondary-button/SecondaryButton.vue +27 -0
  45. package/components/confirm/Confirm.scss +44 -0
  46. package/components/confirm/Confirm.ts +82 -0
  47. package/components/confirm/Confirm.vue +64 -0
  48. package/components/give-kudos-form/GiveKudosForm.scss +114 -0
  49. package/components/give-kudos-form/GiveKudosForm.ts +159 -0
  50. package/components/give-kudos-form/GiveKudosForm.vue +131 -0
  51. package/components/give-kudos-form/mixins/UserSelectMixin.ts +57 -0
  52. package/components/give-kudos-form/models/KudosShareModel.ts +6 -0
  53. package/components/give-kudos-form/models/UserListModel.ts +5 -0
  54. package/components/give-kudos-form/validators/InEnglishValidatorRegex.ts +17 -0
  55. package/components/give-kudos-form/validators/KudosBalance.ts +10 -0
  56. package/components/modal/Modal.scss +53 -0
  57. package/components/modal/Modal.ts +70 -0
  58. package/components/modal/Modal.vue +28 -0
  59. package/components/notifications-sidebar/NotificationsSidebar.scss +665 -0
  60. package/components/notifications-sidebar/NotificationsSidebar.ts +203 -0
  61. package/components/notifications-sidebar/NotificationsSidebar.vue +171 -0
  62. package/components/notifications-sidebar/models/BroadcastNotificationPayload.ts +8 -0
  63. package/components/notifications-sidebar/models/TotalCounter.ts +50 -0
  64. package/components/notifications-sidebar/notification/Notification.ts +17 -0
  65. package/components/notifications-sidebar/notification/Notification.vue +87 -0
  66. package/components/play-pause/PlayPause.scss +33 -0
  67. package/components/play-pause/PlayPause.ts +156 -0
  68. package/components/play-pause/PlayPause.vue +36 -0
  69. package/components/play-pause/PlayPauseStatus.ts +4 -0
  70. package/components/play-pause/helpers/LatestTrackedTimeDurationHelper.ts +55 -0
  71. package/components/play-pause/helpers/PauseHelper.ts +55 -0
  72. package/components/play-pause/helpers/TrackedTimeHelper.ts +80 -0
  73. package/components/preloader/Preloader.vue +34 -0
  74. package/components/request-loader/RequestLoader.scss +20 -0
  75. package/components/request-loader/RequestLoader.ts +80 -0
  76. package/components/request-loader/RequestLoader.vue +15 -0
  77. package/components/sub-menu/SubMenu.scss +33 -0
  78. package/components/sub-menu/SubMenu.ts +38 -0
  79. package/components/sub-menu/SubMenu.vue +21 -0
  80. package/components/time-ago/TimeAgo.ts +34 -0
  81. package/components/time-ago/TimeAgo.vue +9 -0
  82. package/components/user-picture/UserPicture.scss +62 -0
  83. package/components/user-picture/UserPicture.ts +105 -0
  84. package/components/user-picture/UserPicture.vue +23 -0
  85. package/components/v-select-intems/VSelectIntems.ts +112 -0
  86. package/components/v-select-intems/VSelectIntems.vue +68 -0
  87. package/components/v-select-intems/open-indicator/OpenIndicator.vue +3 -0
  88. package/dist/css/1.css +85 -0
  89. package/dist/css/2.css +34 -0
  90. package/dist/css/3.css +34 -0
  91. package/dist/css/4.css +34 -0
  92. package/dist/css/5.css +34 -0
  93. package/dist/css/main.css +1564 -0
  94. package/dist/html/app.html +19 -0
  95. package/dist/html/styles.html +1 -0
  96. package/dist/images/intems-logo.svg +3 -0
  97. package/dist/js/0.js +315 -0
  98. package/dist/js/1.js +313 -0
  99. package/dist/js/2.js +217 -0
  100. package/dist/js/3.js +181 -0
  101. package/dist/js/4.js +181 -0
  102. package/dist/js/5.js +181 -0
  103. package/dist/js/6.js +47 -0
  104. package/dist/js/main.js +7465 -0
  105. package/dist/js/vue.js +15 -0
  106. package/helpers/GeneralHelper.ts +61 -0
  107. package/helpers/PublisherSubscriber.ts +34 -0
  108. package/helpers/QueryFilter.ts +204 -0
  109. package/helpers/TimeHelper.ts +54 -0
  110. package/helpers/Validations.ts +7 -0
  111. package/helpers/model/ModelHelper.ts +155 -0
  112. package/helpers/model/decorators/AsCollection.ts +26 -0
  113. package/helpers/model/decorators/AsModel.ts +25 -0
  114. package/helpers/model/decorators/DateTime.ts +26 -0
  115. package/helpers/model/decorators/TimeDuration.ts +33 -0
  116. package/helpers/moment/Duration.ts +64 -0
  117. package/helpers/moment/Moment.ts +17 -0
  118. package/helpers/moment/index.d.ts +20 -0
  119. package/helpers/response/AxiosProxy.ts +72 -0
  120. package/helpers/response/ErrorsToToastHelper.ts +42 -0
  121. package/helpers/response/ResponseCode.ts +16 -0
  122. package/helpers/response/ResponseHelper.ts +42 -0
  123. package/helpers/response/ResponseInterface.ts +34 -0
  124. package/helpers/response/ResponseState.ts +6 -0
  125. package/jsconfig.json +19 -0
  126. package/mixins/IntemsMath.ts +29 -0
  127. package/mixins/notifications/ActionProcessing.ts +134 -0
  128. package/mixins/notifications/confirms/AssetRejectionConfirm.vue +59 -0
  129. package/mixins/notifications/confirms/SickLeaveRejectionConfirm.vue +31 -0
  130. package/mixins/notifications/confirms/UnpaidLeaveRejectionConfirm.vue +31 -0
  131. package/mixins/notifications/confirms/VacationRejectionConfirm.vue +31 -0
  132. package/models/AssetModel.ts +80 -0
  133. package/models/AssetRequestModel.ts +25 -0
  134. package/models/ConfigModel.ts +20 -0
  135. package/models/EmployeeStartEndDateModel.ts +16 -0
  136. package/models/EmploymentTypeModel.ts +95 -0
  137. package/models/LogoutModel.ts +3 -0
  138. package/models/Model.ts +12 -0
  139. package/models/ModuleOptions.ts +24 -0
  140. package/models/PublicInfoModel.ts +38 -0
  141. package/models/PublicLocationModel.ts +36 -0
  142. package/models/StatusModel.ts +8 -0
  143. package/models/TrackedTimeModel.ts +32 -0
  144. package/models/location/PublicLocationModel.ts +36 -0
  145. package/models/timezones/LocalTimezoneHistoryModel.ts +8 -0
  146. package/models/timezones/TimezoneModel.ts +9 -0
  147. package/models/user/ExtendedInfoModel.ts +37 -0
  148. package/models/user/NotificationActionModel.ts +53 -0
  149. package/models/user/NotificationModel.ts +84 -0
  150. package/models/user/PublicInfoModel.ts +38 -0
  151. package/models/user/WelcomeProgram.ts +4 -0
  152. package/package.json +117 -0
  153. package/repositories/BaseRepository.ts +42 -0
  154. package/repositories/BaseUrl.ts +107 -0
  155. package/repositories/Repository.ts +291 -0
  156. package/repositories/ResourceRepository.ts +99 -0
  157. package/repositories/TrackedTimeRepository.ts +43 -0
  158. package/repositories/UserRepository.ts +75 -0
  159. package/repositories/subscribers/CreateSubscribers.ts +28 -0
  160. package/repositories/subscribers/DefaultSubscribers.ts +82 -0
  161. package/repositories/subscribers/DeleteSubscribers.ts +28 -0
  162. package/repositories/subscribers/DownloadSubscribers.ts +28 -0
  163. package/repositories/subscribers/Subscribers.ts +13 -0
  164. package/repositories/subscribers/UpdateSubscribers.ts +32 -0
  165. package/scss/components/_global.scss +66 -0
  166. package/scss/components/_mixins.scss +31 -0
  167. package/scss/components/_tooltip.scss +45 -0
  168. package/scss/components/_utils.scss +26 -0
  169. package/scss/components/_variables.scss +103 -0
  170. package/scss/main.scss +7 -0
  171. package/shims-vue.d.ts +9 -0
  172. package/tsconfig.json +31 -0
  173. package/webpack.config.js +126 -0
  174. package/wrapper.ts +51 -0
package/package.json ADDED
@@ -0,0 +1,117 @@
1
+ {
2
+ "name": "@intellias/menu",
3
+ "version": "1.0.0",
4
+ "description": "Menu for intems project.",
5
+ "author": "Intems",
6
+ "scripts": {
7
+ "dev": "npm run development-build",
8
+ "development-build": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=./webpack.config.js",
9
+ "serve": "vue-cli-service serve",
10
+ "lint": "vue-cli-service lint",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "main": "./dist/js/main.js",
14
+ "files": [
15
+ "dist/*",
16
+ "assets/*",
17
+ "buses/*",
18
+ "components/*",
19
+ "helpers/*",
20
+ "mixins/*",
21
+ "models/*",
22
+ "repositories/*",
23
+ "requests/*",
24
+ "scss/*",
25
+ "*.json",
26
+ "*.js",
27
+ "*.ts"
28
+ ],
29
+ "dependencies": {
30
+ "@types/vuelidate": "^0.7.15",
31
+ "@typescript-eslint/eslint-plugin": "^4.7.0",
32
+ "@typescript-eslint/parser": "^4.7.0",
33
+ "@vue/cli-plugin-babel": "^5.0.8",
34
+ "axios": "^0.21.1",
35
+ "collect.js": "^4.18.1",
36
+ "core-js": "^3.8.3",
37
+ "eslint": "^7.13.0",
38
+ "eslint-config-airbnb-base": "^14.2.1",
39
+ "eslint-config-prettier": "^6.15.0",
40
+ "eslint-plugin-import": "^2.22.1",
41
+ "eslint-plugin-prettier": "^3.1.4",
42
+ "eslint-plugin-vue": "^7.1.0",
43
+ "lodash.debounce": "^4.0.8",
44
+ "mobile-device-detect": "^0.4.3",
45
+ "moment": "^2.29.4",
46
+ "moment-timezone": "^0.5.43",
47
+ "prettier": "^2.1.2",
48
+ "socket.io-client": "^4.4.1",
49
+ "v-dropdown-menu": "^2.0.2",
50
+ "v-tooltip": "^2.1.3",
51
+ "vue": "^2.6.14",
52
+ "vue-custom-scrollbar": "^1.4.3",
53
+ "vue-echo-laravel": "^1.0.0",
54
+ "vue-js-modal": "^2.0.1",
55
+ "vue-lazyload": "^1.3.3",
56
+ "vue-router": "^3.5.0",
57
+ "vue-select": "^3.2.0",
58
+ "vue-tabs-with-active-line": "^1.2.6",
59
+ "vuelidate": "^0.7.4",
60
+ "vuex": "^3.1.1"
61
+ },
62
+ "devDependencies": {
63
+ "@babel/core": "^7.12.16",
64
+ "@babel/eslint-parser": "^7.12.16",
65
+ "@vue/cli-service": "~5.0.0",
66
+ "autoprefixer": "^9.8.8",
67
+ "babel-loader": "^8.0.6",
68
+ "clean-webpack-plugin": "^3.0.0",
69
+ "cross-env": "5.1",
70
+ "css-loader": "^3.2.0",
71
+ "eslint": "^7.32.0",
72
+ "eslint-plugin-vue": "^8.0.3",
73
+ "file-loader": "^4.2.0",
74
+ "fork-ts-checker-webpack-plugin": "^6.0.0",
75
+ "html-webpack-plugin": "^3.2.0",
76
+ "mini-css-extract-plugin": "^0.8.0",
77
+ "postcss-loader": "^3.0.0",
78
+ "sass": "^1.23.0",
79
+ "sass-loader": "^7.1.0",
80
+ "sass-resources-loader": "^2.0.1",
81
+ "ts-loader": "^6.2.0",
82
+ "typescript": "^5.0.4",
83
+ "vue-loader": "^15.10.1",
84
+ "vue-style-loader": "^4.1.3",
85
+ "vue-template-compiler": "^2.7.14",
86
+ "webpack": "^4.46.0",
87
+ "webpack-cli": "^3.3.9"
88
+ },
89
+ "eslintConfig": {
90
+ "root": true,
91
+ "env": {
92
+ "node": true
93
+ },
94
+ "extends": [
95
+ "plugin:vue/essential",
96
+ "eslint:recommended"
97
+ ],
98
+ "parserOptions": {
99
+ "parser": "@babel/eslint-parser"
100
+ },
101
+ "rules": {}
102
+ },
103
+ "browserslist": [
104
+ "> 1%",
105
+ "last 2 versions",
106
+ "not dead"
107
+ ],
108
+ "keywords": [
109
+ "intems",
110
+ "menu"
111
+ ],
112
+ "license": "ISC",
113
+ "repository": {
114
+ "type": "git",
115
+ "url": "git@ssh.dev.azure.com:v3/IntelliasTS/Intems/Intems-menu"
116
+ }
117
+ }
@@ -0,0 +1,42 @@
1
+ import { AxiosResponse } from "axios";
2
+ import Repository from "./Repository";
3
+ import { RequestMethod } from "../models/user/NotificationActionModel";
4
+ import { BaseUrl } from "./BaseUrl";
5
+
6
+ export default class BaseRepository<
7
+ TModel extends new (...args: any) => any
8
+ > extends Repository {
9
+ protected model: TModel;
10
+ constructor(baseUrl: BaseUrl = BaseUrl.Default, model?: TModel) {
11
+ super(baseUrl);
12
+ this.model = model;
13
+ }
14
+
15
+ async get<Result>(
16
+ parameters?
17
+ ): Promise<keyof Result extends never ? InstanceType<TModel> : Result> {
18
+ return await this.getResource(this.model, "", parameters);
19
+ }
20
+
21
+ async post<TData>(data?, parameters?): Promise<TData> {
22
+ return this.postData("", data, parameters);
23
+ }
24
+
25
+ async request(
26
+ url: string,
27
+ method: RequestMethod,
28
+ data: Record<string, unknown>
29
+ ): Promise<AxiosResponse> {
30
+ if (method === RequestMethod.put) {
31
+ return this.putData(url, data);
32
+ }
33
+ if (method === RequestMethod.post) {
34
+ return this.postData(url, data);
35
+ }
36
+ if (method === RequestMethod.patch) {
37
+ return this.patch(url);
38
+ }
39
+
40
+ return null;
41
+ }
42
+ }
@@ -0,0 +1,107 @@
1
+ export enum BaseUrl {
2
+ Default = "",
3
+ LoggedInUser = "/api/users/me",
4
+ ProgressBar = "/api/users/me/progress-bar",
5
+ LogOut = "/logout",
6
+ SessionMessages = "/api/session-messages",
7
+ Config = "/api/config",
8
+ DescribedTime = "/api/described-times",
9
+ TrackedTimes = "/api/tracked-times",
10
+ Holidays = "/api/holidays",
11
+ News = "/api/news",
12
+ Tags = "/api/tags",
13
+ Roles = "/api/roles",
14
+ ScheduledMaintenance = "/api/scheduled-maintenance",
15
+ StatsFilter = "api/stats/filter",
16
+ MinReportDate = "api/stats/min-date",
17
+ AnniversaryUsers = "/api/anniversary-users",
18
+ RequestedDays = "/api/requested-days",
19
+ WallOfGlory = "/api/wall-of-glory",
20
+ WorkingNorm = "api/users/working-norm",
21
+ BirthdayUsers = "/api/birthday-users",
22
+ SendRecommendation = "/api/send-recommendation",
23
+ Stats = "/api/stats",
24
+ TalentPlanner = "/api/talent-planner",
25
+ Projects = "api/projects",
26
+ ProjectsTree = "api/projects-tree",
27
+ ImportEffort = "api/users/import-effort",
28
+ JobProfileGroup = "/api/users/job-profiles",
29
+ WelcomeProgram = "/api/welcome-program",
30
+ Rotation = "api/rotation",
31
+ Cities = "api/cities",
32
+ ReleaseNotes = "api/release-notes",
33
+ ZabbixMap = "api/network-map",
34
+ Sows = "/api/sows",
35
+ Clients = "/api/clients",
36
+ Engagements = "/api/engagements",
37
+ OrganisationStructure = "/api/organisation-structure",
38
+ NewCollegues = "/api/new-collegues",
39
+ OvertimeRequests = "/api/overtime-requests",
40
+ CompensationPackage = "/api/users/me/compensation-package",
41
+ BabyBorn = "/api/baby-born",
42
+ WeddingUser = "/api/wedding-user",
43
+ CostCenters = "/api/cost-centers",
44
+ Users = "/api/users",
45
+ KudosAndSmartsStatistic = "/api/kudos-and-smarts/statistic",
46
+ MyReferrals = "/api/referrals/my-referrals",
47
+ MyReferralLogs = "/api/referrals/my-referral-logs",
48
+ TopRecommenders = "/api/referrals/top-recommenders",
49
+ LastActions = "/api/kudos-and-smarts/last-actions",
50
+ GiveKudos = "/api/kudos-and-smarts/give-kudos",
51
+ CostCenterCategory = "/api/cost-center-category",
52
+ Department = "/api/departments",
53
+ GiveKudosUsersList = "/api/kudos-and-smarts/users-list",
54
+ Tasks = "/api/tasks",
55
+ Folder = "api/tasks/folder",
56
+ DonationCampaign = "/api/donation-campaign",
57
+ Donation = "/api/donation-transaction",
58
+ Upload = "/api/upload",
59
+ DonationAttachment = "/api/donation-attachment",
60
+ PipeDriveOption = "/api/pipedrive-option",
61
+ Banner = "/api/banners",
62
+ Assets = "/api/users/assets",
63
+ PositionSubscription = "/api/position-subscription",
64
+ Currency = "/api/currency",
65
+ Rate = "/api/rates",
66
+ Timesheet = "/api/timesheets",
67
+ TimesheetDiscount = "/api/timesheets/discount",
68
+ TimesheetReimbursed = "/api/timesheets/reimbursed",
69
+ JobProfile = "/api/job-profile",
70
+ EmployeeReport = "/api/report/employees",
71
+ Locations = "/api/location",
72
+ MyProfile = "/api/users/my-profile",
73
+ Employees = "/api/employees",
74
+ EmploymentTypes = "/api/employment-types",
75
+ EmergencyContacts = "/api/emergency-contact",
76
+ LeavesAndAbsences = "/api/leaves-and-absences",
77
+ Delivery = "/api/delivery-address",
78
+ Trainings = "/api/events",
79
+ Skills = "/api/skills",
80
+ JiraSatisfactionSurvey = "/api/enps-survey",
81
+ IntelliStoreCategory = "/api/smart-catalog/category",
82
+ IntelliStoreType = "/api/smart-catalog/type",
83
+ IntelliStoreAttribute = "/api/smart-catalog/attribute",
84
+ IntelliStoreProduct = "/api/smart-catalog/product",
85
+ IntelliStoreOrder = "/api/smart-catalog/order",
86
+ IntelliStoreStat = "/api/smart-catalog/statistic",
87
+ IntelliStoreClient = "/api/smart-catalog/shop",
88
+ IntelliStoreWishlist = "/api/smart-catalog/wish-list",
89
+ Dictionary = "/api/dictionary",
90
+ Offices = "/api/offices",
91
+ Calendars = "/api/calendars",
92
+ ImprovementsHub = "/api/improvements-hub",
93
+ ViewLogs = "/api/logs",
94
+ TotalRewardsPortal = "/api/total-rewards-portal",
95
+ CompensationPackages = "/api/compensation-package",
96
+ Timezones = "/api/available-timezones",
97
+ AccessCards = "/api/access_card",
98
+ ValidationCompensation = "/api/validation-compensations",
99
+ VacationAndSickBalance = "/api/vacation-and-sick-balance",
100
+ TechnicalWorks = "/api/technical-work",
101
+ PDUSystem = "/api/pdu-system",
102
+ Logger = "/api/logger",
103
+ BenefitsPackages = "/api/benefits-package",
104
+ OnCallRate = "/api/on-call-rate",
105
+ OnCallSupport = "/api/on-call-support",
106
+ OnCallSupportEmployee = "/api/on-call-support-employee",
107
+ }
@@ -0,0 +1,291 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
2
+ import * as moment from "moment";
3
+ import { Collection } from "collect.js";
4
+ import DefaultSubscribers from "./subscribers/DefaultSubscribers";
5
+ import { BaseUrl } from "./BaseUrl";
6
+ import AxiosProxy from "../helpers/response/AxiosProxy";
7
+ import * as Response from "../helpers/response/ResponseInterface";
8
+ import * as ModelHelper from "../helpers/model/ModelHelper";
9
+ import { ResponseCode } from "../helpers/response/ResponseCode";
10
+ import { Meta } from "../helpers/response/ResponseInterface";
11
+ import NotificationModel from "../models/user/NotificationModel";
12
+ import Model from "../models/Model";
13
+ import ResponseHelper, {
14
+ DefaultContext,
15
+ } from "../helpers/response/ResponseHelper";
16
+
17
+ export type PaginatedResponse = {
18
+ collection: Collection<Model>;
19
+ meta: Meta;
20
+ };
21
+ export default abstract class Repository {
22
+ protected baseUrl: BaseUrl;
23
+ protected responseHelper: ResponseHelper;
24
+ protected axiosProxy: AxiosProxy;
25
+
26
+ protected constructor(baseUrl: BaseUrl) {
27
+ this.baseUrl = baseUrl;
28
+ this.responseHelper = new ResponseHelper();
29
+ this.responseHelper.applySubscribers(
30
+ new DefaultSubscribers(),
31
+ DefaultContext
32
+ );
33
+ this.axiosProxy = new AxiosProxy(this.responseHelper);
34
+ }
35
+
36
+ getResponseHelper() {
37
+ return this.responseHelper;
38
+ }
39
+
40
+ protected async getData<TData>(
41
+ resource = "",
42
+ parameters?,
43
+ context: string = DefaultContext
44
+ ) {
45
+ const response = await this.axiosProxy.get<TData>(
46
+ this.getUrl(resource),
47
+ this.getConfig({ params: parameters }),
48
+ context
49
+ );
50
+
51
+ return response.data;
52
+ }
53
+
54
+ protected async getResource<TData>(
55
+ model,
56
+ resource = "",
57
+ parameters?,
58
+ context: string = DefaultContext
59
+ ) {
60
+ const response = await this.axiosProxy.get<Response.Read<TData>>(
61
+ this.getUrl(resource),
62
+ this.getConfig({ params: parameters }),
63
+ context
64
+ );
65
+
66
+ if (response.data.data === undefined) {
67
+ console.error(
68
+ 'Key "data" does not exist in response from API',
69
+ response.data
70
+ );
71
+ }
72
+
73
+ return response.status < ResponseCode.BadRequest
74
+ ? this.map(model, response.data.data)
75
+ : null;
76
+ }
77
+
78
+ protected async getPaginatedResource<TData>(
79
+ model: typeof Model,
80
+ resource = "",
81
+ parameters?: Record<string, unknown>,
82
+ context: string = DefaultContext
83
+ ): Promise<PaginatedResponse> {
84
+ const response = await this.axiosProxy.get<{
85
+ data: { data: Record<string, unknown> };
86
+ meta: Meta;
87
+ }>(this.getUrl(resource), this.getConfig({ params: parameters }), context);
88
+ if (response.status < ResponseCode.BadRequest) {
89
+ return {
90
+ collection: this.map(
91
+ model !== undefined ? model : NotificationModel,
92
+ response.data.data
93
+ ),
94
+ meta: response.data.meta,
95
+ };
96
+ }
97
+
98
+ return null;
99
+ }
100
+
101
+ protected async getFile<TData>(
102
+ model,
103
+ resource = "",
104
+ parameters?,
105
+ context: string = DefaultContext
106
+ ) {
107
+ const response = await this.axiosProxy.get<Response.Read<TData>>(
108
+ this.getUrl(resource),
109
+ this.getConfig({ params: parameters, responseType: "blob" }),
110
+ context
111
+ );
112
+ return response.status < ResponseCode.BadRequest
113
+ ? this.map(model, response.data)
114
+ : null;
115
+ }
116
+
117
+ protected async postData<TData>(
118
+ resource = "",
119
+ data?,
120
+ parameters?,
121
+ context: string = DefaultContext
122
+ ) {
123
+ const response = await this.axiosProxy.post<TData>(
124
+ this.getUrl(resource),
125
+ data,
126
+ this.getConfig({ params: parameters }),
127
+ context
128
+ );
129
+ return response.data;
130
+ }
131
+
132
+ protected async post<TData>(
133
+ resource = "",
134
+ data?,
135
+ parameters?,
136
+ context: string = DefaultContext
137
+ ): Promise<AxiosResponse<TData>> {
138
+ return this.axiosProxy.post<TData>(
139
+ this.getUrl(resource),
140
+ data,
141
+ this.getConfig({ params: parameters }),
142
+ context
143
+ );
144
+ }
145
+
146
+ protected async putResource<TData>(
147
+ model,
148
+ resource = "",
149
+ data?,
150
+ context: string = DefaultContext
151
+ ) {
152
+ const response = await this.axiosProxy.put<Response.Read<TData>>(
153
+ this.getUrl(resource),
154
+ data,
155
+ this.getConfig({ params: {} }),
156
+ context
157
+ );
158
+
159
+ return response.status < ResponseCode.BadRequest
160
+ ? this.map(model, response.data.data)
161
+ : null;
162
+ }
163
+
164
+ protected async postResource<TData>(
165
+ model,
166
+ resource = "",
167
+ data?,
168
+ context: string = DefaultContext
169
+ ) {
170
+ const response = await this.axiosProxy.post<Response.Read<TData>>(
171
+ this.getUrl(resource),
172
+ data,
173
+ this.getConfig({ params: {} }),
174
+ context
175
+ );
176
+
177
+ return response.status < ResponseCode.BadRequest
178
+ ? this.map(model, response.data.data)
179
+ : null;
180
+ }
181
+
182
+ protected async putData<TData>(
183
+ resource = "",
184
+ data?,
185
+ parameters?,
186
+ context: string = DefaultContext
187
+ ) {
188
+ const response = await this.axiosProxy.put<TData>(
189
+ this.getUrl(resource),
190
+ data,
191
+ this.getConfig({ params: parameters }),
192
+ context
193
+ );
194
+
195
+ return response.data;
196
+ }
197
+
198
+ protected async put<TData>(
199
+ resource = "",
200
+ data?,
201
+ parameters?,
202
+ context: string = DefaultContext
203
+ ): Promise<AxiosResponse<TData>> {
204
+ return this.axiosProxy.put<TData>(
205
+ this.getUrl(resource),
206
+ data,
207
+ this.getConfig({ params: parameters }),
208
+ context
209
+ );
210
+ }
211
+
212
+ protected async deleteData(
213
+ resource = "",
214
+ parameters?: unknown,
215
+ context: string = DefaultContext
216
+ ) {
217
+ const response = await this.axiosProxy.delete(
218
+ this.getUrl(resource),
219
+ this.getConfig({ params: parameters }),
220
+ context
221
+ );
222
+
223
+ return response.data;
224
+ }
225
+
226
+ protected async deleteResource(
227
+ resource = "",
228
+ parameters?: unknown,
229
+ context: string = DefaultContext
230
+ ): Promise<AxiosResponse> {
231
+ return this.axiosProxy.delete(
232
+ this.getUrl(resource),
233
+ this.getConfig({ params: parameters }),
234
+ context
235
+ );
236
+ }
237
+
238
+ protected async patch(resource = "", context: string = DefaultContext) {
239
+ return this.axiosProxy.patch(
240
+ this.getUrl(resource),
241
+ this.getConfig(),
242
+ context
243
+ );
244
+ }
245
+
246
+ protected async patchData<TData>(
247
+ resource = "",
248
+ data?,
249
+ parameters?,
250
+ context: string = DefaultContext
251
+ ) {
252
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
253
+ const response = await this.axiosProxy.patch<TData>(
254
+ this.getUrl(resource),
255
+ { ...data, ...this.getConfig({ params: parameters }) },
256
+ context
257
+ );
258
+ return response.data;
259
+ }
260
+
261
+ protected map(model, resource) {
262
+ // Todo: model must be specified each time, remove this!!!
263
+ if (!model) {
264
+ return resource;
265
+ }
266
+ return ModelHelper.map(model, resource);
267
+ }
268
+ protected getUrl(resource: string): string {
269
+ if (this.baseUrl === null) {
270
+ throw new Error("baseUrl is not specified");
271
+ }
272
+ return this.baseUrl + resource;
273
+ }
274
+
275
+ protected getQueryString(params): string {
276
+ return Object.keys(params)
277
+ .map((key) => `${key}=${params[key]}`)
278
+ .join("&");
279
+ }
280
+
281
+ protected getConfig(
282
+ parameters?: Record<string, unknown>
283
+ ): AxiosRequestConfig {
284
+ return {
285
+ ...parameters,
286
+ headers: {
287
+ tz: moment.tz?.guess(),
288
+ },
289
+ };
290
+ }
291
+ }
@@ -0,0 +1,99 @@
1
+ import { Collection } from "collect.js";
2
+ import { ResponseCode } from "../helpers/response/ResponseCode";
3
+ import { BaseUrl } from "./BaseUrl";
4
+ import { Read } from "../helpers/response/ResponseInterface";
5
+ import { DefaultContext } from "../helpers/response/ResponseHelper";
6
+ import CreateSubscribers from "./subscribers/CreateSubscribers";
7
+ import UpdateSubscribers from "./subscribers/UpdateSubscribers";
8
+ import DeleteSubscribers from "./subscribers/DeleteSubscribers";
9
+ import Repository from "./Repository";
10
+ import DownloadSubscribers from "./subscribers/DownloadSubscribers";
11
+
12
+ export type Config = {
13
+ resourceName?: string;
14
+ successMessage?: string;
15
+ };
16
+
17
+ export const CreateContext = "create";
18
+ export const UpdateContext = "update";
19
+ export const DeleteContext = "delete";
20
+ export const DownloadContext = "download";
21
+ export const RejectContext = "reject";
22
+ export const ConfirmContext = "confirm";
23
+ export const ApproveContext = "approve";
24
+ export const HeadContext = "head";
25
+
26
+ export default abstract class ResourceRepository<
27
+ TModel extends new (...args: any) => any
28
+ > extends Repository {
29
+ protected model: TModel;
30
+ protected config: Config;
31
+
32
+ protected constructor(baseUrl: BaseUrl, model: TModel, config?: Config) {
33
+ super(baseUrl);
34
+ this.model = model;
35
+ this.responseHelper.applySubscribers(
36
+ new CreateSubscribers(config?.resourceName),
37
+ CreateContext
38
+ );
39
+ this.responseHelper.applySubscribers(
40
+ new UpdateSubscribers(config?.resourceName, config?.successMessage),
41
+ UpdateContext
42
+ );
43
+ this.responseHelper.applySubscribers(
44
+ new DeleteSubscribers(config?.resourceName),
45
+ DeleteContext
46
+ );
47
+ this.responseHelper.applySubscribers(
48
+ new DownloadSubscribers(config?.resourceName),
49
+ DownloadContext
50
+ );
51
+ }
52
+
53
+ async getById(
54
+ id: number | string,
55
+ context: string = DefaultContext
56
+ ): Promise<TModel> {
57
+ return await this.getResource(this.model, `/${id}`, {}, context);
58
+ }
59
+
60
+ async all(
61
+ parameters?,
62
+ context: string = DefaultContext
63
+ ): Promise<Collection<TModel>> {
64
+ return await this.getResource(this.model, "", parameters, context);
65
+ }
66
+
67
+ async create(model: TModel) {
68
+ const response = await this.axiosProxy.post<Read<TModel>>(
69
+ this.getUrl(""),
70
+ model,
71
+ this.getConfig(),
72
+ CreateContext
73
+ );
74
+ return response.status === ResponseCode.Created
75
+ ? this.map(this.model, response.data.data)
76
+ : null;
77
+ }
78
+
79
+ async update(id: number | string, model: InstanceType<TModel>) {
80
+ const response = await this.axiosProxy.put<Read<TModel>>(
81
+ this.getUrl(`/${id}`),
82
+ model,
83
+ this.getConfig(),
84
+ UpdateContext
85
+ );
86
+ return response.status === ResponseCode.Ok
87
+ ? this.map(this.model, response.data.data)
88
+ : null;
89
+ }
90
+
91
+ async delete(id: number | string) {
92
+ const response = await this.axiosProxy.delete(
93
+ this.getUrl(`/${id}`),
94
+ this.getConfig(),
95
+ DeleteContext
96
+ );
97
+ return response.status === ResponseCode.NoContent;
98
+ }
99
+ }
@@ -0,0 +1,43 @@
1
+ import TrackedTimeModel from "../models/TrackedTimeModel";
2
+ import * as Response from "../helpers/response/ResponseInterface";
3
+ import { ResponseCode } from "../helpers/response/ResponseCode";
4
+ import ResourceRepository from "./ResourceRepository";
5
+ import { BaseUrl } from "./BaseUrl";
6
+
7
+ export const PlayContext = "play";
8
+ export const PauseContext = "pause";
9
+
10
+ export default class TrackedTimeRepository extends ResourceRepository<
11
+ typeof TrackedTimeModel
12
+ > {
13
+ constructor() {
14
+ super(BaseUrl.TrackedTimes, TrackedTimeModel, {
15
+ resourceName: "Worked Time",
16
+ });
17
+ }
18
+
19
+ async latest(): Promise<TrackedTimeModel> {
20
+ return await this.getResource(this.model, "/latest");
21
+ }
22
+
23
+ async play() {
24
+ const response = await this.axiosProxy.post<
25
+ Response.Read<TrackedTimeModel>
26
+ >(this.baseUrl, {}, this.getConfig(), PlayContext);
27
+ return response.status === ResponseCode.Created
28
+ ? this.map(this.model, response.data.data)
29
+ : null;
30
+ }
31
+
32
+ async pause() {
33
+ const response = await this.axiosProxy.put<Response.Read<string>>(
34
+ this.baseUrl,
35
+ {},
36
+ this.getConfig(),
37
+ PauseContext
38
+ );
39
+ return response.status === ResponseCode.Ok
40
+ ? this.map(this.model, response.data.data)
41
+ : null;
42
+ }
43
+ }