From 5c339d53badae17d74dc983077e1326b22c6043a Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 25 Jan 2020 11:44:15 +0100 Subject: [PATCH] Change level query to correspond to the new api --- .../main-navigation/main-navigation.component.ts | 2 +- src/app/components/profile/profile.component.ts | 2 +- src/app/models/friendinfo.ts | 13 +++++++------ src/app/models/interfaces/IUser.ts | 2 +- src/app/models/user.ts | 8 ++++++-- src/app/services/chat/chat.service.ts | 8 ++++---- src/app/services/login/login.service.ts | 10 ++++++++-- src/app/services/profile/profile.service.ts | 5 ++++- src/app/services/register/register.service.ts | 10 ++++++++-- src/app/services/search/search.service.ts | 10 ++++++++-- src/app/services/selfservice/self.service.ts | 10 ++++++++-- 11 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/app/components/main-navigation/main-navigation.component.ts b/src/app/components/main-navigation/main-navigation.component.ts index 2990672..a9bcdc2 100644 --- a/src/app/components/main-navigation/main-navigation.component.ts +++ b/src/app/components/main-navigation/main-navigation.component.ts @@ -66,7 +66,7 @@ export class MainNavigationComponent implements OnInit { this.loggedIn = user.loggedIn; this.userId = user.userID; this.username = user.username; - this.level = this.levellist.getLevelName(user.level); + this.level = user.levelName; this.points = user.points; this.profileUrl = '/profile/' + this.userId; if (this.user.darkmode === true && this.lighttheme) { diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 81bb20b..200f2d9 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -63,7 +63,7 @@ export class ProfileComponent implements OnInit { // tslint:disable-next-line:max-line-length this.userProfile.allowedToSendRequest = this.requestService.isAllowedToSendRequest(this.userProfile.userID, this.self); this.ownProfile = this.userProfile.userID === this.self.userID; - this.rankname = this.levellist.getLevelName(this.userProfile.level); + this.rankname = this.userProfile.levelName; } else { this.profileNotFound = true; } diff --git a/src/app/models/friendinfo.ts b/src/app/models/friendinfo.ts index bfca61c..887737b 100644 --- a/src/app/models/friendinfo.ts +++ b/src/app/models/friendinfo.ts @@ -1,16 +1,17 @@ import {Levellist} from 'src/app/models/levellist'; export class FriendInfo { - levellist: Levellist = new Levellist(); id: number; name: string; - rankname: string; + rankname = 'Rookie'; profilePicture: string; - constructor(pId: number, pName: string, pLevel: number, pic: string) { - this.id = pId; - this.name = pName; - this.rankname = this.levellist.getLevelName(pLevel); + constructor(id: number, name: string, level: {name: string}, pic: string) { + this.id = id; + this.name = name; + if (level) { + this.rankname = level.name; + } this.profilePicture = pic; } } diff --git a/src/app/models/interfaces/IUser.ts b/src/app/models/interfaces/IUser.ts index ca39305..7f23010 100644 --- a/src/app/models/interfaces/IUser.ts +++ b/src/app/models/interfaces/IUser.ts @@ -16,7 +16,7 @@ export interface IUser { settings?: string; - level: number; + level: {name: string, levelNumber: number}; points: number; diff --git a/src/app/models/user.ts b/src/app/models/user.ts index 528e7ce..6836d10 100644 --- a/src/app/models/user.ts +++ b/src/app/models/user.ts @@ -12,7 +12,8 @@ export class User { handle: string; email: string; points: number; - level: number; + level = 0; + levelName = 'Rookie'; profilePicture: string; joinedAt: string; friendCount: number; @@ -36,7 +37,10 @@ export class User { this.handle = userDataResponse.handle; this.email = userDataResponse.email; this.points = userDataResponse.points; - this.level = userDataResponse.level; + if (userDataResponse.level) { + this.level = userDataResponse.level.levelNumber; + this.levelName = userDataResponse.level.name; + } this.profilePicture = this.buildProfilePictureUrl(userDataResponse.profilePicture); this.joinedAt = userDataResponse.joinedAt; this.friendCount = userDataResponse.friendCount; diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts index 14a5c82..bec24a8 100644 --- a/src/app/services/chat/chat.service.ts +++ b/src/app/services/chat/chat.service.ts @@ -105,7 +105,7 @@ export class ChatService { for (const chat of temp.data.getSelf.chats) { let memberID: number; let memberName: string; - let memberLevel: number; + let memberLevel: {name: string, levelNumber: number}; let profilePicture: string; for (const member of chat.members) { if (member.id !== this.ownID) { @@ -226,7 +226,7 @@ export class ChatService { const body = { query: `query { getSelf { - chats(first: 1000, offset: 0) {members{name, id, level}} + chats(first: 1000, offset: 0) {members{name, id, level {name levelNumber}}} }}` }; @@ -251,7 +251,7 @@ export class ChatService { query: `query { getSelf { chats(first: 10, offset: 0) { - id, members{name, id, level}, + id, members{name, id, level {name levelNumber}}, messages(first: 10, offset: 0) { author {id}, createdAt, content } @@ -265,7 +265,7 @@ export class ChatService { getBodyForGetChatsByID(pChatID: number) { const body = { query: `query($chatID: ID!) { - getChat(chatId: $chatID) {id, members{name, id, level}, + getChat(chatId: $chatID) {id, members{name, id, level {name levelNumber}}, messages(first: 1000, offset: 0) {author {id}, createdAt, content}} } }`, variables: { diff --git a/src/app/services/login/login.service.ts b/src/app/services/login/login.service.ts index ed1884e..b22002f 100644 --- a/src/app/services/login/login.service.ts +++ b/src/app/services/login/login.service.ts @@ -21,14 +21,20 @@ const graphqlQuery = `mutation($email: String!, $pwHash: String!) { email, handle, points, - level, + level { + name + levelNumber + }, profilePicture, receivedRequests{id, sender{name, handle, id}}, sentRequests{receiver{id}}, friends { id, name, - level, + level { + name + levelNumber + }, profilePicture }, groups { diff --git a/src/app/services/profile/profile.service.ts b/src/app/services/profile/profile.service.ts index a808a16..1a8c24d 100644 --- a/src/app/services/profile/profile.service.ts +++ b/src/app/services/profile/profile.service.ts @@ -16,7 +16,10 @@ const graphqlGetProfileQuery = `query($userId: ID) { name profilePicture points - level + level { + name + levelNumber + } friendCount groupCount joinedAt diff --git a/src/app/services/register/register.service.ts b/src/app/services/register/register.service.ts index 2eac62a..7050d4a 100644 --- a/src/app/services/register/register.service.ts +++ b/src/app/services/register/register.service.ts @@ -77,13 +77,19 @@ export class RegisterService { name, handle, points, - level, + level { + name + levelNumber + }, receivedRequests{id, sender{name, handle, id}}, sentRequests{receiver{id}} friends { id, name, - level, + level { + name + levelNumber + }, profilePicture }, groups{id}, diff --git a/src/app/services/search/search.service.ts b/src/app/services/search/search.service.ts index 690dadb..f88facf 100644 --- a/src/app/services/search/search.service.ts +++ b/src/app/services/search/search.service.ts @@ -23,7 +23,10 @@ const graphqlQuery = `query($query: String!, $first: Int, $offset: Int) { id, handle, points, - level, + level { + name + levelNumber + }, friends { id } @@ -77,7 +80,10 @@ export class SearchService extends BaseService { user.userID = foundUser.id; user.handle = foundUser.handle; user.points = foundUser.points; - user.level = foundUser.level; + if (foundUser.level) { + user.level = foundUser.level.levelNumber; + user.levelName = foundUser.level.name; + } // @ts-ignore user.friends = foundUser.friends; users.push(user); diff --git a/src/app/services/selfservice/self.service.ts b/src/app/services/selfservice/self.service.ts index 7c22071..3b356fb 100644 --- a/src/app/services/selfservice/self.service.ts +++ b/src/app/services/selfservice/self.service.ts @@ -14,14 +14,20 @@ const getSelfGraphqlQuery = `{ email, handle, points, - level, + level { + name + levelNumber + }, profilePicture, receivedRequests{id, sender{name, handle, id}}, sentRequests{receiver{id}}, friends { id, name, - level, + level { + name + levelNumber + }, profilePicture, }, groups {