|
|
@ -1,5 +1,6 @@
|
|
|
|
import * as sqz from "sequelize";
|
|
|
|
import * as sqz from "sequelize";
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
|
|
|
|
BeforeCreate,
|
|
|
|
BeforeUpdate,
|
|
|
|
BeforeUpdate,
|
|
|
|
BelongsTo,
|
|
|
|
BelongsTo,
|
|
|
|
BelongsToMany,
|
|
|
|
BelongsToMany,
|
|
|
@ -42,13 +43,16 @@ export class User extends Model<User> {
|
|
|
|
* It assigns the corresponding level to the user
|
|
|
|
* It assigns the corresponding level to the user
|
|
|
|
* @param instance
|
|
|
|
* @param instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@BeforeCreate
|
|
|
|
@BeforeUpdate
|
|
|
|
@BeforeUpdate
|
|
|
|
public static async assignLevel(instance: User) {
|
|
|
|
public static async assignLevel(instance: User) {
|
|
|
|
|
|
|
|
if (instance.changed("rankpoints") || instance.isNewRecord) {
|
|
|
|
const level = await Level.findOne({where: {points: {[sqz.Op.lte]: instance.rankpoints}}, order: [["points", "desc"]]}) as Level;
|
|
|
|
const level = await Level.findOne({where: {points: {[sqz.Op.lte]: instance.rankpoints}}, order: [["points", "desc"]]}) as Level;
|
|
|
|
if (level) {
|
|
|
|
if (level) {
|
|
|
|
instance.$set("rLevel", level);
|
|
|
|
instance.$set("rLevel", level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The name of the user
|
|
|
|
* The name of the user
|
|
|
|