This commit is contained in:
parent
06eb7dbbb1
commit
789d5d6410
3 changed files with 61 additions and 0 deletions
|
@ -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`);
|
35
src/database/entities/UserSetting.ts
Normal file
35
src/database/entities/UserSetting.ts
Normal file
|
@ -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<UserSetting | null> {
|
||||||
|
const repository = AppDataSource.getRepository(UserSetting);
|
||||||
|
|
||||||
|
const single = await repository.findOne({ where: { UserId: userId, Key: key }, relations: relations || {} });
|
||||||
|
|
||||||
|
return single;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<void> {
|
||||||
|
MigrationHelper.Up('1727286976268-CreateUserSetting', '3.3.0', [
|
||||||
|
"01-UserSetting",
|
||||||
|
], queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue