WIP: Add UserSetting entity
All checks were successful
Test / build (push) Successful in 6s

This commit is contained in:
Ethan Lane 2024-09-25 19:03:16 +01:00
parent 06eb7dbbb1
commit 789d5d6410
3 changed files with 61 additions and 0 deletions

View file

@ -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`);

View 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;
}
}

View file

@ -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> {
}
}