Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Commits
c5eb5eba
Commit
c5eb5eba
authored
5 months ago
by
심재엽
Browse files
Options
Downloads
Patches
Plain Diff
refactor: 연관관계 매핑 변경
parent
1cf47570
Branches
Branches containing commit
No related tags found
2 merge requests
!31
Develop
,
!11
[#9] 번개모임, 채팅 로직 구현
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
models/chatRooms.js
+21
-0
21 additions, 0 deletions
models/chatRooms.js
models/meeting.js
+31
-4
31 additions, 4 deletions
models/meeting.js
models/meetingParticipant.js
+21
-8
21 additions, 8 deletions
models/meetingParticipant.js
models/user.js
+19
-1
19 additions, 1 deletion
models/user.js
with
92 additions
and
13 deletions
models/chatRooms.js
0 → 100644
+
21
−
0
View file @
c5eb5eba
const
mongoose
=
require
(
'
mongoose
'
);
// MongoDB 채팅방 스키마 수정 (현재 참가 중인 유저 목록 추가)
const
chatRoomsSchema
=
new
mongoose
.
Schema
({
chatRoomId
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
messages
:
[{
sender
:
String
,
message
:
String
,
timestamp
:
Date
,
type
:
{
type
:
String
,
default
:
'
message
'
}
// 기본값은 'message', 다른 값으로 'join', 'leave' 가능
}],
participants
:
[{
type
:
String
}],
lastReadAt
:
{
type
:
Map
,
of
:
Date
},
// 각 참가자의 마지막 읽은 메시지 시간 기록
lastReadLogId
:
{
type
:
Map
,
of
:
String
},
// 각 참가자의 마지막으로 읽은 logID 기록
isOnline
:
{
type
:
Map
,
of
:
Boolean
}
// 각 참가자의 온라인 상태
},
{
collection
:
'
chatrooms
'
});
// 모델이 이미 정의되어 있는 경우 재정의하지 않음
const
ChatRooms
=
mongoose
.
models
.
ChatRooms
||
mongoose
.
model
(
'
ChatRooms
'
,
chatRoomsSchema
);
module
.
exports
=
ChatRooms
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
models/meeting.js
+
31
−
4
View file @
c5eb5eba
// models/Meeting.js
const
{
DataTypes
}
=
require
(
'
sequelize
'
);
const
sequelize
=
require
(
'
../config/sequelize
'
);
const
{
sequelize
}
=
require
(
'
../config/sequelize
'
);
const
User
=
require
(
'
./User
'
);
const
Meeting
=
sequelize
.
define
(
'
Meeting
'
,
{
id
:
{
type
:
DataTypes
.
BIGINT
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
title
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
...
...
@@ -30,12 +35,34 @@ const Meeting = sequelize.define('Meeting', {
type
:
DataTypes
.
ENUM
(
'
OPEN
'
,
'
CLOSE
'
),
allowNull
:
false
,
},
created_by
:
{
type
:
DataTypes
.
BIGINT
,
allowNull
:
false
,
references
:
{
model
:
'
Users
'
,
key
:
'
id
'
,
},
},
chatRoomId
:
{
// 새로운 필드 추가
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
},
},
{
tableName
:
'
Meetings
'
,
timestamps
:
false
,
});
Meeting
.
belongsTo
(
User
,
{
foreignKey
:
'
created_by
'
,
as
:
'
creator
'
});
User
.
hasMany
(
Meeting
,
{
foreignKey
:
'
created_by
'
,
as
:
'
meetings
'
});
module
.
exports
=
Meeting
;
// 연관 관계 설정
Meeting
.
associate
=
(
models
)
=>
{
Meeting
.
belongsTo
(
models
.
User
,
{
foreignKey
:
'
created_by
'
,
// FK 설정
as
:
'
creator
'
,
// 별칭
});
Meeting
.
hasMany
(
models
.
MeetingParticipant
,
{
foreignKey
:
'
meeting_id
'
,
as
:
'
participants
'
,
});
};
module
.
exports
=
Meeting
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
models/meetingParticipant.js
+
21
−
8
View file @
c5eb5eba
// models/MeetingParticipant.js
const
{
DataTypes
}
=
require
(
'
sequelize
'
);
const
sequelize
=
require
(
'
../config/sequelize
'
);
const
Meeting
=
require
(
'
./Meeting
'
);
const
User
=
require
(
'
./User
'
);
const
{
sequelize
}
=
require
(
'
../config/sequelize
'
);
const
MeetingParticipant
=
sequelize
.
define
(
'
MeetingParticipant
'
,
{},
{
const
MeetingParticipant
=
sequelize
.
define
(
'
MeetingParticipant
'
,
{
meeting_id
:
{
type
:
DataTypes
.
BIGINT
,
allowNull
:
false
},
user_id
:
{
type
:
DataTypes
.
BIGINT
,
allowNull
:
false
}
},
{
tableName
:
'
MeetingParticipants
'
,
timestamps
:
false
,
});
MeetingParticipant
.
belongsTo
(
Meeting
,
{
foreignKey
:
'
meeting_id
'
,
as
:
'
meeting
'
});
Meeting
.
hasMany
(
MeetingParticipant
,
{
foreignKey
:
'
meeting_id
'
,
as
:
'
participants
'
});
MeetingParticipant
.
associate
=
(
models
)
=>
{
MeetingParticipant
.
belongsTo
(
models
.
Meeting
,
{
foreignKey
:
'
meeting_id
'
,
as
:
'
meeting
'
});
MeetingParticipant
.
belongsTo
(
User
,
{
foreignKey
:
'
user_id
'
,
as
:
'
user
'
});
User
.
hasMany
(
MeetingParticipant
,
{
foreignKey
:
'
user_id
'
,
as
:
'
meetingParticipations
'
});
MeetingParticipant
.
belongsTo
(
models
.
User
,
{
foreignKey
:
'
user_id
'
,
as
:
'
participantUser
'
});
};
module
.
exports
=
MeetingParticipant
;
This diff is collapsed.
Click to expand it.
models/user.js
+
19
−
1
View file @
c5eb5eba
// models/User.js
const
{
DataTypes
}
=
require
(
'
sequelize
'
);
const
sequelize
=
require
(
'
../config/sequelize
'
);
// sequelize 인스턴스 경로에 맞게 수정하세요.
const
{
sequelize
}
=
require
(
'
../config/sequelize
'
);
const
User
=
sequelize
.
define
(
'
User
'
,
{
id
:
{
type
:
DataTypes
.
BIGINT
,
// 수정: id 필드를 BIGINT로 설정
autoIncrement
:
true
,
primaryKey
:
true
,
},
name
:
{
type
:
DataTypes
.
STRING
,
// VARCHAR
allowNull
:
false
,
...
...
@@ -21,4 +26,17 @@ const User = sequelize.define('User', {
timestamps
:
true
,
// createdAt과 updatedAt 자동 관리
});
User
.
associate
=
(
models
)
=>
{
User
.
hasMany
(
models
.
Meeting
,
{
foreignKey
:
'
created_by
'
,
as
:
'
createdMeetings
'
,
});
User
.
hasMany
(
models
.
MeetingParticipant
,
{
foreignKey
:
'
user_id
'
,
as
:
'
userMeetingParticipations
'
,
});
};
module
.
exports
=
User
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment