diff --git a/database/3.3.0/1727286976268-CreateUserSetting/Up/01-UserSetting.sql b/database/3.3.0/1727286976268-CreateUserSetting/Up/01-UserSetting.sql new file mode 100644 index 0000000..1c645c0 --- /dev/null +++ b/database/3.3.0/1727286976268-CreateUserSetting/Up/01-UserSetting.sql @@ -0,0 +1,11 @@ +CREATE TABLE `user_setting` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL, + `UserId` varchar(255) NOT NULL, + `Key` varchar(255) NOT NULL, + `Value` varchar(255) NOT NULL, +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +ALTER TABLE `user_setting` + ADD PRIMARY KEY (`Id`); diff --git a/src/database/entities/UserSetting.ts b/src/database/entities/UserSetting.ts new file mode 100644 index 0000000..e5f9ce4 --- /dev/null +++ b/src/database/entities/UserSetting.ts @@ -0,0 +1,35 @@ +import { Column, Entity} from "typeorm"; +import AppDataSource from "../dataSources/appDataSource"; +import BaseEntity from "../../contracts/BaseEntity"; + +@Entity() +export default class UserSetting extends BaseEntity { + constructor(userId: string, key: string, value: string) { + super(); + + this.UserId = userId; + this.Key = key; + this.Value = value; + } + + @Column() + UserId: string; + + @Column() + Key: string; + + @Column() + Value: string; + + public UpdateValue(value: string) { + this.Value = value; + } + + public static async FetchOneByKey(userId: string, key: string, relations?: string[]): Promise { + const repository = AppDataSource.getRepository(UserSetting); + + const single = await repository.findOne({ where: { UserId: userId, Key: key }, relations: relations || {} }); + + return single; + } +} diff --git a/src/database/migrations/3.3/1727286976268-CreateUserSetting.ts b/src/database/migrations/3.3/1727286976268-CreateUserSetting.ts new file mode 100644 index 0000000..81e09b9 --- /dev/null +++ b/src/database/migrations/3.3/1727286976268-CreateUserSetting.ts @@ -0,0 +1,15 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; +import MigrationHelper from "../../../helpers/MigrationHelper"; + +export class CreateUserSetting1727286976268 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + MigrationHelper.Up('1727286976268-CreateUserSetting', '3.3.0', [ + "01-UserSetting", + ], queryRunner); + } + + public async down(queryRunner: QueryRunner): Promise { + } + +}