add new tables
This commit is contained in:
parent
8ebd9b78ec
commit
956435ba40
@ -54,11 +54,13 @@ module.exports = async function (sequelize, dbObj) {
|
||||
unique: false,
|
||||
comment: "Hash code of password",
|
||||
set: function (value) {
|
||||
if (value === "") return this.setDataValue('password', "");
|
||||
const hash = bcrypt.hashSync(value, getSalt());
|
||||
this.setDataValue('password', hash);
|
||||
},
|
||||
get: function () {
|
||||
const checkHash = this.getDataValue("password");
|
||||
if (checkHash === "") return Promise.resolve(false);
|
||||
return async function (password) {
|
||||
return await new Promise((rs, rj) => {
|
||||
bcrypt.compare(password, checkHash, (err, res) => {
|
||||
@ -87,16 +89,124 @@ module.exports = async function (sequelize, dbObj) {
|
||||
primaryKey: true,
|
||||
comment: "ID of character",
|
||||
},
|
||||
ownerId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: "ID of character's owner",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: "Name of character",
|
||||
},
|
||||
ownerId: {
|
||||
nameMasked: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: false,
|
||||
comment: "Masked name of character",
|
||||
},
|
||||
avatar: {
|
||||
type: DataTypes.BLOB,
|
||||
allowNull: true,
|
||||
comment: "Avatar of character",
|
||||
},
|
||||
avatarMime: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: "Mimetype of character's avatar",
|
||||
},
|
||||
descriptionPrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Description of character",
|
||||
},
|
||||
appearancePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Appearance of character",
|
||||
},
|
||||
naturePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Nature of character",
|
||||
},
|
||||
prehistoryPrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Pre-history of character",
|
||||
},
|
||||
communicationStylePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Communication style of character",
|
||||
},
|
||||
}),
|
||||
|
||||
npcCharacters: sequelize.define("npcCharacters", {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
comment: "ID of character's owner",
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
comment: "ID of character",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
comment: "Name of character",
|
||||
},
|
||||
nameMasked: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: false,
|
||||
comment: "Masked name of character",
|
||||
},
|
||||
avatar: {
|
||||
type: DataTypes.BLOB,
|
||||
allowNull: true,
|
||||
comment: "Avatar of character",
|
||||
},
|
||||
avatarMime: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: "Mimetype of character's avatar",
|
||||
},
|
||||
descriptionPrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Description of character",
|
||||
},
|
||||
appearancePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Appearance of character",
|
||||
},
|
||||
naturePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Nature of character",
|
||||
},
|
||||
prehistoryPrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Pre-history of character",
|
||||
},
|
||||
communicationStylePrompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
defaultValue: "",
|
||||
comment: "Communication style of character",
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
@ -59,6 +59,62 @@ class DatabaseCache {
|
||||
this.users.byId[addedData.id] = addedData;
|
||||
}
|
||||
}
|
||||
|
||||
async userCharacters (rows, table) {
|
||||
this.userCharacters.rows = rows;
|
||||
|
||||
// Add new character at cache
|
||||
this.userCharacters.add = async (row, isCreate = false) => {
|
||||
if (isCreate)
|
||||
await table.create(row);
|
||||
|
||||
let addedData = null;
|
||||
if (row.name)
|
||||
addedData = await table.findAll({
|
||||
where: {
|
||||
name: row.name
|
||||
}
|
||||
})[0];
|
||||
else if (row.id)
|
||||
addedData = await table.findAll({
|
||||
where: {
|
||||
id: row.id
|
||||
}
|
||||
})[0];
|
||||
|
||||
if (!addedData) throw new Error("Invalid row information");
|
||||
this.userCharacters.rows.push(addedData);
|
||||
// By keys
|
||||
}
|
||||
}
|
||||
|
||||
async npcCharacters (rows, table) {
|
||||
this.npcCharacters.rows = rows;
|
||||
|
||||
// Add new character at cache
|
||||
this.npcCharacters.add = async (row, isCreate = false) => {
|
||||
if (isCreate)
|
||||
await table.create(row);
|
||||
|
||||
let addedData = null;
|
||||
if (row.name)
|
||||
addedData = await table.findAll({
|
||||
where: {
|
||||
name: row.name
|
||||
}
|
||||
})[0];
|
||||
else if (row.id)
|
||||
addedData = await table.findAll({
|
||||
where: {
|
||||
id: row.id
|
||||
}
|
||||
})[0];
|
||||
|
||||
if (!addedData) throw new Error("Invalid row information");
|
||||
this.npcCharacters.rows.push(addedData);
|
||||
// By keys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Database {
|
||||
|
Loading…
Reference in New Issue
Block a user