websockets implemented
This commit is contained in:
@@ -28,6 +28,9 @@ import ForumPermission from './forum/forum_permission.js';
|
||||
import ForumUserPermission from './forum/forum_user_permission.js';
|
||||
import ForumForumPermission from './forum/forum_forum_permission.js';
|
||||
import Friendship from './community/friendship.js';
|
||||
import FalukantUser from './falukant/data/user.js';
|
||||
import RegionType from './falukant/type/region.js';
|
||||
import RegionData from './falukant/data/region.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
// UserParam related associations
|
||||
@@ -40,12 +43,13 @@ export default function setupAssociations() {
|
||||
User.hasMany(UserParam, { foreignKey: 'userId', as: 'user_params' });
|
||||
UserParam.belongsTo(User, { foreignKey: 'userId', as: 'user' });
|
||||
|
||||
// UserRight related associations
|
||||
UserParamValue.belongsTo(UserParamType, { foreignKey: 'userParamTypeId', as: 'user_param_value_type' });
|
||||
UserParamType.hasMany(UserParamValue, { foreignKey: 'userParamTypeId', as: 'user_param_type_value' });
|
||||
|
||||
UserRight.belongsTo(User, { foreignKey: 'userId', as: 'user_with_rights' });
|
||||
UserRight.belongsTo(UserRightType, { foreignKey: 'rightTypeId', as: 'rightType' });
|
||||
UserRightType.hasMany(UserRight, { foreignKey: 'rightTypeId', as: 'user_rights' });
|
||||
|
||||
// UserParamVisibility related associations
|
||||
UserParam.hasMany(UserParamVisibility, { foreignKey: 'param_id', as: 'param_visibilities' });
|
||||
UserParamVisibility.belongsTo(UserParam, { foreignKey: 'param_id', as: 'param' });
|
||||
|
||||
@@ -162,4 +166,19 @@ export default function setupAssociations() {
|
||||
Friendship.belongsTo(User, { foreignKey: 'user2Id', as: 'friendReceiver' });
|
||||
User.hasMany(Friendship, { foreignKey: 'user1Id', as: 'friendSender' });
|
||||
User.hasMany(Friendship, { foreignKey: 'user2Id', as: 'friendReceiver' });
|
||||
|
||||
User.hasMany(FalukantUser, { foreignKey: 'userId', as: 'falukantData' });
|
||||
FalukantUser.belongsTo(User, { foreignKey: 'userId', as: 'user' });
|
||||
|
||||
RegionType.hasMany(RegionType, { foreignKey: 'parentId', as: 'children' });
|
||||
RegionType.belongsTo(RegionType, { foreignKey: 'parentId', as: 'parent' });
|
||||
|
||||
RegionData.hasMany(RegionData, { foreignKey: 'parentId', as: 'children' });
|
||||
RegionData.belongsTo(RegionData, { foreignKey: 'parentId', as: 'parent' });
|
||||
|
||||
RegionData.belongsTo(RegionType, { foreignKey: 'regionTypeId', as: 'regionType' });
|
||||
RegionType.hasMany(RegionData, { foreignKey: 'regionTypeId', as: 'regions' });
|
||||
|
||||
FalukantUser.belongsTo(RegionData, { foreignKey: 'mainBranchRegionId', as: 'mainBranchRegion' });
|
||||
RegionData.hasMany(FalukantUser, { foreignKey: 'mainBranchRegionId', as: 'users' });
|
||||
}
|
||||
|
||||
@@ -5,14 +5,27 @@ import crypto from 'crypto';
|
||||
|
||||
const User = sequelize.define('user', {
|
||||
email: {
|
||||
type: DataTypes.BLOB,
|
||||
type: DataTypes.BLOB,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
set(value) {
|
||||
if (value) {
|
||||
this.setDataValue('email', Buffer.from(encrypt(value), 'hex'));
|
||||
const encrypted = encrypt(value);
|
||||
this.setDataValue('email', encrypted);
|
||||
}
|
||||
},
|
||||
get() {
|
||||
const encrypted = this.getDataValue('email');
|
||||
if (encrypted) {
|
||||
return decrypt(encrypted);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
salt: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: () => crypto.randomBytes(16).toString('hex')
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
@@ -58,11 +71,6 @@ const User = sequelize.define('user', {
|
||||
user.hashedId = hashedId;
|
||||
await user.save();
|
||||
}
|
||||
},
|
||||
getterMethods: {
|
||||
email() {
|
||||
return decrypt(this.getDataValue('email').toString('hex'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import User from './user.js';
|
||||
import UserParamType from '../type/user_param.js';
|
||||
import { encrypt, decrypt, generateIv } from '../../utils/encryption.js';
|
||||
import { encrypt, decrypt } from '../../utils/encryption.js';
|
||||
|
||||
const UserParam = sequelize.define('user_param', {
|
||||
userId: {
|
||||
@@ -10,45 +10,43 @@ const UserParam = sequelize.define('user_param', {
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: User,
|
||||
key: 'id'
|
||||
}
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
paramTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: UserParamType,
|
||||
key: 'id'
|
||||
}
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
value: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
console.log('.... [set param value]', value);
|
||||
if (value) {
|
||||
try {
|
||||
const iv = generateIv();
|
||||
this.setDataValue('iv', iv.toString('hex'));
|
||||
this.setDataValue('value', encrypt(value.toString(), iv));
|
||||
const encrypted = encrypt(value.toString());
|
||||
console.log('.... [encrypted param value]', encrypted);
|
||||
this.setDataValue('value', encrypted);
|
||||
} catch (error) {
|
||||
this.setDataValue('value', '');
|
||||
console.error('.... Error encrypting param value:', error);
|
||||
this.setDataValue('value', '');
|
||||
}
|
||||
}
|
||||
},
|
||||
get() {
|
||||
try {
|
||||
const value = this.getDataValue('value');
|
||||
const iv = Buffer.from(this.getDataValue('iv'), 'hex');
|
||||
return decrypt(value, iv);
|
||||
const value = this.getDataValue('value');
|
||||
return decrypt(value);
|
||||
} catch (error) {
|
||||
console.error('.... Error decrypting param value:', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
iv: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'user_param',
|
||||
schema: 'community',
|
||||
@@ -56,9 +54,9 @@ const UserParam = sequelize.define('user_param', {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: ['user_id', 'param_type_id']
|
||||
}
|
||||
]
|
||||
fields: ['user_id', 'param_type_id'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default UserParam;
|
||||
|
||||
39
backend/models/falukant/data/region.js
Normal file
39
backend/models/falukant/data/region.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import RegionType from '../type/region.js';
|
||||
|
||||
class RegionData extends Model { }
|
||||
|
||||
RegionData.init({
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
regionTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: RegionType,
|
||||
key: 'id',
|
||||
schema: 'falukant_type'
|
||||
}
|
||||
},
|
||||
parentId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'region',
|
||||
key: 'id',
|
||||
schema: 'falukant_data',
|
||||
}
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'RegionData',
|
||||
tableName: 'region',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default RegionData;
|
||||
57
backend/models/falukant/data/user.js
Normal file
57
backend/models/falukant/data/user.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
import RegionData from './region.js';
|
||||
|
||||
class FalukantUser extends Model { }
|
||||
|
||||
FalukantUser.init({
|
||||
userId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: {
|
||||
tableName: 'user',
|
||||
schema: 'community'
|
||||
},
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
money: {
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
creditAmount: {
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
todayCreditTaken: {
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
creditInterestRate: {
|
||||
type: DataTypes.DECIMAL(5, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
mainBranchRegionId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: RegionData,
|
||||
key: 'id',
|
||||
schema: 'falukant_data'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'FalukantUser',
|
||||
tableName: 'falukant_user',
|
||||
schema: 'falukant_data',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default FalukantUser;
|
||||
29
backend/models/falukant/type/region.js
Normal file
29
backend/models/falukant/type/region.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class RegionType extends Model { }
|
||||
|
||||
RegionType.init({
|
||||
labelTr: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
parentId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'region',
|
||||
key: 'id',
|
||||
schema: 'falukant_type',
|
||||
}
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'RegionType',
|
||||
tableName: 'region',
|
||||
schema: 'falukant_type',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default RegionType;
|
||||
@@ -32,6 +32,9 @@ import MessageHistory from './forum/message_history.js';
|
||||
import MessageImage from './forum/message_image.js';
|
||||
import ForumForumPermission from './forum/forum_forum_permission.js';
|
||||
import Friendship from './community/friendship.js';
|
||||
import FalukantUser from './falukant/data/user.js';
|
||||
import RegionType from './falukant/type/region.js';
|
||||
import RegionData from './falukant/data/region.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
@@ -40,7 +43,7 @@ const models = {
|
||||
UserRightType,
|
||||
User,
|
||||
UserParam,
|
||||
Login,
|
||||
Login,
|
||||
UserRight,
|
||||
InterestType,
|
||||
InterestTranslationType,
|
||||
@@ -68,6 +71,9 @@ const models = {
|
||||
MessageHistory,
|
||||
MessageImage,
|
||||
Friendship,
|
||||
RegionType,
|
||||
RegionData,
|
||||
FalukantUser,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
@@ -3,6 +3,11 @@ import { DataTypes } from 'sequelize';
|
||||
import UserParam from './user_param.js';
|
||||
|
||||
const UserParamValue = sequelize.define('user_param_value', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
userParamTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
|
||||
Reference in New Issue
Block a user