Fix user validator preventing update
This commit is contained in:
parent
ff28c95f2a
commit
add54e6b68
@ -197,8 +197,14 @@ export class User extends BaseClass {
|
||||
extended_settings: string;
|
||||
|
||||
@BeforeUpdate()
|
||||
_update_validator() { this.validate(true); }
|
||||
|
||||
@BeforeInsert()
|
||||
validate() {
|
||||
_insert_validator() { this.validate(false); }
|
||||
|
||||
validate(update: boolean = false) {
|
||||
// inserting or email provided in update
|
||||
if (!update || this.email) {
|
||||
this.email = adjustEmail(this.email);
|
||||
if (!this.email)
|
||||
throw FieldErrors({
|
||||
@ -208,7 +214,10 @@ export class User extends BaseClass {
|
||||
throw FieldErrors({
|
||||
email: { message: "Invalid email", code: "EMAIL_INVALID" },
|
||||
});
|
||||
}
|
||||
|
||||
// inserting or discrim provided
|
||||
if (!update || this.discriminator) {
|
||||
const discrim = Number(this.discriminator);
|
||||
if (this.discriminator.length > 4)
|
||||
throw FieldErrors({
|
||||
@ -232,7 +241,9 @@ export class User extends BaseClass {
|
||||
},
|
||||
});
|
||||
this.discriminator = discrim.toString().padStart(4, "0");
|
||||
}
|
||||
|
||||
if (!update || this.username)
|
||||
if (BannedWords.find(this.username))
|
||||
throw FieldErrors({
|
||||
username: { message: "Bad username", code: "INVALID_USERNAME" },
|
||||
@ -436,7 +447,7 @@ export interface UserSettings {
|
||||
disable_games_tab: boolean;
|
||||
enable_tts_command: boolean;
|
||||
explicit_content_filter: number;
|
||||
friend_source_flags: { all: boolean };
|
||||
friend_source_flags: { all: boolean; };
|
||||
gateway_connected: boolean;
|
||||
gif_auto_play: boolean;
|
||||
// every top guild is displayed as a "folder"
|
||||
|
Loading…
x
Reference in New Issue
Block a user