mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 10:22:39 +01:00
feat: badges
This commit is contained in:
parent
2f679fda5d
commit
01ca7b7736
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
|
Badge,
|
||||||
Member,
|
Member,
|
||||||
PrivateUserProjection,
|
PrivateUserProjection,
|
||||||
User,
|
User,
|
||||||
@ -98,6 +99,9 @@ router.get(
|
|||||||
bio: guild_member?.bio || "",
|
bio: guild_member?.bio || "",
|
||||||
guild_id,
|
guild_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const badges = await Badge.find();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
connected_accounts: user.connected_accounts.filter(
|
connected_accounts: user.connected_accounts.filter(
|
||||||
(x) => x.visibility != 0,
|
(x) => x.visibility != 0,
|
||||||
@ -111,6 +115,7 @@ router.get(
|
|||||||
user_profile: userProfile,
|
user_profile: userProfile,
|
||||||
guild_member: guild_member?.toPublicMember(),
|
guild_member: guild_member?.toPublicMember(),
|
||||||
guild_member_profile: guild_id && guildMemberProfile,
|
guild_member_profile: guild_id && guildMemberProfile,
|
||||||
|
badges: badges.filter((x) => user.badge_ids?.includes(x.id)),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -24,6 +24,7 @@ export class MinimalPublicUserDTO {
|
|||||||
id: string;
|
id: string;
|
||||||
public_flags: number;
|
public_flags: number;
|
||||||
username: string;
|
username: string;
|
||||||
|
badge_ids?: string[] | null;
|
||||||
|
|
||||||
constructor(user: User) {
|
constructor(user: User) {
|
||||||
this.avatar = user.avatar;
|
this.avatar = user.avatar;
|
||||||
@ -31,5 +32,6 @@ export class MinimalPublicUserDTO {
|
|||||||
this.id = user.id;
|
this.id = user.id;
|
||||||
this.public_flags = user.public_flags;
|
this.public_flags = user.public_flags;
|
||||||
this.username = user.username;
|
this.username = user.username;
|
||||||
|
this.badge_ids = user.badge_ids;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
src/util/entities/Badge.ts
Normal file
35
src/util/entities/Badge.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
|
||||||
|
Copyright (C) 2023 Spacebar and Spacebar Contributors
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Column, Entity } from "typeorm";
|
||||||
|
import { BaseClassWithoutId } from "./BaseClass";
|
||||||
|
|
||||||
|
@Entity("badges")
|
||||||
|
export class Badge extends BaseClassWithoutId {
|
||||||
|
@Column({ primary: true })
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
icon: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
link?: string;
|
||||||
|
}
|
@ -49,6 +49,7 @@ export enum PublicUserEnum {
|
|||||||
premium_type,
|
premium_type,
|
||||||
theme_colors,
|
theme_colors,
|
||||||
pronouns,
|
pronouns,
|
||||||
|
badge_ids,
|
||||||
}
|
}
|
||||||
export type PublicUserKeys = keyof typeof PublicUserEnum;
|
export type PublicUserKeys = keyof typeof PublicUserEnum;
|
||||||
|
|
||||||
@ -231,6 +232,9 @@ export class User extends BaseClass {
|
|||||||
@OneToMany(() => SecurityKey, (key: SecurityKey) => key.user)
|
@OneToMany(() => SecurityKey, (key: SecurityKey) => key.user)
|
||||||
security_keys: SecurityKey[];
|
security_keys: SecurityKey[];
|
||||||
|
|
||||||
|
@Column({ type: "simple-array", nullable: true })
|
||||||
|
badge_ids?: string[];
|
||||||
|
|
||||||
// TODO: I don't like this method?
|
// TODO: I don't like this method?
|
||||||
validate() {
|
validate() {
|
||||||
if (this.discriminator) {
|
if (this.discriminator) {
|
||||||
|
@ -20,6 +20,7 @@ export * from "./Application";
|
|||||||
export * from "./Attachment";
|
export * from "./Attachment";
|
||||||
export * from "./AuditLog";
|
export * from "./AuditLog";
|
||||||
export * from "./BackupCodes";
|
export * from "./BackupCodes";
|
||||||
|
export * from "./Badge";
|
||||||
export * from "./Ban";
|
export * from "./Ban";
|
||||||
export * from "./BaseClass";
|
export * from "./BaseClass";
|
||||||
export * from "./Categories";
|
export * from "./Categories";
|
||||||
|
21
src/util/migration/mariadb/1720628601997-badges.ts
Normal file
21
src/util/migration/mariadb/1720628601997-badges.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class Badges1720628601997 implements MigrationInterface {
|
||||||
|
name = "Badges1720628601997";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE \`badges\` (\`id\` varchar(255) NOT NULL, \`description\` varchar(255) NOT NULL, \`icon\` varchar(255) NOT NULL, \`link\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`users\` ADD \`badge_ids\` text NULL`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`users\` DROP COLUMN \`badge_ids\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE \`badges\``);
|
||||||
|
}
|
||||||
|
}
|
21
src/util/migration/mysql/1720628601997-badges.ts
Normal file
21
src/util/migration/mysql/1720628601997-badges.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class Badges1720628601997 implements MigrationInterface {
|
||||||
|
name = "Badges1720628601997";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE \`badges\` (\`id\` varchar(255) NOT NULL, \`description\` varchar(255) NOT NULL, \`icon\` varchar(255) NOT NULL, \`link\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`users\` ADD \`badge_ids\` text NULL`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE \`users\` DROP COLUMN \`badge_ids\``,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TABLE \`badges\``);
|
||||||
|
}
|
||||||
|
}
|
16
src/util/migration/postgres/1720628601997-badges.ts
Normal file
16
src/util/migration/postgres/1720628601997-badges.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class Badges1720628601997 implements MigrationInterface {
|
||||||
|
name = "Badges1720628601997";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "badges" ("id" character varying NOT NULL, "description" character varying NOT NULL, "icon" character varying NOT NULL, "link" character varying, CONSTRAINT "PK_8a651318b8de577e8e217676466" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`ALTER TABLE "users" ADD "badge_ids" text`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "badge_ids"`);
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
Badge,
|
||||||
Member,
|
Member,
|
||||||
PublicConnectedAccount,
|
PublicConnectedAccount,
|
||||||
PublicMember,
|
PublicMember,
|
||||||
@ -52,4 +53,5 @@ export interface UserProfileResponse {
|
|||||||
user_profile: UserProfile;
|
user_profile: UserProfile;
|
||||||
guild_member?: PublicMember;
|
guild_member?: PublicMember;
|
||||||
guild_member_profile?: PublicMemberProfile;
|
guild_member_profile?: PublicMemberProfile;
|
||||||
|
badges: Badge[];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user