Skip to content
Merged
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
38 changes: 38 additions & 0 deletions prisma/migrations/20250802104722_init/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions prisma/migrations/20250802150431_account_id_unique/migration.sql
Original file line number Diff line number Diff line change
@@ -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`);
Original file line number Diff line number Diff line change
@@ -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;
34 changes: 17 additions & 17 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -44,10 +47,7 @@ model User {
chatMessages ChatMessage[]
reviews Review[]
bookmarks Bookmark[]
follows Follow[]
notifications Notification[]
userAgreements UserAgreement[]
userCategories UserCategory[]
searchHistories SearchHistory[]
pushToken PushToken?

Expand All @@ -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)
Expand All @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
74 changes: 71 additions & 3 deletions prisma/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,89 @@ 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:"(선택) 마케팅 수신 동의"
},
});

// Commission 생성 (Artist가 작성)
const commission = await prisma.commission.create({
data: {
artistId: artist.id,
categoryId: category.id,
categoryId: 1,
title: "테스트 커미션 글",
summary: "이것은 테스트용 커미션 글입니다.",
content: "테스트 커미션의 상세 설명입니다. 이 부분에는 커미션의 자세한 내용이 들어갑니다.",
minPrice: 1000,

formSchema: {},
},
});
Expand Down
44 changes: 33 additions & 11 deletions src/auth.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

// 사용자가 없으면 회원가입 페이지로 이동하도록 응답
Expand Down Expand Up @@ -59,21 +67,29 @@ 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};
}

// 사용자가 없으면 회원가입 페이지로 이동하도록 응답
// ex. 프론트에서 signupRequired : true를 응답받으면 회원가입 페이지로 이동
return {
signupRequired : true,
provider : profile.provider,
oauth_id : profile.id,
oauth_id : profile.id.toString(),
};
};

Expand All @@ -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};
}

// 사용자가 없으면 회원가입 페이지로 이동하도록 응답
Expand Down
Loading