Changed controllers to classes, added image functionality
This commit is contained in:
@@ -10,6 +10,8 @@ import InterestTranslationType from './type/interest_translation.js';
|
||||
import Interest from './community/interest.js';
|
||||
import UserParamVisibilityType from './type/user_param_visibility.js';
|
||||
import UserParamVisibility from './community/user_param_visibility.js';
|
||||
import Folder from './community/folder.js';
|
||||
import Image from './community/image.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
SettingsType.hasMany(UserParamType, { foreignKey: 'settingsId', as: 'user_param_types' });
|
||||
@@ -43,4 +45,16 @@ export default function setupAssociations() {
|
||||
|
||||
UserParamVisibility.belongsTo(UserParamVisibilityType, { foreignKey: 'visibility', as: 'visibility_type' });
|
||||
UserParamVisibilityType.hasMany(UserParamVisibility, { foreignKey: 'visibility', as: 'user_param_visibilities' });
|
||||
|
||||
Folder.belongsTo(User, { foreignKey: 'userId' });
|
||||
User.hasMany(Folder, { foreignKey: 'userId' });
|
||||
|
||||
Folder.belongsTo(Folder, { foreignKey: 'parentId', as: 'parent' });
|
||||
Folder.hasMany(Folder, { foreignKey: 'parentId', as: 'children' });
|
||||
|
||||
Image.belongsTo(Folder, { foreignKey: 'folderId' });
|
||||
Folder.hasMany(Image, { foreignKey: 'folderId' });
|
||||
|
||||
Image.belongsTo(User, { foreignKey: 'userId' });
|
||||
User.hasMany(Image, { foreignKey: 'userId' });
|
||||
}
|
||||
|
||||
41
backend/models/community/folder.js
Normal file
41
backend/models/community/folder.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import UserParamVisibilityType from '../type/user_param_visibility.js';
|
||||
|
||||
const Folder = sequelize.define('folder', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
parentId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'folder',
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'user',
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
visibilityType: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: UserParamVisibilityType,
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
}, {
|
||||
tableName: 'folder',
|
||||
schema: 'community',
|
||||
underscored: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
export default Folder;
|
||||
54
backend/models/community/image.js
Normal file
54
backend/models/community/image.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import UserParamVisibilityType from '../type/user_param_visibility.js';
|
||||
|
||||
const Image = sequelize.define('image', {
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
originalFileName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
hash: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
folderId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'folder',
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'user',
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
visibilityType: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: UserParamVisibilityType,
|
||||
key: 'id',
|
||||
},
|
||||
},
|
||||
}, {
|
||||
tableName: 'image',
|
||||
schema: 'community',
|
||||
underscored: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
export default Image;
|
||||
@@ -12,6 +12,8 @@ import Interest from './community/interest.js';
|
||||
import ContactMessage from './service/contactmessage.js';
|
||||
import UserParamVisibilityType from './type/user_param_visibility.js';
|
||||
import UserParamVisibility from './community/user_param_visibility.js';
|
||||
import Folder from './community/folder.js';
|
||||
import Image from './community/image.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
@@ -28,6 +30,8 @@ const models = {
|
||||
ContactMessage,
|
||||
UserParamVisibilityType,
|
||||
UserParamVisibility,
|
||||
Folder,
|
||||
Image,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
Reference in New Issue
Block a user