Skip to content

Commit

Permalink
관리화면에서 특수문자 제대로 나오게 수정 및 그룹 ID 변경 가능하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Heegeun Park committed Aug 13, 2024
1 parent 07ef864 commit a74248a
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 9 deletions.
13 changes: 13 additions & 0 deletions server/database/admin/group/list/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ export async function removeGroup(groupUid: number): Promise<boolean> {
await remove(`DELETE FROM ${table}group WHERE uid = ? LIMIT 1`, [groupUidQuery])
return true
}

// 그룹 ID 업데이트
export async function updateGroupId(groupUid: number, newId: string): Promise<boolean> {
const [group] = await select(`SELECT uid FROM ${table}group WHERE id = ? LIMIT 1`, [newId])
if (group) {
return false
}
await update(`UPDATE ${table}group SET id = ? WHERE uid = ? LIMIT 1`, [
newId,
groupUid.toString(),
])
return true
}
40 changes: 39 additions & 1 deletion server/routers/admin/group/list/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import { Elysia, t } from "elysia"
import { jwt } from "@elysiajs/jwt"
import { createGroup, removeGroup } from "../../../../database/admin/group/list/update"
import {
createGroup,
removeGroup,
updateGroupId,
} from "../../../../database/admin/group/list/update"
import { fail, success, EXTEND_TYPE_CHECK } from "../../../../util/tools"
import { getUserBasic } from "../../../../database/board/list"
import { SUPER_ADMIN_UID } from "../../../../database/auth/const"
Expand Down Expand Up @@ -115,3 +119,37 @@ export const update = new Elysia()
}),
},
)
.put(
"/update/group",
async ({ body: { groupUid, changeGroupId }, newAccessToken, accessUserUid }) => {
const response = {
newAccessToken: "",
}

if (accessUserUid < 1) {
return fail(`Unauthorized access.`, response)
}
if (groupUid < 1) {
return fail(`Invalid group uid.`, response)
}
if (changeGroupId.length < 2) {
return fail(`Invalid group id.`, response)
}

const result = await updateGroupId(groupUid, changeGroupId.trim())
if (result === false) {
return fail(`Duplicated group id.`, response)
}

return success({
newAccessToken,
})
},
{
...EXTEND_TYPE_CHECK,
body: t.Object({
groupUid: t.Number(),
changeGroupId: t.String(),
}),
},
)
4 changes: 2 additions & 2 deletions src/components/admin/group/BoardGroupGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
</template>

<v-chip variant="tonal" color="blue-grey" class="ml-2"
><strong>{{ board.name }}</strong>
><strong>{{ util.unescape(board.name) }}</strong>
<v-divider vertical class="ml-2 mr-2"></v-divider>
{{ board.info }}
{{ util.unescape(board.info) }}
<v-divider vertical class="ml-2 mr-2"></v-divider>
<strong class="mr-2">{{ board.total.post }}</strong> posts
<v-divider vertical class="ml-2 mr-2"></v-divider>
Expand Down
37 changes: 37 additions & 0 deletions src/components/admin/grouplist/ChangeGroupIdDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<v-dialog v-model="list.changeGroupIdDialog" persistent>
<v-card :max-width="home.dialogWidth" class="mx-auto" :color="home.color.header">
<v-card-title>그룹ID 변경하기</v-card-title>
<v-divider></v-divider>
<v-card-text>
<v-text-field
v-model="list.changeGroupId"
hide-details
bg-color="white"
width="200"
variant="solo"
prepend-inner-icon="mdi-identifier"
></v-text-field>
</v-card-text>
<v-divider></v-divider>

<v-card-actions>
<v-btn prepend-icon="mdi-close" rounded="xl" @click="list.closeChangeGroupIdDialog"
>닫기</v-btn
>
<v-spacer></v-spacer>
<v-btn prepend-icon="mdi-content-save" rounded="xl" @click="list.updateGroupId"
>변경하기</v-btn
>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script setup lang="ts">
import { useAdminGroupListStore } from "../../../store/admin/group/list"
import { useHomeStore } from "../../../store/home"
const list = useAdminGroupListStore()
const home = useHomeStore()
</script>
20 changes: 15 additions & 5 deletions src/components/admin/grouplist/GroupListGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<v-menu activator="parent">
<v-list>
<v-list-item v-for="(group, index) in list.existGroupIds" :key="index">
{{ group.name }}
{{ util.unescape(group.name) }}
</v-list-item>
</v-list>
</v-menu>
Expand All @@ -37,9 +37,16 @@
>
<v-list-item v-for="(group, index) in list.groups" :key="index">
<template v-slot:prepend>
<v-chip variant="outlined" color="blue-grey" prepend-icon="mdi-identifier">{{
group.id
}}</v-chip>
<v-chip
variant="outlined"
color="blue-grey"
prepend-icon="mdi-identifier"
@click="list.openChangeGroupIdDialog(group.uid, group.id)"
>{{ group.id }}
<v-tooltip activator="parent"
>클릭하시면 그룹ID를 변경하실 수 있는 창이 나타납니다</v-tooltip
>
</v-chip>
</template>

<v-chip
Expand All @@ -48,7 +55,7 @@
class="ml-2"
:prepend-avatar="TSBOARD.PREFIX + (group.manager.profile || '/no-profile.svg')"
>
<strong class="ml-1">{{ group.manager.name }}</strong>
<strong class="ml-1">{{ util.unescape(group.manager.name) }}</strong>
<v-divider vertical class="ml-2 mr-2"></v-divider>
<strong class="mr-1">{{ group.count }}</strong> board(s)
</v-chip>
Expand All @@ -74,13 +81,16 @@
</v-list-item>
</v-list>
</v-card>

<change-group-id-dialog></change-group-id-dialog>
</template>

<script setup lang="ts">
import { onMounted } from "vue"
import { useAdminGroupListStore } from "../../../store/admin/group/list"
import { useUtilStore } from "../../../store/util"
import { TSBOARD } from "../../../../tsboard.config"
import ChangeGroupIdDialog from "./ChangeGroupIdDialog.vue"
const list = useAdminGroupListStore()
const util = useUtilStore()
Expand Down
1 change: 1 addition & 0 deletions src/messages/store/admin/group/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const LIST = {
INVALID_REMOVE_TARGET: "삭제할 그룹이 올바르게 지정되지 않았습니다.",
FAILED_REMOVE_GROUP: "지정된 그룹을 삭제할 수 없었습니다.",
REMOVED_GROUP: "그룹을 성공적으로 삭제하였습니다.",
FAILED_UPDATE_GROUP_ID: "그룹 ID를 업데이트 하지 못했습니다.",
NO_DUPLICATE_ID: "입력하신 그룹 아이디는 사용 가능합니다.",
MINIMUM_GROUP_COUNT: "그룹은 최소 1개 이상 존재해야 합니다.",
}
5 changes: 5 additions & 0 deletions src/store/admin/board/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { App } from "../../../../server/index"
import { AdminBoardConfig, AdminPair } from "../../../interface/admin"
import { useAdminStore } from "../common"
import { useAuthStore } from "../../user/auth"
import { useUtilStore } from "../../util"
import { GENERAL } from "../../../messages/store/admin/board/general"
import { INIT_BOARD_CONFIG } from "../../../../server/database/admin/board/general/const"
import { TSBOARD } from "../../../../tsboard.config"
Expand All @@ -23,6 +24,7 @@ export const useAdminBoardGeneralStore = defineStore("adminBoardGeneral", () =>
const client = edenTreaty<App>(TSBOARD.API.URI)
const admin = useAdminStore()
const auth = useAuthStore()
const util = useUtilStore()
const confirmRemoveCategoryDialog = ref<boolean>(false)
const board = ref<AdminBoardConfig>(INIT_BOARD_CONFIG)
const boardGroupName = ref<string>("")
Expand Down Expand Up @@ -51,7 +53,10 @@ export const useAdminBoardGeneralStore = defineStore("adminBoardGeneral", () =>
return admin.error(`${GENERAL.UNABLE_LOAD_CONFIG} (${response.data.error})`)
}
auth.updateUserToken(response.data.result.newAccessToken)

board.value = response.data.result.config
board.value.name = util.unescape(board.value.name)
board.value.info = util.unescape(board.value.info)
boardRows.value = board.value.rowCount.toString()
boardWidth.value = board.value.width.toString()
boardUseCategory.value = board.value.useCategory
Expand Down
48 changes: 48 additions & 0 deletions src/store/admin/group/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ export const useAdminGroupListStore = defineStore("adminGroupList", () => {
name: "",
})
const confirmRemoveGroupDialog = ref<boolean>(false)
const changeGroupIdDialog = ref<boolean>(false)
const existGroupIds = ref<AdminPair[]>([])
const newGroupId = ref<string>("")
const changeGroupId = ref<string>("")
const groupUid = ref<number>(0)

// 그룹들 목록 가져오기
async function loadGroupList(): Promise<void> {
Expand Down Expand Up @@ -165,17 +168,62 @@ export const useAdminGroupListStore = defineStore("adminGroupList", () => {
closeRemoveGroupDialog()
}

// 그룹 ID 변경하기 다이얼로그 띄우기
function openChangeGroupIdDialog(uid: number, id: string): void {
groupUid.value = uid
changeGroupId.value = id
changeGroupIdDialog.value = true
}

// 그룹 ID 변경하기 다이얼로그 닫기
function closeChangeGroupIdDialog(): void {
groupUid.value = 0
changeGroupId.value = ""
changeGroupIdDialog.value = false
}

// 그룹 ID 변경하기
async function updateGroupId(): Promise<void> {
const response = await client.tsapi.admin.group.list.update.group.put({
$headers: {
authorization: auth.user.token,
},
$query: {
userUid: auth.user.uid,
},
groupUid: groupUid.value,
changeGroupId: changeGroupId.value,
})

if (!response.data) {
return admin.error(LIST.NO_RESPONSE)
}
if (response.data.success === false) {
return admin.error(`${LIST.FAILED_UPDATE_GROUP_ID} (${response.data.error})`)
}

auth.updateUserToken(response.data.result.newAccessToken)
await loadGroupList()
closeChangeGroupIdDialog()
}

return {
groups,
removeGroupTarget,
confirmRemoveGroupDialog,
changeGroupIdDialog,
newGroupId,
changeGroupId,
groupUid,
existGroupIds,
loadGroupList,
updateExistGroupIds,
createNewGroup,
confirmRemoveGroup,
closeRemoveGroupDialog,
removeGroup,
openChangeGroupIdDialog,
closeChangeGroupIdDialog,
updateGroupId,
}
})
2 changes: 1 addition & 1 deletion tsboard.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const IS_DEV = false // 개발중일 때 true 로 설정 후 저장, 프
export const PORT_DEV_VITE = 3000
export const PORT_DEV = 3200
export const PORT_PROD = 3100
export const LOCALHOST = "http://geunyul2.asuscomm.com" // 개발중일때는 localhost 혹은 본인 도메인 설정
export const LOCALHOST = "http://localhost" // 개발중일때는 localhost 혹은 본인 도메인 설정
const DEV_URL = `${LOCALHOST}:${PORT_DEV_VITE}`
const PROD_URL = "https://tsboard.dev" /*** 수정 필요 ***/

Expand Down

0 comments on commit a74248a

Please sign in to comment.