Skip to content

Commit 764668f

Browse files
authored
Reverting api commits (#250)
## Изменения Отменил коммиты для апи, которые выехали в прод
1 parent be7aaf0 commit 764668f

98 files changed

Lines changed: 3168 additions & 2576 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,43 @@
2020
"check": "vue-tsc && pnpm run lint && pnpm run prettier && pnpm run stylelint"
2121
},
2222
"dependencies": {
23-
"@profcomff/api-uilib": "2024.9.29",
23+
"@profcomff/api-uilib": "2024.7.2-5.2",
24+
"axios": "^1.7.2",
2425
"markdown-it": "^14.1.0",
25-
"openapi-fetch": "^0.12.2",
26-
"pinia": "^2.2.2",
26+
"pinia": "^2.1.7",
2727
"query-string": "^9.1.0",
28-
"ua-parser-js": "^1.0.39",
29-
"vue": "^3.5.10",
30-
"vue-router": "^4.4.5",
28+
"ua-parser-js": "^1.0.38",
29+
"vue": "^3.4.34",
30+
"vue-router": "^4.4.0",
3131
"workbox-window": "^7.1.0"
3232
},
3333
"devDependencies": {
3434
"@types/markdown-it": "^14.1.2",
35-
"@types/node": "^20.16.10",
35+
"@types/node": "^20.14.12",
3636
"@types/ua-parser-js": "^0.7.39",
37-
"@typescript-eslint/eslint-plugin": "^7.18.0",
38-
"@typescript-eslint/parser": "^7.18.0",
39-
"@vitejs/plugin-vue": "^5.1.4",
37+
"@typescript-eslint/eslint-plugin": "^7.17.0",
38+
"@typescript-eslint/parser": "^7.17.0",
39+
"@vitejs/plugin-vue": "^5.1.0",
4040
"@vue/eslint-config-typescript": "^12.0.0",
41-
"eslint": "^8.57.1",
41+
"eslint": "^8.57.0",
4242
"eslint-config-prettier": "^9.1.0",
4343
"eslint-plugin-prettier": "^5.2.1",
44-
"eslint-plugin-vue": "^9.28.0",
45-
"openapi-typescript": "^7.4.1",
46-
"postcss": "^8.4.47",
44+
"eslint-plugin-vue": "^9.27.0",
45+
"postcss": "^8.4.40",
4746
"postcss-html": "^1.7.0",
4847
"postcss-preset-env": "^9.6.0",
4948
"prettier": "^3.3.3",
50-
"stylelint": "^16.9.0",
49+
"stylelint": "^16.7.0",
5150
"stylelint-config-recommended-vue": "^1.5.0",
5251
"stylelint-config-standard": "^36.0.1",
5352
"typescript": "5.3.3",
54-
"vite": "^5.4.8",
53+
"vite": "^5.3.5",
5554
"vite-plugin-eslint": "^1.8.1",
5655
"vite-plugin-pwa": "^0.19.8",
5756
"vite-plugin-stylelint": "^5.3.1",
58-
"vite-plugin-vuetify": "^2.0.4",
57+
"vite-plugin-vuetify": "^2.0.3",
5958
"vitest": "^1.6.0",
60-
"vue-tsc": "^2.1.6",
61-
"vuetify": "^3.7.2"
59+
"vue-tsc": "^2.0.29",
60+
"vuetify": "^3.6.13"
6261
}
6362
}

pnpm-lock.yaml

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

src/App.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import { onMounted } from 'vue';
3+
import { marketingApi } from './api/marketing';
34
import { useProfileStore } from './store/profile';
45
import { useTimetableStore } from './store/timetable';
56
import { navbarItems } from './constants/navbarItems';
@@ -8,7 +9,6 @@ import IrdomToastList from './components/IrdomToastList.vue';
89
import { useToolbar } from './store/toolbar';
910
import IrdomToolbar from './components/IrdomToolbar.vue';
1011
import CalendarDropdown from './views/timetable/CalendarDropdown.vue';
11-
import apiClient from '@/api/';
1212
1313
const profileStore = useProfileStore();
1414
const toolbar = useToolbar();
@@ -22,11 +22,9 @@ onMounted(async () => {
2222
updateTokenScopes();
2323
await updateMarketingId();
2424
if (profileStore.marketingId) {
25-
apiClient.POST('/marketing/v1/action', {
26-
body: {
27-
action: 'app loaded',
28-
user_id: profileStore.marketingId,
29-
},
25+
marketingApi.writeAction({
26+
action: 'app loaded',
27+
user_id: profileStore.marketingId,
3028
});
3129
}
3230
});

src/api/BaseApi.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import axios, { AxiosResponse } from 'axios';
2+
import queryString from 'query-string';
3+
import { createClient } from '@profcomff/api-uilib';
4+
5+
const apiClient = createClient(import.meta.env.VITE_API_URL);
6+
export default apiClient;
7+
8+
export interface DefaultResponse {
9+
status: string;
10+
message: string;
11+
ru?: string;
12+
}
13+
14+
export class BaseApi {
15+
url: string;
16+
17+
constructor(path: string) {
18+
this.url = import.meta.env.VITE_API_URL + path;
19+
}
20+
21+
protected async get<Response, Params = never>(
22+
path: string,
23+
params?: Params,
24+
headers: Record<string, string> = {}
25+
): Promise<AxiosResponse<Response>> {
26+
if (!headers.Authorization) {
27+
headers.Authorization = localStorage.getItem('token') ?? '';
28+
}
29+
30+
return axios.get<Response>(`${this.url}${path}`, {
31+
params,
32+
headers,
33+
paramsSerializer: {
34+
serialize: params => queryString.stringify(params, { arrayFormat: 'none' }),
35+
},
36+
});
37+
}
38+
39+
protected async post<Response, Body = never>(
40+
path: string,
41+
body?: Body,
42+
headers: Record<string, string> = {}
43+
): Promise<AxiosResponse<Response>> {
44+
if (!headers.Authorization) {
45+
headers.Authorization = localStorage.getItem('token') ?? '';
46+
}
47+
48+
return axios.post<Response, AxiosResponse<Response>, Body>(`${this.url}${path}`, body, {
49+
headers,
50+
});
51+
}
52+
53+
protected async delete<Response, Params = never>(
54+
path: string,
55+
params?: Params,
56+
headers: Record<string, string> = {}
57+
): Promise<AxiosResponse<Response>> {
58+
if (!headers.Authorization) {
59+
headers.Authorization = localStorage.getItem('token') ?? '';
60+
}
61+
62+
return axios.delete<Response>(`${this.url}${path}`, { params, headers });
63+
}
64+
65+
protected async patch<Response, Body>(
66+
path: string,
67+
body: Body,
68+
headers: Record<string, string> = {}
69+
): Promise<AxiosResponse<Response>> {
70+
if (!headers.Authorization) {
71+
headers.Authorization = localStorage.getItem('token') ?? '';
72+
}
73+
74+
return axios.patch<Response, AxiosResponse<Response>, Body>(`${this.url}${path}`, body, {
75+
headers,
76+
});
77+
}
78+
}

src/api/EntityBaseApi.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { BaseApi } from './BaseApi';
2+
import { ArrayResponse, Entity } from './models';
3+
4+
export interface GetAllParams {
5+
limit?: number;
6+
offset?: number;
7+
}
8+
9+
export class EntityBaseApi<
10+
E extends Entity,
11+
GetAllP extends GetAllParams = never,
12+
ModifyB = Omit<E, 'id'>,
13+
GetP = never,
14+
> extends BaseApi {
15+
constructor(path: string) {
16+
super(path);
17+
}
18+
19+
public async getById(id: number, params?: GetP) {
20+
return this.get<E, GetP>(`/${id}`, params);
21+
}
22+
23+
public async getAll(params?: GetAllP) {
24+
return this.get<ArrayResponse<E>, GetAllP>('/', params);
25+
}
26+
27+
public async deleteById(id: number) {
28+
return this.delete<string>(`/${id}`);
29+
}
30+
31+
public async patchById(id: number, body: ModifyB) {
32+
return this.patch<E, ModifyB>(`/${id}`, body);
33+
}
34+
35+
public async create(body: ModifyB) {
36+
return this.post<E, ModifyB>('', body);
37+
}
38+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { BaseApi } from '../BaseApi';
2+
3+
interface AchievementCreate {
4+
name: string;
5+
description: string;
6+
}
7+
interface Reciever {
8+
user_id: number;
9+
}
10+
export interface AchievementGet {
11+
id: number;
12+
name: string;
13+
description: string;
14+
picture: string | undefined;
15+
owner_user_id: number;
16+
recievers: Reciever[] | undefined;
17+
}
18+
interface AchievementEdit {
19+
name?: string | null;
20+
description?: string | null;
21+
}
22+
export interface UserAchievementsGet {
23+
id: number;
24+
achievement: AchievementGet[];
25+
}
26+
27+
class AchievementApi extends BaseApi {
28+
constructor() {
29+
super('/achievement');
30+
}
31+
32+
public async create(name: string, description: string, picture: File) {
33+
const form = new FormData();
34+
form.append('picture_file', picture);
35+
36+
return this.post<AchievementGet, AchievementCreate>('/achievement', { name, description }).then(
37+
resp => this.patch<AchievementGet, FormData>(`/achievement/${resp.data.id}/picture`, form)
38+
);
39+
}
40+
41+
public async edit(id: number, edit: AchievementEdit) {
42+
return this.patch<AchievementGet, AchievementEdit>(`/achievement/${id}`, edit);
43+
}
44+
45+
public async getAll() {
46+
return this.get<AchievementGet[]>('/achievement');
47+
}
48+
49+
public async getOne(id: number) {
50+
return this.get<AchievementGet>(`/achievement/${id}`);
51+
}
52+
53+
public async getRecievers(id: number) {
54+
return this.get<AchievementGet>(`/achievement/${id}/reciever`);
55+
}
56+
57+
public async revoke(user_id: number, achievement_id: number) {
58+
return this.delete<AchievementGet>(`/achievement/${achievement_id}/reciever/${user_id}`);
59+
}
60+
61+
public async give(user_id: number, achievement_id: number) {
62+
return this.post<AchievementGet>(`/achievement/${achievement_id}/reciever/${user_id}`);
63+
}
64+
65+
public async getUser(id: number) {
66+
return this.get<UserAchievementsGet>(`/user/${id}`);
67+
}
68+
69+
public getPictureUrl(picture: string | undefined) {
70+
return import.meta.env.VITE_API_URL + '/achievement/' + picture;
71+
}
72+
}
73+
74+
export const achievementApi = new AchievementApi();

src/api/achievement/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { achievementApi } from './AchievementApi';
2+
export type { AchievementGet, UserAchievementsGet } from './AchievementApi';

src/api/auth/AuthBaseApi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { BaseApi } from '../BaseApi';
2+
3+
export class AuthBaseApi extends BaseApi {
4+
constructor(path = '') {
5+
super(`/auth${path}`);
6+
}
7+
}

src/api/auth/AuthEmailApi.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { DefaultResponse } from '../BaseApi';
2+
import { AuthBaseApi } from './AuthBaseApi';
3+
import { UNKNOWN_DEVICE } from './AuthOauth2BaseApi';
4+
5+
interface RegisterBody {
6+
email: string;
7+
password: string;
8+
}
9+
10+
interface LoginBody {
11+
email: string;
12+
password: string;
13+
scopes?: string[];
14+
session_name?: string;
15+
}
16+
17+
interface RequestResetEmailBody {
18+
email: string;
19+
}
20+
21+
interface ApproveEmailParams {
22+
token: string;
23+
}
24+
25+
interface RequestResetPasswordBody {
26+
password: string;
27+
new_password: string;
28+
}
29+
30+
interface RequestResetForgottenPasswordBody {
31+
email: string;
32+
}
33+
34+
interface ResetPasswordParams {
35+
new_password: string;
36+
}
37+
38+
interface LoginResponse {
39+
token: string;
40+
expires: string;
41+
id: number;
42+
user_id: number;
43+
session_scopes: string[];
44+
}
45+
46+
class AuthEmailApi extends AuthBaseApi {
47+
constructor() {
48+
super('/email');
49+
}
50+
51+
public async register(body: RegisterBody) {
52+
return this.post<DefaultResponse, RegisterBody>('/registration', body);
53+
}
54+
55+
public async login(body: LoginBody) {
56+
if (!body.session_name) {
57+
body.session_name = navigator.userAgent ?? UNKNOWN_DEVICE;
58+
}
59+
60+
return this.post<LoginResponse, LoginBody>('/login', body);
61+
}
62+
63+
public async approveEmail(params: ApproveEmailParams) {
64+
return this.get<DefaultResponse, ApproveEmailParams>('/approve', params);
65+
}
66+
67+
public async requestResetEmail(body: RequestResetEmailBody) {
68+
return this.post<DefaultResponse, RequestResetEmailBody>('/reset/email/request', body);
69+
}
70+
71+
public async resetEmail(params: ApproveEmailParams) {
72+
return this.get<DefaultResponse, ApproveEmailParams>('/reset/email', params);
73+
}
74+
75+
public async requestResetPassword(body: RequestResetPasswordBody) {
76+
return this.post<DefaultResponse, RequestResetPasswordBody>('/reset/password/request', body);
77+
}
78+
79+
public async requestResetForgottenPassword(body: RequestResetForgottenPasswordBody) {
80+
return this.post<DefaultResponse, RequestResetForgottenPasswordBody>(
81+
'/reset/password/restore',
82+
body
83+
);
84+
}
85+
86+
public async resetPassword(body: ResetPasswordParams, token: string) {
87+
return this.post<DefaultResponse, ResetPasswordParams>('/reset/password', body, {
88+
'reset-token': token,
89+
});
90+
}
91+
}
92+
93+
export const authEmailApi = new AuthEmailApi();

0 commit comments

Comments
 (0)