Skip to content

Commit

Permalink
fix: anonType management in DB and BE
Browse files Browse the repository at this point in the history
  • Loading branch information
monde2738 committed Dec 2, 2024
1 parent e9bf14a commit b2d899b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -127,6 +126,7 @@ model UserTag {
enum ChatType {
message
notice
anonymous
adminnotice
@@map("chat_type")
}
33 changes: 11 additions & 22 deletions packages/api/src/service/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ export const createMessage = async (
{ message, type }: schema.Send,
user: User,
): Promise<schema.Message> => {
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(),
};

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

Check warning on line 38 in packages/api/src/service/chat.ts

View workflow job for this annotation

GitHub Actions / Lint and Format (18.x, 8.x)

Unexpected console statement

return {
...createdMessage,
createdAt: createdAt.toISOString(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit b2d899b

Please sign in to comment.