시드 생성
This commit is contained in:
@@ -1239,10 +1239,8 @@ router.get('/clubs/:id', async (req, res) => {
|
||||
},
|
||||
{
|
||||
model: ClubFeature,
|
||||
as: 'features',
|
||||
include: [{
|
||||
model: Feature,
|
||||
as: 'feature',
|
||||
attributes: ['id', 'name', 'code', 'description']
|
||||
}]
|
||||
},
|
||||
@@ -1280,12 +1278,13 @@ router.get('/clubs/:id', async (req, res) => {
|
||||
delete response.ClubSubscriptions;
|
||||
|
||||
// 기능 정보 포맷팅
|
||||
const formattedFeatures = response.features.map(feature => ({
|
||||
...feature.feature,
|
||||
const formattedFeatures = response.ClubFeatures.map(feature => ({
|
||||
...feature.Feature,
|
||||
enabled: feature.enabled,
|
||||
expiryDate: feature.expiryDate
|
||||
}));
|
||||
response.features = formattedFeatures;
|
||||
delete response.ClubFeatures;
|
||||
|
||||
res.json(response);
|
||||
await logActivity(req.user.id, 'VIEW_CLUB', `클럽 ${id}의 정보를 조회했습니다.`);
|
||||
@@ -1299,59 +1298,7 @@ router.get('/clubs/:id', async (req, res) => {
|
||||
router.post('/clubs', authenticateJWT, clubController.createClub);
|
||||
|
||||
// 클럽 수정
|
||||
router.put('/clubs/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { name, description, ownerEmail, location } = req.body;
|
||||
|
||||
// 클럽 존재 여부 확인
|
||||
const club = await Club.findByPk(id);
|
||||
if (!club) {
|
||||
return res.status(404).json({ message: '클럽을 찾을 수 없습니다.' });
|
||||
}
|
||||
|
||||
// 새 모임장 정보 확인
|
||||
const newOwner = await User.findOne({ where: { email: ownerEmail } });
|
||||
if (!newOwner) {
|
||||
return res.status(404).json({ message: '모임장으로 지정할 사용자를 찾을 수 없습니다.' });
|
||||
}
|
||||
|
||||
// 트랜잭션 시작
|
||||
const t = await sequelize.transaction();
|
||||
|
||||
try {
|
||||
// 클럽 정보 업데이트
|
||||
await club.update({
|
||||
name,
|
||||
description,
|
||||
location,
|
||||
ownerId: newOwner.id
|
||||
}, { transaction: t });
|
||||
|
||||
// 활동 로그 기록
|
||||
await logActivity(req.user.id, 'UPDATE_CLUB', `클럽 "${name}"의 정보를 수정했습니다.`);
|
||||
|
||||
await t.commit();
|
||||
|
||||
// 업데이트된 클럽 정보 조회
|
||||
const updatedClub = await Club.findByPk(id, {
|
||||
include: [{
|
||||
model: User,
|
||||
as: 'owner',
|
||||
attributes: ['id', 'name', 'email']
|
||||
}]
|
||||
});
|
||||
|
||||
res.json(updatedClub);
|
||||
} catch (error) {
|
||||
await t.rollback();
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('클럽 수정 중 오류:', error);
|
||||
res.status(500).json({ message: '클럽 수정 중 오류가 발생했습니다.' });
|
||||
}
|
||||
});
|
||||
router.put('/clubs/:id', authenticateJWT, clubController.updateClub);
|
||||
|
||||
// 클럽 기능 관리
|
||||
router.put('/clubs/:id/features', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user