Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions loaders/dbLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const path = require('path')

const env = config.NODE_ENV
const db_config = config.DB_CONFIG[env] || 'development'
const db = new Sequelize(

let db = {}

let sequelize = new Sequelize(
db_config.database,
db_config.username,
db_config.password,
Expand All @@ -14,4 +17,30 @@ const db = new Sequelize(
}
)

module.exports = db
db.sequelize = sequelize
db.Sequelize = Sequelize

db.User = require('../models/entities/user')(sequelize, Sequelize)
db.Team = require('../models/entities/team')(sequelize, Sequelize)
db.Report = require('../models/entities/report')(sequelize, Sequelize)
db.MatchingLog = require('../models/entities/matchingLog')(sequelize, Sequelize)

db.Team.hasMany(db.User, { foreignKey: 'team', sourceKey: 'id' })
db.User.belongsToMany(db.MatchingLog, {
through: 'warningForMan',
foreignKey: 'manId'
})
db.MatchingLog.belongsToMany(db.User, {
through: 'warningForMan',
foreignKey: 'matchingLogId'
})
db.User.belongsToMany(db.MatchingLog, {
through: 'warningForWoman',
foreignKey: 'womanId'
})
db.MatchingLog.belongsToMany(db.User, {
through: 'warningForWoman',
foreignKey: 'matchingLogId'
})

module.exports = db.sequelize
28 changes: 28 additions & 0 deletions models/entities/matchinglog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define(
'matchingLog',
{
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
womanTeam: {
type: DataTypes.STRING(100),
allowNull: false
},
manTeam: {
type: DataTypes.STRING(100),
allowNull: false
},
matchedAt: {
type: DataTypes.DATE,
allowNull: false
}
},
{
tableName: 'matchingLog'
}
)
}
52 changes: 52 additions & 0 deletions models/entities/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define(
'report',
{
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
type: {
type: DataTypes.STRING(45),
allowNull: false
},
matchingLog: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'matchingLog',
key: 'id'
}
},
target: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'user',
key: 'id'
}
},
author: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'user',
key: 'id'
}
},
content: {
type: DataTypes.STRING(45),
allowNull: false
},
image: {
type: DataTypes.STRING(200),
allowNull: false
}
},
{
tableName: 'report'
}
)
}
69 changes: 69 additions & 0 deletions models/entities/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define(
'team',
{
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
teamCode: {
type: DataTypes.STRING(20),
allowNull: false
},
gender: {
type: DataTypes.STRING(45),
allowNull: false
},
matchedTeam: {
type: DataTypes.INTEGER(11),
allowNull: true,
references: {
model: 'team',
key: 'id'
}
},
memberIds: {
type: DataTypes.STRING(100),
allowNull: false
},
Comment on lines +27 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jiwon-Yang 1:N 릴레이션에서 N에 해당해야 하는 필드입니다. 릴레이션으로 수정해주세요

isMatching: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: '0'
},
teamType: {
type: DataTypes.INTEGER(4),
allowNull: false
},
preferAge: {
type: DataTypes.STRING(20),
allowNull: false
},
preferSmoking: {
type: DataTypes.BOOLEAN,
allowNull: false
},
preferReligion: {
type: DataTypes.STRING(100),
allowNull: false
},
preferBodyType: {
type: DataTypes.STRING(20),
allowNull: false
},
preferHeight: {
type: DataTypes.STRING(10),
allowNull: false
},
excludeMajor: {
type: DataTypes.STRING(100),
allowNull: false
}
},
{
tableName: 'team'
}
)
}
142 changes: 142 additions & 0 deletions models/entities/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define(
'user',
{
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
weehanId: {
type: DataTypes.STRING(45),
allowNull: false,
unique: true
},
gender: {
type: DataTypes.ENUM('f', 'm'),
allowNull: false
},
birth: {
type: DataTypes.INTEGER(4),
allowNull: false
},
email: {
type: DataTypes.STRING(100),
allowNull: false
},
kakaoId: {
type: DataTypes.STRING(45),
allowNull: false,
unique: true
},
height: {
type: DataTypes.INTEGER(3),
allowNull: false
},
bodyType: {
type: DataTypes.ENUM('light', 'middle', 'heavy'),
allowNull: false
},
smoking: {
type: DataTypes.BOOLEAN,
allowNull: false
},
major: {
type: DataTypes.ENUM(
'국어국문학과',
'중어중문학과',
'영어영문학과',
'독어독문학과',
'사학과',
'철학과',
'경제금융학과',
'경영학부',
'파이낸스경영학과',
'의류학과',
'식품영양학과',
'실내건축디자인학과',
'교육학과',
'교육공학과',
'국어교육과',
'영어교육과',
'수학교육과',
'응용미술교육과',
'성악과',
'작곡과',
'피아노과',
'관현악과',
'국악과',
'체육학과',
'스포스산업학과',
'연극영화학과',
'무용학과',
'국제학부',
'간호학부',
'산업융합학부',
'관광학부',
'미디어커뮤니케이션학과',
'사회학과',
'정치외교학과',
'의과대학',
'수학과',
'화학과',
'물리학과',
'생명과학과',
'행정학과',
'정책학과',
'건축학부',
'건축공학부',
'건설환경공학과',
'도시공학과',
'자원환경공학과',
'융합전자공학부',
'전기생체공학부',
'신소재공학부',
'화학공학과',
'생명공학과',
'유기나노공학과',
'에너지공학과',
'기계공학부',
'원자력공학과',
'산업공학과',
'미래자동차공학과',
'컴퓨터소프트웨어학부',
'정보시스템학과'
),
allowNull: false
},
religion: {
type: DataTypes.ENUM(
'기독교',
'천주교',
'불교',
'원불교',
'이슬람교',
'기타',
'종교없음'
),
allowNull: false
},
team: {
type: DataTypes.INTEGER(11),
allowNull: true,
references: {
model: 'team',
key: 'id'
}
},
isActivate: {
type: DataTypes.INTEGER(4),
allowNull: false
},
warning: {
type: DataTypes.STRING(100),
allowNull: true
}
Comment on lines +133 to +136

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

report과 N:M 관계입니다. 다만 여기가 manTeam과 관계가 걸리는 건지, womanTeam과 관계가 걸리는 건지에 따라 reference가 달라져야 할 텐데 이 부분을 어떻게 해야 할지?..

가장 간단하게는 warningForMan, warningForWoman으로 띡 나눠버리면 될 것 같긴 한데, 다른 방법이 있는지는 잘 모르겠네요

},
{
tableName: 'user'
}
)
}
Loading