Skip to content

Commit

Permalink
[MOD] 뮤멘트 기록하기에서 뮤멘트 태그 데이터 삽입 쿼리 부분 모듈 사용으로 교체 #70
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchaeeun3447 committed Nov 3, 2022
1 parent 6ac8547 commit 60c6a97
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/services/MumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,18 @@ const createMument = async (userId: string, musicId: string, mumentCreateDto: Mu
try {
await connection.beginTransaction(); // 트랜잭션 적용 시작

// 뮤멘트 생성
const query1 = 'INSERT INTO mument(user_id, music_id, content, is_first, is_Private) VALUES(?, ?, ?, ?, ?)';
const query1Result = await connection.query(query1, [
userId, musicId,
!mumentCreateDto.content ? null : mumentCreateDto.content,
mumentCreateDto.isFirst,
mumentCreateDto.isPrivate
]);
const tagList = mumentCreateDto.impressionTag.concat(mumentCreateDto.feelingTag);

for(let idx in tagList) {
const query2 = 'INSERT INTO mument_tag(mument_id, tag_id) VALUES(?, ?)';
await connection.query(query2, [
query1Result.insertId, // 생성된 뮤멘트 id값
tagList[idx] // tag 번호
]);
}

// 뮤멘트 태그 생성
await mumentDB.mumentTagCreate(mumentCreateDto.impressionTag, mumentCreateDto.feelingTag, connection, query1Result.insertId);

await connection.commit(); // query1, query2 모두 성공시 커밋(데이터 적용)

const data = {
Expand Down

0 comments on commit 60c6a97

Please sign in to comment.