Преглед изворни кода

refactor: Adds most remaining user attributes

Playlist and Station integration not yet added
Owen Diffey пре 2 месеци
родитељ
комит
f843136d3d

+ 93 - 5
backend/src/modules/DataModule/migrations/1725485641-create-users-table.ts

@@ -9,22 +9,110 @@ export const up = async ({
 			// eslint-disable-next-line
 			// @ts-ignore
 			type: DataTypes.OBJECTID,
-			primaryKey: true,
-			allowNull: false
+			autoNull: false,
+			primaryKey: true
 		},
-		username: {
+		name: {
 			type: DataTypes.STRING,
 			allowNull: false
 		},
-		name: {
+		username: {
 			type: DataTypes.STRING,
 			allowNull: false
 		},
 		role: {
 			type: DataTypes.ENUM("admin", "moderator", "user"),
-			defaultValue: "user",
 			allowNull: false
 		},
+		emailAddress: {
+			type: DataTypes.STRING,
+			allowNull: false
+		},
+		emailVerifiedAt: {
+			type: DataTypes.DATE,
+			allowNull: true
+		},
+		emailVerificationToken: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		avatarType: {
+			type: DataTypes.ENUM("gravatar", "initials"),
+			allowNull: false
+		},
+		avatarColor: {
+			type: DataTypes.ENUM(
+				"blue",
+				"green",
+				"orange",
+				"purple",
+				"red",
+				"teal"
+			),
+			allowNull: true
+		},
+		avatarUrl: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		password: {
+			type: DataTypes.STRING,
+			allowNull: false
+		},
+		passwordResetToken: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		passwordResetExpiresAt: {
+			type: DataTypes.DATE,
+			allowNull: true
+		},
+		githubId: {
+			type: DataTypes.BIGINT,
+			allowNull: true
+		},
+		githubAccessToken: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		songsRequested: {
+			type: DataTypes.BIGINT,
+			allowNull: false,
+			defaultValue: 0
+		},
+		location: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		bio: {
+			type: DataTypes.STRING,
+			allowNull: true
+		},
+		nightmode: {
+			type: DataTypes.BOOLEAN,
+			allowNull: false,
+			defaultValue: false
+		},
+		autoSkipDisliked: {
+			type: DataTypes.BOOLEAN,
+			allowNull: false,
+			defaultValue: true
+		},
+		activityLogPublic: {
+			type: DataTypes.BOOLEAN,
+			allowNull: false,
+			defaultValue: false
+		},
+		anonymousSongRequests: {
+			type: DataTypes.BOOLEAN,
+			allowNull: false,
+			defaultValue: false
+		},
+		activityWatch: {
+			type: DataTypes.BOOLEAN,
+			allowNull: false,
+			defaultValue: false
+		},
 		createdAt: DataTypes.DATE,
 		updatedAt: DataTypes.DATE
 	});

+ 138 - 9
backend/src/modules/DataModule/models/User.ts

@@ -18,9 +18,11 @@ import {
 	Association
 } from "sequelize";
 import { UserRole } from "./User/UserRole";
-import { ObjectIdType } from "@/modules/DataModule";
-import Session from "./Session";
+import { UserAvatarColor } from "./User/UserAvatarColor";
+import { UserAvatarType } from "./User/UserAvatarType";
 import News from "./News";
+import Session from "./Session";
+import { ObjectIdType } from "@/modules/DataModule";
 
 export class User extends Model<
 	// eslint-disable-next-line no-use-before-define
@@ -30,11 +32,57 @@ export class User extends Model<
 > {
 	declare _id: CreationOptional<ObjectIdType>;
 
+	declare name: string;
+
 	declare username: string;
 
-	declare name: string;
+	declare role: UserRole;
+
+	declare emailAddress: string;
+
+	declare emailVerifiedAt: CreationOptional<Date | null>;
+
+	declare emailVerificationToken: CreationOptional<string | null>;
+
+	declare avatarType: UserAvatarType;
+
+	declare avatarColor: CreationOptional<UserAvatarColor | null>;
+
+	declare avatarUrl: CreationOptional<string | null>;
+
+	declare password: string;
+
+	declare passwordResetToken: CreationOptional<string | null>;
+
+	declare passwordResetExpiresAt: CreationOptional<Date | null>;
 
-	declare role: CreationOptional<UserRole>;
+	declare githubId: CreationOptional<number | null>;
+
+	declare githubAccessToken: CreationOptional<string | null>;
+
+	declare songsRequested: CreationOptional<number>;
+
+	// declare likedSongsPlaylist: Types.ObjectId;
+
+	// declare dislikedSongsPlaylist: Types.ObjectId;
+
+	// declare favoriteStations: Types.ObjectId[];
+
+	declare location: CreationOptional<string | null>;
+
+	declare bio: CreationOptional<string | null>;
+
+	// declare orderOfPlaylists: Types.ObjectId[];
+
+	declare nightmode: CreationOptional<boolean>;
+
+	declare autoSkipDisliked: CreationOptional<boolean>;
+
+	declare activityLogPublic: CreationOptional<boolean>;
+
+	declare anonymousSongRequests: CreationOptional<boolean>;
+
+	declare activityWatch: CreationOptional<boolean>;
 
 	declare createdAt: CreationOptional<Date>;
 
@@ -107,22 +155,103 @@ export class User extends Model<
 export const schema = {
 	_id: {
 		type: DataTypes.OBJECTID,
-		primaryKey: true,
-		allowNull: false
+		autoNull: false,
+		primaryKey: true
 	},
-	username: {
+	name: {
 		type: DataTypes.STRING,
 		allowNull: false
 	},
-	name: {
+	username: {
 		type: DataTypes.STRING,
 		allowNull: false
 	},
 	role: {
 		type: DataTypes.ENUM(...Object.values(UserRole)),
-		defaultValue: UserRole.USER,
 		allowNull: false
 	},
+	emailAddress: {
+		type: DataTypes.STRING,
+		allowNull: false
+	},
+	emailVerifiedAt: {
+		type: DataTypes.DATE,
+		allowNull: true
+	},
+	emailVerificationToken: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	avatarType: {
+		type: DataTypes.ENUM(...Object.values(UserAvatarType)),
+		allowNull: false
+	},
+	avatarColor: {
+		type: DataTypes.ENUM(...Object.values(UserAvatarColor)),
+		allowNull: true
+	},
+	avatarUrl: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	password: {
+		type: DataTypes.STRING,
+		allowNull: false
+	},
+	passwordResetToken: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	passwordResetExpiresAt: {
+		type: DataTypes.DATE,
+		allowNull: true
+	},
+	githubId: {
+		type: DataTypes.BIGINT,
+		allowNull: true
+	},
+	githubAccessToken: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	songsRequested: {
+		type: DataTypes.BIGINT,
+		allowNull: false,
+		defaultValue: 0
+	},
+	location: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	bio: {
+		type: DataTypes.STRING,
+		allowNull: true
+	},
+	nightmode: {
+		type: DataTypes.BOOLEAN,
+		allowNull: false,
+		defaultValue: false
+	},
+	autoSkipDisliked: {
+		type: DataTypes.BOOLEAN,
+		allowNull: false,
+		defaultValue: true
+	},
+	activityLogPublic: {
+		type: DataTypes.BOOLEAN,
+		allowNull: false,
+		defaultValue: false
+	},
+	anonymousSongRequests: {
+		type: DataTypes.BOOLEAN,
+		allowNull: false,
+		defaultValue: false
+	},
+	activityWatch: {
+		type: DataTypes.BOOLEAN,
+		allowNull: false,
+		defaultValue: false
+	},
 	createdAt: DataTypes.DATE,
 	updatedAt: DataTypes.DATE,
 	_name: {