From 8910583aa3440dc3524c4ff4c314f1b547dc3a86 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Tue, 7 Nov 2023 09:17:34 +0100 Subject: [PATCH] Migrated the User.ts model --- models/User.ts | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/models/User.ts b/models/User.ts index 0b9df6c..86cf1c2 100644 --- a/models/User.ts +++ b/models/User.ts @@ -1,4 +1,5 @@ -import mongoose, {Schema} from 'mongoose'; +import {sequelize} from "../app"; +import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize"; export enum Rank { USER = "user", @@ -6,51 +7,51 @@ export enum Rank { ADMIN = "admin" } -export interface IUser { +export interface IUser extends Model, InferCreationAttributes> { clientId: number username: string - locale: string - rank: Rank - avatarId: string + locale?: string + rank?: Rank + avatarId?: string accessToken: string refreshToken: string - created: Date + created?: Date } -const UserSchema = new Schema({ +const UserSchema = sequelize.define('users', { clientId: { - type: Number, - required: true + type: DataTypes.BIGINT, + allowNull: false, + primaryKey: true }, username: { - type: String, - default: "User#0001" + type: DataTypes.STRING, + defaultValue: "User#0001" }, locale: { - type: String, - default: "en" + type: DataTypes.STRING, + defaultValue: "en" }, rank: { - type: String, - enum: Rank, - default: Rank.USER + type: DataTypes.STRING, + defaultValue: Rank.USER }, avatarId: { - type: String, - default: "590962a0d694945a779054cd078a7efd" + type: DataTypes.STRING, + defaultValue: "590962a0d694945a779054cd078a7efd" }, accessToken: { - type: String, - required: true + type: DataTypes.STRING, + allowNull: false }, refreshToken: { - type: String, - required: true + type: DataTypes.STRING, + allowNull: false }, created: { - type: Date, - default: Date.now + type: DataTypes.DATE, + defaultValue: Date.now } }); -export const User = mongoose.model('users', UserSchema); \ No newline at end of file +export const User = UserSchema; \ No newline at end of file