summary refs log tree commit diff
diff options
context:
space:
mode:
authorIratu <me@iratu.pro>2022-02-16 21:23:50 +0000
committerErkin Alp Güney <erkinalp9035@gmail.com>2022-02-18 19:50:11 +0300
commit63fe1ef3b2d082d49ea1397629601e4f019a7801 (patch)
treed84f6e843147c7034fa742c68b7e950f54accdc7
parentMerge pull request #608 from Featyre/master (diff)
downloadserver-63fe1ef3b2d082d49ea1397629601e4f019a7801.tar.xz
Fix for Premium Since to show the 'Guild Boost' and store it correctly in the database
-rw-r--r--api/src/routes/users/#id/profile.ts14
-rw-r--r--util/src/entities/Member.ts4
2 files changed, 13 insertions, 5 deletions
diff --git a/api/src/routes/users/#id/profile.ts b/api/src/routes/users/#id/profile.ts
index 9481451d..06be66ae 100644
--- a/api/src/routes/users/#id/profile.ts
+++ b/api/src/routes/users/#id/profile.ts
@@ -16,21 +16,29 @@ router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }),
 	const user = await User.getPublicUser(req.params.id, { relations: ["connected_accounts"] });
 
 	var mutual_guilds: object[] = [];
-
+	var premium_guild_since;
 	const requested_member = await Member.find( { id: req.params.id,  })
 	const self_member = await Member.find( { id: req.user_id,  })
 
 	for(const rmem of requested_member) {
+		if(rmem.premium_since) {
+			if(premium_guild_since){
+				if(premium_guild_since > rmem.premium_since) {
+					premium_guild_since = rmem.premium_since;
+				}
+			} else {
+				premium_guild_since = rmem.premium_since;
+			}
+		}
 		for(const smem of self_member) {
 			if (smem.guild_id === rmem.guild_id) {
 				mutual_guilds.push({id: rmem.guild_id, nick: rmem.nick})
 			}
 		}
 	}
-
 	res.json({
 		connected_accounts: user.connected_accounts,
-		premium_guild_since: null, // TODO
+		premium_guild_since: premium_guild_since, // TODO
 		premium_since: null, // TODO
 		mutual_guilds: mutual_guilds, // TODO {id: "", nick: null} when ?with_mutual_guilds=true
 		user: {
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts
index 0f7be2a7..3c5f9db0 100644
--- a/util/src/entities/Member.ts
+++ b/util/src/entities/Member.ts
@@ -86,7 +86,7 @@ export class Member extends BaseClassWithoutId {
 	joined_at: Date;
 
 	@Column({ nullable: true })
-	premium_since?: number;
+	premium_since?: Date;
 
 	@Column()
 	deaf: boolean;
@@ -245,7 +245,7 @@ export class Member extends BaseClassWithoutId {
 			nick: undefined,
 			roles: [guild_id], // @everyone role
 			joined_at: new Date(),
-			premium_since: undefined,
+			premium_since: new Date(),
 			deaf: false,
 			mute: false,
 			pending: false,