diff --git a/packages/api/prisma/migrations/20241202073949_alter_anon_flags/migration.sql b/packages/api/prisma/migrations/20241202073949_alter_anon_flags/migration.sql new file mode 100644 index 00000000..c0721e15 --- /dev/null +++ b/packages/api/prisma/migrations/20241202073949_alter_anon_flags/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - You are about to drop the column `is_anon` on the `chat` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE `chat` DROP COLUMN `is_anon`, + MODIFY `type` ENUM('message', 'notice', 'anonymous', 'adminnotice') NOT NULL; diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index ec86d156..ae11108a 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -55,7 +55,6 @@ model Chat { message String @db.VarChar(500) createdAt DateTime @default(now()) @map("created_at") user User @relation(fields: [userId], references: [id]) - isAnon Boolean @default(false) @map("is_anon") @@index([userId], map: "chat_user_id_fkey") @@map("chat") @@ -127,6 +126,7 @@ model UserTag { enum ChatType { message notice - + anonymous + adminnotice @@map("chat_type") } diff --git a/packages/api/src/service/chat.ts b/packages/api/src/service/chat.ts index 94491ac1..d29e2ec3 100644 --- a/packages/api/src/service/chat.ts +++ b/packages/api/src/service/chat.ts @@ -7,18 +7,10 @@ export const createMessage = async ( { message, type }: schema.Send, user: User, ): Promise => { - const isAnon = type === "anonymous"; - const anonUser: User = { - id: 0, - isAdmin: false, - displayName: "익명", - username: "익명", - }; const sendQuery: Prisma.ChatCreateInput = { user: { connect: user }, - type: "message", + type, message, - isAnon, createdAt: new Date(), }; @@ -35,14 +27,16 @@ export const createMessage = async ( type: true, message: true, createdAt: true, - isAnon: true, }, }); - if (isAnon) { - createdMessage.user = anonUser; + if (type === "anonymous") { + createdMessage.user.id = 0; + createdMessage.user.displayName = "익명"; } + console.log(createdMessage); + return { ...createdMessage, createdAt: createdAt.toISOString(), @@ -101,20 +95,15 @@ export const retrieve = async ({ type: true, message: true, createdAt: true, - isAnon: true, }, }); - const anonUser: User = { - id: 0, - isAdmin: false, - displayName: "익명", - username: "익명", - }; - - return messages.map(({ createdAt, isAnon, ...message }) => { + return messages.map(({ createdAt, ...message }) => { const displayMessage = message; - if (isAnon) displayMessage.user = anonUser; + if (message.type === "anonymous") { + displayMessage.user.id = 0; + displayMessage.user.displayName = "익명"; + } return { ...displayMessage, createdAt: createdAt.toISOString(),