diff --git a/prisma/migrations/20250802104722_init/migration.sql b/prisma/migrations/20250802104722_init/migration.sql new file mode 100644 index 0000000..1eb4257 --- /dev/null +++ b/prisma/migrations/20250802104722_init/migration.sql @@ -0,0 +1,38 @@ +/* + Warnings: + + - You are about to drop the column `user_id` on the `user_agreement` table. All the data in the column will be lost. + - The primary key for the `user_categories` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `user_id` on the `user_categories` table. All the data in the column will be lost. + - A unique constraint covering the columns `[account_id,agreement_id]` on the table `user_agreement` will be added. If there are existing duplicate values, this will fail. + - Added the required column `account_id` to the `user_agreement` table without a default value. This is not possible if the table is not empty. + - Added the required column `account_id` to the `user_categories` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE `user_agreement` DROP FOREIGN KEY `user_agreement_user_id_fkey`; + +-- DropForeignKey +ALTER TABLE `user_categories` DROP FOREIGN KEY `user_categories_user_id_fkey`; + +-- DropIndex +DROP INDEX `user_agreement_user_id_agreement_id_key` ON `user_agreement`; + +-- AlterTable +ALTER TABLE `user_agreement` DROP COLUMN `user_id`, + ADD COLUMN `account_id` BIGINT NOT NULL; + +-- AlterTable +ALTER TABLE `user_categories` DROP PRIMARY KEY, + DROP COLUMN `user_id`, + ADD COLUMN `account_id` BIGINT NOT NULL, + ADD PRIMARY KEY (`account_id`, `category_id`); + +-- CreateIndex +CREATE UNIQUE INDEX `user_agreement_account_id_agreement_id_key` ON `user_agreement`(`account_id`, `agreement_id`); + +-- AddForeignKey +ALTER TABLE `user_categories` ADD CONSTRAINT `user_categories_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `user_agreement` ADD CONSTRAINT `user_agreement_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20250802150431_account_id_unique/migration.sql b/prisma/migrations/20250802150431_account_id_unique/migration.sql new file mode 100644 index 0000000..bba1ce6 --- /dev/null +++ b/prisma/migrations/20250802150431_account_id_unique/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - A unique constraint covering the columns `[account_id]` on the table `artists` will be added. If there are existing duplicate values, this will fail. + - A unique constraint covering the columns `[account_id]` on the table `users` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX `artists_account_id_key` ON `artists`(`account_id`); + +-- CreateIndex +CREATE UNIQUE INDEX `users_account_id_key` ON `users`(`account_id`); diff --git a/prisma/migrations/20250802171420_follow_account_id_add/migration.sql b/prisma/migrations/20250802171420_follow_account_id_add/migration.sql new file mode 100644 index 0000000..e7883da --- /dev/null +++ b/prisma/migrations/20250802171420_follow_account_id_add/migration.sql @@ -0,0 +1,23 @@ +/* + Warnings: + + - You are about to drop the column `user_id` on the `follows` table. All the data in the column will be lost. + - A unique constraint covering the columns `[account_id,artist_id]` on the table `follows` will be added. If there are existing duplicate values, this will fail. + - Added the required column `account_id` to the `follows` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE `follows` DROP FOREIGN KEY `follows_user_id_fkey`; + +-- DropIndex +DROP INDEX `follows_user_id_artist_id_key` ON `follows`; + +-- AlterTable +ALTER TABLE `follows` DROP COLUMN `user_id`, + ADD COLUMN `account_id` BIGINT NOT NULL; + +-- CreateIndex +CREATE UNIQUE INDEX `follows_account_id_artist_id_key` ON `follows`(`account_id`, `artist_id`); + +-- AddForeignKey +ALTER TABLE `follows` ADD CONSTRAINT `follows_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e31adc1..099a519 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -19,8 +19,11 @@ model Account { oauthId String @map("oauth_id") @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") - users User[] - artists Artist[] + users User[] + artists Artist[] + userAgreements UserAgreement[] + userCategories UserCategory[] + follows Follow[] @@unique([provider, oauthId]) @@map("accounts") @@ -29,7 +32,7 @@ model Account { model User { id BigInt @id @default(autoincrement()) nickname String @db.VarChar(50) - accountId BigInt @map("account_id") + accountId BigInt @map("account_id") @unique description String? @db.VarChar(1000) profileImage String? @map("profile_image") @db.VarChar(255) createdAt DateTime @default(now()) @map("created_at") @@ -44,10 +47,7 @@ model User { chatMessages ChatMessage[] reviews Review[] bookmarks Bookmark[] - follows Follow[] notifications Notification[] - userAgreements UserAgreement[] - userCategories UserCategory[] searchHistories SearchHistory[] pushToken PushToken? @@ -56,7 +56,7 @@ model User { model Artist { id BigInt @id @default(autoincrement()) - accountId BigInt @map("account_id") + accountId BigInt @map("account_id") @unique nickname String @db.VarChar(50) profileImage String? @map("profile_image") @db.VarChar(255) description String? @db.VarChar(1000) @@ -83,13 +83,13 @@ model Category { } model UserCategory { - userId BigInt @map("user_id") + accountId BigInt @map("account_id") categoryId BigInt @map("category_id") - user User @relation(fields: [userId], references: [id]) + account Account @relation(fields: [accountId], references: [id]) category Category @relation(fields: [categoryId], references: [id]) - @@id([userId, categoryId]) + @@id([accountId, categoryId]) @@map("user_categories") } @@ -241,13 +241,13 @@ model ChatMessage { model Follow { id BigInt @id @default(autoincrement()) artistId BigInt @map("artist_id") - userId BigInt @map("user_id") + accountId BigInt @map("account_id") createdAt DateTime @default(now()) @map("created_at") - artist Artist @relation(fields: [artistId], references: [id]) - user User @relation(fields: [userId], references: [id]) + artist Artist @relation(fields: [artistId], references: [id]) + account Account @relation(fields: [accountId], references: [id]) - @@unique([userId, artistId]) + @@unique([accountId, artistId]) @@map("follows") } @@ -337,13 +337,13 @@ model Agreement { model UserAgreement { id BigInt @id @default(autoincrement()) - userId BigInt @map("user_id") + accountId BigInt @map("account_id") agreementId BigInt @map("agreement_id") - user User @relation(fields: [userId], references: [id]) + account Account @relation(fields: [accountId], references: [id]) agreement Agreement @relation(fields: [agreementId], references: [id]) - @@unique([userId, agreementId]) + @@unique([accountId, agreementId]) @@map("user_agreement") } diff --git a/prisma/seed.js b/prisma/seed.js index d9c25d5..8371dfa 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -55,9 +55,76 @@ async function main() { }); // Category 생성 - const category = await prisma.category.create({ + const category1 = await prisma.category.create({ data: { - name: "캐릭터 일러스트", + name: "글", + }, + }); + // Category 생성 + const category2 = await prisma.category.create({ + data: { + name: "그림", + }, + }); + // Category 생성 + const category3 = await prisma.category.create({ + data: { + name: "영상", + }, + }); + // Category 생성 + const category4 = await prisma.category.create({ + data: { + name: "디자인", + }, + }); + // Category 생성 + const category5 = await prisma.category.create({ + data: { + name: "굿즈", + }, + }); + // Category 생성 + const category6 = await prisma.category.create({ + data: { + name: "점술", + }, + }); + // Category 생성 + const category7 = await prisma.category.create({ + data: { + name: "사운드", + }, + }); + // Category 생성 + const category8 = await prisma.category.create({ + data: { + name: "모션", + }, + }); + // Category 생성 + const category9 = await prisma.category.create({ + data: { + name: "외주", + }, + }); + + // Agreements 생성 + const agreement1 = await prisma.agreement.create({ + data: { + agreeType:"(필수) 서비스 이용약관" + }, + }); + // Agreements 생성 + const agreement2 = await prisma.agreement.create({ + data: { + agreeType:"(필수) 개인정보 수집/이용 동의" + }, + }); + // Agreements 생성 + const agreement3 = await prisma.agreement.create({ + data: { + agreeType:"(선택) 마케팅 수신 동의" }, }); @@ -65,11 +132,12 @@ async function main() { const commission = await prisma.commission.create({ data: { artistId: artist.id, - categoryId: category.id, + categoryId: 1, title: "테스트 커미션 글", summary: "이것은 테스트용 커미션 글입니다.", content: "테스트 커미션의 상세 설명입니다. 이 부분에는 커미션의 자세한 내용이 들어갑니다.", minPrice: 1000, + formSchema: {}, }, }); diff --git a/src/auth.config.js b/src/auth.config.js index 4297840..27e5cfe 100644 --- a/src/auth.config.js +++ b/src/auth.config.js @@ -24,13 +24,21 @@ export const googleStrategy = new GoogleStrategy( const googleVerify = async (profile) => { + console.log("profile -> ",profile); + const user = await prisma.account.findFirst({ where: {oauthId : profile.id, provider:profile.provider}, - include:{users:true}, + include:{users:true, artists:true}, }); - if (user !== null) { - return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() }; + console.log("user -> ", user); + + if (user && user.users.length>0) { + return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId }; + } + + if(user && user.artists.length>0){ + return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId}; } // 사용자가 없으면 회원가입 페이지로 이동하도록 응답 @@ -59,13 +67,21 @@ export const kakaoStrategy = new KakaoStrategy( const kakaoVerify = async (profile) => { + console.log(profile); + const user = await prisma.account.findFirst({ where: {oauthId : profile.id.toString(), provider:profile.provider}, - include:{users:true}, + include:{users:true, artists:true}, }); - if (user !== null) { - return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() }; + console.log(user); + + if (user && user.users.length>0) { + return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId }; + } + + if(user && user.artists.length>0){ + return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId}; } // 사용자가 없으면 회원가입 페이지로 이동하도록 응답 @@ -73,7 +89,7 @@ const kakaoVerify = async (profile) => { return { signupRequired : true, provider : profile.provider, - oauth_id : profile.id, + oauth_id : profile.id.toString(), }; }; @@ -94,14 +110,20 @@ export const naverStrategy = new NaverStrategy( ); const naverVerify = async (profile) => { - + const user = await prisma.account.findFirst({ where: {oauthId : profile.id.toString(), provider:profile.provider}, - include:{users:true}, + include:{users:true, artists:true}, }); - if (user !== null) { - return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() }; + console.log(user); + + if (user && user.users.length>0) { + return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId }; + } + + if(user && user.artists.length>0){ + return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId}; } // 사용자가 없으면 회원가입 페이지로 이동하도록 응답 diff --git a/src/user/controller/user.controller.js b/src/user/controller/user.controller.js index 3d579e7..c68639f 100644 --- a/src/user/controller/user.controller.js +++ b/src/user/controller/user.controller.js @@ -43,12 +43,15 @@ export const addUser = async(req, res, next) => { // 사용자 프로필 조회 export const getUserProfile = async(req, res, next) => { try{ - console.log("Decoded JWT from req.user:", req.user); + console.log("👊Decoded JWT from req.user:", req.user); + + const accountId = req.user.accountId; + console.log("controller accountId -> ", accountId); - const userId = req.user.userId.toString(); - console.log(userId); + const role = req.user.role; + console.log(role); - const result = await UserService.getUserProfile(userId); + const result = await UserService.getUserProfile(accountId, role); res.status(StatusCodes.OK).success(result); } catch(err){ @@ -61,12 +64,15 @@ export const UpdateMyprofile = async(req, res, next) => { try{ console.log("Decoded JWT from req.user:", req.user); - const userId = req.user.userId.toString(); - console.log("userId : ", userId); + const accountId = req.user.accountId; + console.log("accountId -> : ", accountId); + + const role = req.user.role; const dto = new UpdateMyprofileDto(req.body); - const result = await UserService.updateMyprofile(userId, dto); + const result = await UserService.updateMyprofile(accountId, dto, role); + res.status(StatusCodes.OK).success(result); } catch(err){ next(err); @@ -78,10 +84,10 @@ export const AccessUserCategories = async(req, res, next) => { try{ console.log("Decoded JWT from req.user:", req.user); - const userId = req.user.userId.toString(); - console.log("userId : ", userId); + const accountId = req.user.accountId.toString(); + console.log("사용자가 선택한 카테고리 조회 accountId -> ", accountId); - const result = await UserService.accessUserCategories(userId); + const result = await UserService.accessUserCategories(accountId); res.status(StatusCodes.OK).success(result); } catch(err) { next(err); @@ -105,14 +111,14 @@ export const CheckUserNickname = async(req, res, next) => { // 작가 팔로우하기 export const FollowArtist = async(req, res, next) => { try{ - console.log("Decoded JWT from req.user:", req.user); + console.log("⭐Decoded JWT from req.user:", req.user); - const userId = req.user.userId.toString(); - console.log("userId : ", userId); + const accountId = req.user.accountId.toString(); + console.log("작가 팔로우하기 accountId : ", accountId); const artistId = req.params.artistId; - const result = await UserService.FollowArtist(userId, artistId); + const result = await UserService.FollowArtist(accountId, artistId); res.status(StatusCodes.CREATED).success(result); } catch(err) { @@ -123,14 +129,14 @@ export const FollowArtist = async(req, res, next) => { // 작가 팔로우 취소하기 export const CancelArtistFollow = async(req, res, next) => { try{ - console.log("Decoded JWT from req.user:", req.user); + console.log("💟Decoded JWT from req.user:", req.user); - const userId = req.user.userId.toString(); - console.log("userId : ", userId); + const accountId = req.user.accountId.toString(); + console.log("작가 팔로우 취소하기 accountId : ", accountId); const artistId = req.params.artistId; - const result = await UserService.CancelArtistFollow(userId, artistId); + const result = await UserService.CancelArtistFollow(accountId, artistId); res.status(StatusCodes.OK).success(result); } catch(err) { @@ -141,12 +147,12 @@ export const CancelArtistFollow = async(req, res, next) => { // 사용자가 팔로우 한 작가 조회하기 export const LookUserFollow = async(req, res, next) => { try{ - console.log("Decoded JWT from req.user:", req.user); + console.log("🦁Decoded JWT from req.user:", req.user); - const userId = req.user.userId.toString(); - console.log("userId : ", userId); + const accountId = req.user.accountId.toString(); + console.log("팔로우하는 작가 목록 조회 accountId : ", accountId); - const result = await UserService.LookUserFollow(userId); + const result = await UserService.LookUserFollow(accountId); res.status(StatusCodes.OK).success(result); }catch(err) { diff --git a/src/user/repository/user.repository.js b/src/user/repository/user.repository.js index 02395f0..e047899 100644 --- a/src/user/repository/user.repository.js +++ b/src/user/repository/user.repository.js @@ -4,13 +4,13 @@ export const UserRepository = { /** * 사용자 ID로 사용자 조회 */ - async findUserById(userId) { - return await prisma.user.findUnique({ + async findUserById(accountId) { + return await prisma.account.findUnique({ where: { - id: userId, + id: accountId }, - include : { - account:true, + select:{ + users: { select: { id: true, nickname: true, description: true, profileImage: true } } } }); }, @@ -18,13 +18,13 @@ export const UserRepository = { /** * 작가 ID로 작가 조회 */ - async findArtistById(artistId) { - return await prisma.artist.findUnique({ + async findArtistById(accountId) { + return await prisma.account.findUnique({ where: { - id: artistId, + id: accountId, }, - include : { - account:true, + select:{ + artists:{ select: { id: true, nickname: true, description: true, profileImage: true } } } }); }, @@ -86,9 +86,9 @@ export const UserRepository = { /** * 사용자 카테고리 연결 생성 */ - async createUserCategories (userId, categoryIds) { + async createUserCategories (accountId, categoryIds) { const data = categoryIds.map(categoryId => ({ - userId, + accountId, categoryId, })); return await prisma.userCategory.createMany({ @@ -98,9 +98,9 @@ export const UserRepository = { /** * 사용자 약관 동의 생성 */ - async createUserAgreements (userId, agreementIds) { + async createUserAgreements (accountId, agreementIds) { const data = agreementIds.map(agreementId => ({ - userId, + accountId, agreementId, })); return await prisma.userAgreement.createMany({ @@ -110,36 +110,46 @@ export const UserRepository = { /** * 나의 프로필 조회 */ - async getMyProfile(userId) { - return await prisma.user.findUnique({ + async getMyProfile(accountId) { + return await prisma.account.findUnique({ where:{ - id:userId + id:accountId }, select:{ - nickname:true, - description:true, - profileImage: true, + users: { select: { id: true, nickname: true, description: true, profileImage: true } }, + artists:{ select: { id: true, nickname: true, description: true, profileImage: true } }, } - }) + }); }, /** * 나의 프로필 수정 */ - async updateMyprofile(userId, updates) { + async updateMyprofile(accountId, updates) { return await prisma.user.update({ - where:{id: userId}, + where:{accountId}, + data:updates, + }) + }, + /** + * 작가 프로필 수정 + */ + async updateArtistProfile(accountId, updates) { + return await prisma.artist.update({ + where:{accountId}, data:updates, }) }, // 사용자가 선택한 카테고리 조회 - async AccessUserCategories(userId){ - return await prisma.user.findUnique({ - where :{id:userId}, - include:{ - userCategories:{ - include:{ - category:true, + async AccessUserCategories(accountId){ + return await prisma.userCategory.findMany({ + where :{ + accountId + }, + select:{ + category:{ + select:{ + name:true } } } @@ -153,28 +163,28 @@ export const UserRepository = { }, // 작가 팔로우하기 - async FollowArtist(userId, artistId) { + async FollowArtist(accountId, artistId) { return await prisma.follow.create({ data:{ - userId, + accountId, artistId } }) }, // 사용자가 팔로우중인지 확인 - async AlreadyFollow(userId, artistId) { + async AlreadyFollow(accountId, artistId) { return await prisma.follow.findFirst({ - where:{userId, artistId} + where:{accountId, artistId} }) }, // 작가 팔로우 취소하기 - async CancelArtistFollow(userId, artistId) { + async CancelArtistFollow(accountId, artistId) { return await prisma.follow.delete({ where:{ - userId_artistId:{ - userId, + accountId_artistId:{ + accountId, artistId } } @@ -182,10 +192,10 @@ export const UserRepository = { }, // 사용자가 팔로우한 작가 조회하기 - async LookUserFollow(userId){ + async LookUserFollow(accountId){ return await prisma.follow.findMany({ where:{ - userId:userId + accountId:accountId }, select:{ artist:{ diff --git a/src/user/service/user.service.js b/src/user/service/user.service.js index b75f235..3c3ec6f 100644 --- a/src/user/service/user.service.js +++ b/src/user/service/user.service.js @@ -36,21 +36,25 @@ export const UserService = { // 3. 사용자 프로필 생성 profile = await UserRepository.createUserProfile(account.id, nickname, "."); + console.log("user profile -> ", profile); + // 4. 사용자 약관 동의 처리 (agreements -> 사용자가 동의한 agreement id 배열) - await UserRepository.createUserAgreements(profile.id, agreements); + await UserRepository.createUserAgreements(profile.accountId, agreements); // 5. 사용자가 선한 카테고리 처리 (categories -> 사용자가 선택한 category id 배열 ) - await UserRepository.createUserCategories(profile.id, categories); + await UserRepository.createUserCategories(profile.accountId, categories); } else if (role === "artist") { // 3. 사용자 프로필 생성 profile = await UserRepository.createArtistProfile(account.id, nickname, "."); + console.log("artist profile -> ", profile); + // 4. 사용자 약관 동의 처리 (agreements -> 사용자가 동의한 agreement id 배열) - await UserRepository.createUserAgreements(profile.id, agreements); + await UserRepository.createUserAgreements(profile.accountId, agreements); // 5. 사용자가 선한 카테고리 처리 (categories -> 사용자가 선택한 category id 배열 ) - await UserRepository.createUserCategories(profile.id, categories); + await UserRepository.createUserCategories(profile.accountId, categories); } else { throw new UserRoleError(); @@ -105,22 +109,51 @@ export const UserService = { } }, // 사용자 프로필 조회 - async getUserProfile(userId) { - const user = await UserRepository.findUserById(userId); - if(!user) return null; - return { - message:"나의 프로필 조회에 성공하였습니다.", - user:{ - userId: user.id.toString(), - nickname: user.nickname, - profileImage:user.profileImage, - description: user.description + async getUserProfile(accountId, role) { + + let result; + + if(role === 'client') { + result = await UserRepository.findUserById(accountId); + console.log(result); + const user = result.users[0]; + return { + message:"나의 프로필 조회에 성공하였습니다.", + user:{ + userId: user.id, + nickname: user.nickname, + profileImage:user.profileImage, + description: user.description + } + } + } + + if(role === 'artist') { + result = await UserRepository.findArtistById(accountId); + console.log(result); + const artist = result.artists[0]; + return { + message:"나의 프로필 조회에 성공하였습니다.", + user:{ + artistId: artist.id, + nickname: artist.nickname, + profileImage:artist.profileImage, + description: artist.description + } } } }, // 나의 프로필 수정 - async updateMyprofile(userId, dto) { - const user = await UserRepository.findUserById(userId); + async updateMyprofile(accountId, dto, role) { + let user; + if(role === "client") { + user = await UserRepository.findUserById(accountId); + } + + if(role === "artist") { + user = await UserRepository.findArtistById(accountId); + } + if(!user) return null; const updates = {}; @@ -141,25 +174,44 @@ export const UserService = { }; } - const updatedUser = await UserRepository.updateMyprofile(userId, updates); + let updatedUser; - return { + if(role === "client"){ + updatedUser = await UserRepository.updateMyprofile(accountId, updates); + + return { message:"프로필 수정이 완료되었습니다.", user:{ userId: updatedUser.id.toString(), nickname: updatedUser.nickname, profileImage: updatedUser.profileImage, description: updatedUser.description, - } - }; + } + }; + } + + if(role === "artist"){ + updatedUser = await UserRepository.updateArtistProfile(accountId, updates); + + return { + message:"프로필 수정이 완료되었습니다.", + user:{ + userId: updatedUser.id.toString(), + nickname: updatedUser.nickname, + profileImage: updatedUser.profileImage, + description: updatedUser.description, + } + }; + } }, // 사용자가 선택한 카테고리 조회 - async accessUserCategories(userId) { - const user = await UserRepository.AccessUserCategories(userId); + async accessUserCategories(accountId) { + const user = await UserRepository.AccessUserCategories(accountId); + console.log(user); if(!user) return null; - const categoryName = user.userCategories.map(uc => uc.category.name); + const categoryName = user.map(item => item.category.name); return { message:"사용자가 선택한 카테고리 조회에 성공했습니다.", @@ -184,18 +236,18 @@ export const UserService = { }, // 작가 팔로우하기 - async FollowArtist(userId, artistId) { + async FollowArtist(accountId, artistId) { const artist = await UserRepository.findArtistById(artistId); if(!artist) throw new ArtistNotFound(); - const alreadyFollowing = await UserRepository.AlreadyFollow(userId, artistId); + const alreadyFollowing = await UserRepository.AlreadyFollow(accountId, artistId); if(alreadyFollowing) throw new UserAlreadyFollowArtist(); - const result = await UserRepository.FollowArtist(userId, artistId); + const result = await UserRepository.FollowArtist(accountId, artistId); return { message:"해당 작가 팔로우를 성공했습니다.", @@ -204,18 +256,18 @@ export const UserService = { }, // 작가 팔로우 취소하기 - async CancelArtistFollow(userId, artistId) { + async CancelArtistFollow(accountId, artistId) { const artist = await UserRepository.findArtistById(artistId); if(!artist) throw new ArtistNotFound(); - const FollowState = await UserRepository.AlreadyFollow(userId, artistId); + const FollowState = await UserRepository.AlreadyFollow(accountId, artistId); if(!FollowState) throw new NotFollowingArtist(); - const result = await UserRepository.CancelArtistFollow(userId, artistId); + const result = await UserRepository.CancelArtistFollow(accountId, artistId); return { message: "해당 작가 팔로우를 취소했습니다.", @@ -224,8 +276,8 @@ export const UserService = { }, // 사용자가 팔로우한 작가 조회하기 - async LookUserFollow(userId) { - const artistList = await UserRepository.LookUserFollow(userId); + async LookUserFollow(accountId) { + const artistList = await UserRepository.LookUserFollow(accountId); if(artistList.length === 0) return { message:"팔로우하는 작가가 없습니다.", diff --git a/src/user/user.routes.js b/src/user/user.routes.js index 46c36ce..1bbacb9 100644 --- a/src/user/user.routes.js +++ b/src/user/user.routes.js @@ -30,6 +30,7 @@ router.get( passport.authenticate("google", { failureRedirect: "/oauth2/login/google", failureMessage: true, + session:false, }), (req, res) => { console.log("req.user", req.user); // BigInt 의심 필드 확인 @@ -38,13 +39,14 @@ router.get( if(req.user.signupRequired){ token = signJwt({ - provider: req.user.provider.toString(), - oauth_id : req.user.oauth_id.toString(), + provider: req.user.provider, + oauth_id : req.user.oauth_id, }); return res.redirect(`/signup?token=${token}`); } token = signJwt({ - userId: req.user.id?.toString(), + accountId: req.user.accountId, + role:req.user.role, }); res.redirect(`/?token=${token}`) @@ -60,6 +62,7 @@ router.get( passport.authenticate("kakao", { failureRedirect: "/oauth2/login/kakao", failureMessage: true, + session:false, }), (req, res) => { console.log("req.user", req.user); // BigInt 의심 필드 확인 @@ -68,13 +71,14 @@ router.get( if(req.user.signupRequired){ token = signJwt({ - provider: req.user.provider.toString(), - oauth_id : req.user.oauth_id.toString(), + provider: req.user.provider, + oauth_id : req.user.oauth_id, }); return res.redirect(`/signup?token=${token}`); } token = signJwt({ - userId: req.user.id?.toString(), + accountId: req.user.accountId, + role:req.user.role, }); res.redirect(`/?token=${token}`) @@ -90,6 +94,7 @@ router.get( passport.authenticate("naver", { failureRedirect: "/oauth2/login/naver", failureMessage: true, + session:false, }), (req, res) => { console.log("req.user", req.user); // BigInt 의심 필드 확인 @@ -105,7 +110,8 @@ router.get( } token = signJwt({ - userId: req.user.id?.toString(), + accountId: req.user.accountId, + role:req.user.role, }); res.redirect(`/?token=${token}`)