Skip to content

Commit

Permalink
resolved type issues in auth
Browse files Browse the repository at this point in the history
  • Loading branch information
BatuevIO committed Sep 5, 2024
1 parent 21e6558 commit 51390c5
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
11 changes: 6 additions & 5 deletions src/api/auth/AuthGroupApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Group, Scope } from '../models';
import { Scope } from '../models';
import { AuthGroup } from '@/models';
import { AuthBaseApi } from './AuthBaseApi';

interface CreateGroupBody {
Expand All @@ -20,10 +21,10 @@ export enum GroupInfo {
Users = 'users',
}

type GetGroupResponse<Info extends GroupInfo> = Group & {
type GetGroupResponse<Info extends GroupInfo> = AuthGroup & {
[GroupInfo.Scopes]: GroupInfo.Scopes extends Info ? Scope[] : never;
[GroupInfo.IndirectScopes]: GroupInfo.IndirectScopes extends Info ? Scope[] : never;
[GroupInfo.Children]: GroupInfo.Children extends Info ? Group[] : never;
[GroupInfo.Children]: GroupInfo.Children extends Info ? AuthGroup[] : never;
[GroupInfo.Users]: never;
};

Expand All @@ -41,7 +42,7 @@ class AuthGroupApi extends AuthBaseApi {
}

public async patchGroup(id: number, body: Partial<PatchGroupBody>) {
return this.patch<Group, Partial<PatchGroupBody>>(`/${id}`, body);
return this.patch<AuthGroup, Partial<PatchGroupBody>>(`/${id}`, body);
}

public async renameGroup(id: number, name: string) {
Expand All @@ -53,7 +54,7 @@ class AuthGroupApi extends AuthBaseApi {
}

public async createGroup(body: CreateGroupBody) {
return this.post<Group, CreateGroupBody>('', body);
return this.post<AuthGroup, CreateGroupBody>('', body);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/api/auth/AuthUserApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Group, User, Scope } from '../models';
import { User, Scope } from '../models';
import { AuthBaseApi } from './AuthBaseApi';
import { Group } from '@/models';

export enum UserInfo {
Groups = 'groups',
Expand Down
22 changes: 7 additions & 15 deletions src/api/marketing/MarketingApi.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { BaseApi } from '../BaseApi';
import apiClient, { BaseApi } from '../BaseApi';
import { components } from '@profcomff/api-uilib/src/openapi/marketing';

interface WriteActionBody {
user_id: number;
action: string;
additional_data?: string;
path_from?: string;
path_to?: string;
}

interface MarketingUser {
id: number;
union_number: string;
}
type WriteActionBody = components['schemas']['ActionInfo'];

class MarketingApi extends BaseApi {
constructor() {
Expand All @@ -23,11 +13,13 @@ class MarketingApi extends BaseApi {
data.user_agent = navigator.userAgent;
body.additional_data = JSON.stringify(data);

return this.post<string, WriteActionBody>('/action', body);
apiClient.POST('/marketing/v1/action', {
body,
});
}

public async createUser() {
return this.post<MarketingUser>('/user');
apiClient.POST('/marketing/v1/user');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/EventRow.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Event } from '@/api/models';
import { Event } from '@/models';
import { computed } from 'vue';
import DataRow from './DataRow.vue';
import { getNameWithInitials } from '@/utils/personName';
Expand Down
2 changes: 1 addition & 1 deletion src/models/LocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum LocalStorageItem {
StudyGroup = 'timetable-group',
Group = 'timetable-group',
Token = 'token',
TokenScopes = 'token-scopes',
MarketingId = 'marketing-id',
Expand Down
10 changes: 10 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { UserdataExtendedValue } from '@/api/models';
import { components as timetableComponents } from '@profcomff/api-uilib/src/openapi/timetable';
import { components as authComponents } from '@profcomff/api-uilib/src/openapi/auth';

type Lecturer = timetableComponents['schemas']['LecturerGet'];
type Room = timetableComponents['schemas']['RoomGet'];
type Event = timetableComponents['schemas']['Event'];
type Group = timetableComponents['schemas']['GroupGet'];
type AuthGroup = authComponents['schemas']['Group'];

export type { Lecturer, Room, Event, Group, AuthGroup };

export enum ToastType {
Error = 'error',
Expand Down
13 changes: 7 additions & 6 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { GroupInfo } from './../api/auth/AuthGroupApi';
import { Group, Scope, User } from '@/api/models';
import { Scope, User } from '@/api/models';
import { AuthGroup } from '@/models';
import { defineStore } from 'pinia';
import { ref } from 'vue';

interface StoreUser extends User {
groups?: Group[];
indirectGroups?: Group[];
groups?: AuthGroup[];
indirectGroups?: AuthGroup[];
scopes?: Scope[];
deleted: boolean;
}

export interface StoreGroup extends Group {
export interface StoreGroup extends AuthGroup {
scopes: Map<number, Scope>;
children: Map<number, StoreGroup>;
parent: StoreGroup | null;
users: Map<number, StoreUser>;
}

interface SetGroupArgs extends Group {
interface SetGroupArgs extends AuthGroup {
[GroupInfo.Scopes]?: Scope[];
[GroupInfo.Children]?: Group[];
[GroupInfo.Children]?: AuthGroup[];
[GroupInfo.Users]?: User[];
}

Expand Down
7 changes: 1 addition & 6 deletions src/store/timetable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { LocalStorage, LocalStorageItem } from '@/models/LocalStorage';
import { stringifyDate } from '@/utils/date';
import type { components } from '@profcomff/api-uilib/src/openapi/timetable';
import { defineStore } from 'pinia';
import { ref } from 'vue';

type Lecturer = components['schemas']['LecturerGet'];
type Room = components['schemas']['RoomGet'];
type Event = components['schemas']['Event'];
type Group = components['schemas']['GroupGet'];
import { Lecturer, Room, Event, Group } from '@/models';

interface StoreLecturer extends Lecturer {
schedule: Map<number, Event> | null;
Expand Down
4 changes: 2 additions & 2 deletions src/views/timetable/init/AsyncGroupsList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { StudyGroup } from '@/api/models';
import { Group } from '@/models';
import { computed } from 'vue';
import GroupsListItem from './GroupsListItem.vue';
import apiClient from '@/api/BaseApi';
Expand Down Expand Up @@ -43,7 +43,7 @@ const sorted = computed(() =>
'6': [],
'': [],
'': [],
} as Record<string, StudyGroup[]>
} as Record<string, Group[]>
)
);
</script>
Expand Down
8 changes: 4 additions & 4 deletions src/views/timetable/init/GroupsListItem.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<script setup lang="ts">
import { StudyGroup } from '@/api/models';
import { Group } from '@/models';
import { LocalStorage, LocalStorageItem } from '@/models/LocalStorage';
import { useTimetableStore } from '@/store/timetable';
import { useRouter } from 'vue-router';
defineProps<{
course: string;
groups: StudyGroup[];
groups: Group[];
}>();
const router = useRouter();
const { updateGroup } = useTimetableStore();
const setGroup = (group: StudyGroup) => {
LocalStorage.set<StudyGroup>(LocalStorageItem.StudyGroup, group);
const setGroup = (group: Group) => {
LocalStorage.set<Group>(LocalStorageItem.Group, group);
updateGroup();
router.push('/timetable');
Expand Down

0 comments on commit 51390c5

Please sign in to comment.