mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-22 03:20:10 +00:00
Fix categories type
This commit is contained in:
@@ -86,6 +86,7 @@ nixpkgs.lib.recursiveUpdate (
|
||||
name = "Spacebar.Models.Api";
|
||||
projectFile = "Spacebar.Models.Api.csproj";
|
||||
srcRoot = Models/Spacebar.Models.Api;
|
||||
projectReferences = [ proj.Spacebar-Models-Generic ];
|
||||
};
|
||||
Spacebar-Models-AdminApi = buildSpacebarDotnetModule {
|
||||
name = "Spacebar.Models.AdminApi";
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { BaseClassWithoutId } from "./BaseClass";
|
||||
import { DiscoveryCategory } from "@spacebar/schemas";
|
||||
|
||||
// TODO: categories:
|
||||
// was this an old response format? Keeping for completeness sake
|
||||
// [{
|
||||
// "id": 16,
|
||||
// "default": "Anime & Manga",
|
||||
@@ -31,7 +32,6 @@ import { BaseClassWithoutId } from "./BaseClass";
|
||||
// },
|
||||
// "is_primary": false/true
|
||||
// }]
|
||||
// Also populate discord default categories
|
||||
|
||||
@Entity({
|
||||
name: "categories",
|
||||
@@ -39,19 +39,34 @@ import { BaseClassWithoutId } from "./BaseClass";
|
||||
export class Categories extends BaseClassWithoutId {
|
||||
// Not using snowflake
|
||||
|
||||
@PrimaryColumn({ type: "int4" })
|
||||
@PrimaryGeneratedColumn({ type: "int2" })
|
||||
id: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
name: string;
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
localizations: string;
|
||||
localizations: CategoryLocalization;
|
||||
|
||||
// Whether to show the category prominently (e.g. in a sidebar) instead of only secondary (e.g. in search results)
|
||||
@Column({ nullable: true })
|
||||
is_primary: boolean;
|
||||
|
||||
// TODO: was this removed?
|
||||
@Column({ nullable: true })
|
||||
icon?: string;
|
||||
|
||||
public toDiscoveryCategory(locale?: string): DiscoveryCategory {
|
||||
locale ??= "en-US";
|
||||
let name = this.name;
|
||||
if (locale in this.localizations) name = this.localizations[locale] ?? this.name;
|
||||
|
||||
return {
|
||||
id: this.id,
|
||||
name: name,
|
||||
is_primary: this.is_primary,
|
||||
} satisfies DiscoveryCategory;
|
||||
}
|
||||
}
|
||||
|
||||
export type CategoryLocalization = { [locale: string]: string };
|
||||
|
||||
@@ -106,8 +106,8 @@ export class Guild extends BaseClass {
|
||||
features: string[] = []; //TODO use enum
|
||||
//TODO: https://discord.com/developers/docs/resources/guild#guild-object-guild-features
|
||||
|
||||
@Column({ type: "int8", nullable: true })
|
||||
primary_category_id?: string; // TODO: this was number?
|
||||
@Column({ type: "int2", nullable: true })
|
||||
primary_category_id?: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
icon?: string;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Int2CategoryId1786139482251 implements MigrationInterface {
|
||||
name = "Int2CategoryId1786139482251";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE guilds ALTER COLUMN primary_category_id TYPE int2 USING primary_category_id::int2`);
|
||||
await queryRunner.query(`ALTER TABLE categories ALTER COLUMN id TYPE smallserial USING id::smallserial`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE guilds ALTER COLUMN primary_category_id TYPE bigint USING primary_category_id::bigint`);
|
||||
await queryRunner.query(`ALTER TABLE categories ALTER COLUMN id TYPE bigint USING id::bigint`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user