Skip to content

Commit fae9a5e

Browse files
Fix circular deps (#306)
## Изменения <!-- Опишите здесь на языке, понятном каждому, изменения, сделанные в исходном коде по пунктам. --> ## Детали реализации <!-- Здесь можно описать технические детали по пунктам. --> ## Check-List <!-- После сохранения у следующих полей появятся галочки, которые нужно проставить мышкой --> - [ ] Вы проверили свой код перед отправкой запроса? - [ ] Вы написали тесты к реализованным функциям? - [ ] Вы не забыли применить форматирование `black` и `isort` для _Back-End_ или `Prettier` для _Front-End_? --------- Co-authored-by: Artem Netsvetaev <[email protected]>
1 parent 2f6ce44 commit fae9a5e

33 files changed

+823
-137
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
"test": "vitest",
1313
"lint": "eslint \"**/*.{vue,ts}\"",
1414
"lint:fix": "eslint \"**/*.{vue,ts}\" --fix",
15+
"lint:deadcode": "knip --exclude binaries,dependencies,unlisted",
16+
"lint:circular": "dpdm --exit-code circular:1 --no-tree --no-warning --progress false --transform './src/main.ts'",
1517
"prettier": "prettier . --check",
1618
"prettier:write": "prettier . --write",
1719
"stylelint": "stylelint \"**/*.{vue,css}\"",
1820
"stylelint:fix": "stylelint \"**/*.{vue,css}\" --fix",
19-
"format": "pnpm run lint:fix && pnpm run prettier:write && pnpm run stylelint:fix",
21+
"format": "vue-tsc && pnpm run lint:fix && pnpm run prettier:write && pnpm run stylelint:fix",
2022
"check": "vue-tsc && pnpm run lint && pnpm run prettier && pnpm run stylelint"
2123
},
2224
"dependencies": {
@@ -41,11 +43,13 @@
4143
"@typescript-eslint/parser": "^8.15.0",
4244
"@vitejs/plugin-vue": "^5.2.0",
4345
"@vue/eslint-config-typescript": "^14.1.3",
46+
"dpdm": "^3.14.0",
4447
"eslint": "^9.15.0",
4548
"eslint-config-prettier": "^9.1.0",
4649
"eslint-plugin-prettier": "^5.2.1",
4750
"eslint-plugin-vue": "^9.31.0",
4851
"globals": "^15.12.0",
52+
"knip": "^5.45.0",
4953
"openapi-typescript": "^7.4.3",
5054
"postcss": "^8.4.49",
5155
"postcss-html": "^1.7.0",
@@ -55,6 +59,7 @@
5559
"stylelint-config-recommended-vue": "^1.5.0",
5660
"stylelint-config-standard": "^36.0.1",
5761
"typescript": "5.6.3",
62+
"typescript-eslint": "^8.26.0",
5863
"vite": "^5.4.11",
5964
"vite-plugin-eslint": "^1.8.1",
6065
"vite-plugin-pwa": "^0.21.0",

pnpm-lock.yaml

Lines changed: 734 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import IrdomToastList from './components/IrdomToastList.vue';
88
import { useToolbar } from './store/toolbar';
99
import IrdomToolbar from './components/IrdomToolbar.vue';
1010
import CalendarDropdown from './views/timetable/CalendarDropdown.vue';
11-
import apiClient from '@/api/';
11+
import { apiClient } from '@/api/';
1212
1313
const profileStore = useProfileStore();
1414
const toolbar = useToolbar();

src/api/client.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createClient } from '@profcomff/api-uilib';
2+
import { type Middleware } from 'openapi-fetch';
3+
import { ApiError, ErrorInfo } from './types';
4+
5+
export function recordError(url: string, status: number, error: ApiError | undefined) {
6+
if (error) {
7+
const errorInfo: ErrorInfo = {
8+
url,
9+
status,
10+
message: error.message,
11+
};
12+
apiClient.POST('/marketing/v1/action', {
13+
body: {
14+
action: 'error',
15+
additional_data: JSON.stringify(errorInfo),
16+
},
17+
});
18+
}
19+
}
20+
21+
const errorMiddleware: Middleware = {
22+
async onResponse({ response }) {
23+
const data = await response.clone();
24+
if (!response.ok) {
25+
const error = await data.json();
26+
recordError(response.url, response.status, await error);
27+
return undefined;
28+
}
29+
return response;
30+
},
31+
};
32+
33+
export const apiClient = createClient(import.meta.env.VITE_API_URL);
34+
apiClient.use(errorMiddleware);

src/api/controllers/TimetableApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { stringifyDate, getDateWithDayOffset } from './../../utils/date';
22
import { useTimetableStore } from './../../store/timetable';
3-
import apiClient from '@/api/';
3+
import { apiClient } from '../client';
44

55
interface GetLecturersParams {
66
query?: string;

src/api/controllers/UserdataApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { apply, checkToken, showErrorToast } from './auth/decorators';
22
import { UserdataUpdateUser } from '@/models';
3-
import apiClient from '@/api/';
3+
import { apiClient } from '../client';
44

55
export class UserdataApi {
66
static getUser = apply(

src/api/controllers/auth/AuthApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { LocalStorage, LocalStorageItem } from '@/models/LocalStorage';
77
import { UNKNOWN_DEVICE } from '@/models';
88

99
import router from '@/router';
10-
import apiClient from '@/api/';
10+
import { apiClient } from '../../client';
1111

1212
export enum UserInfo {
1313
Groups = 'groups',

src/api/controllers/auth/decorators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import apiClient from '@/api/';
2+
import { ApiError } from '@/api';
3+
import { apiClient } from '../../client';
34
import { ToastType } from '@/models';
45
import router from '@/router';
56
import { useProfileStore } from '@/store/profile';
67
import { useToastStore } from '@/store/toast';
7-
import { apiError } from '@/utils/errorHandler';
88

99
export type Func<R = any, FuncArgs extends any[] = any[]> = (...args: FuncArgs) => R;
1010
type Decorator<F extends Func = Func, DecoratorArgs extends any[] = any[]> = Func<
@@ -44,7 +44,7 @@ export function showErrorToast<F extends Func>(
4444
const response = await method(...args);
4545
return response;
4646
} catch (err) {
47-
const error = err as apiError;
47+
const error = err as ApiError;
4848
if (error) {
4949
toastStore.push({
5050
title: error.ru ?? error.message,

src/api/index.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
export * from './controllers';
2-
import { recordError } from '@/utils/errorHandler';
3-
import { createClient } from '@profcomff/api-uilib';
4-
import { type Middleware } from 'openapi-fetch';
5-
6-
const errorMiddleware: Middleware = {
7-
async onResponse({ response }) {
8-
const data = await response.clone();
9-
if (!response.ok) {
10-
const error = await data.json();
11-
recordError(response.url, response.status, await error);
12-
return undefined;
13-
}
14-
return response;
15-
},
16-
};
17-
18-
const apiClient = createClient(import.meta.env.VITE_API_URL);
19-
apiClient.use(errorMiddleware);
20-
export default apiClient;
1+
export { apiClient } from './client';
2+
export * from './types';
3+
export * from './controllers';

src/api/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type ApiError = {
2+
status: string;
3+
message: string;
4+
ru: string;
5+
};
6+
7+
export interface ErrorInfo {
8+
url: string;
9+
status: number;
10+
message: string;
11+
}

0 commit comments

Comments
 (0)