thainv-dev: tạo lại cấu trúc folder và làm UI

This commit is contained in:
nguyen van thai
2024-06-12 17:17:49 +07:00
parent c217ed82c9
commit 5b1e0af397
44 changed files with 2674 additions and 228 deletions
+7
View File
@@ -6,6 +6,9 @@ import * as topicCtrl from '~/server/models/topic'
import * as pollCtrl from '~/server/models/poll'
import * as pollOptionCtrl from '~/server/models/poll-option'
import * as pollResponseCtrl from '~/server/models/poll-response'
import * as CategoryCtrl from '~/server/models/category'
import * as quizCtrl from '~/server/models/quiz'
import * as survetCtrl from '~/server/models/survey'
const router = createRouter()
@@ -16,4 +19,8 @@ router.get('/event', defineEventHandler(eventCtrl.fetchById))
router.get('/poll-by-id', defineEventHandler(pollCtrl.fetchById))
router.get('/poll-option/pollId', defineEventHandler(pollOptionCtrl.fetchByPollId))
router.post('/poll-response', defineEventHandler(pollResponseCtrl.create))
router.get('/poll-response/pollId', defineEventHandler(pollResponseCtrl.fetchByPollId))
router.get('/quiz/get-by-id', defineEventHandler(quizCtrl.fetchById))
router.get('/survey/get-by-id', defineEventHandler(survetCtrl.fetchById))
router.get('/category-tree', defineEventHandler(CategoryCtrl.list))
export default useBase('/api/services', router.handler)
+8 -6
View File
@@ -24,20 +24,22 @@ export type Category = {
status: number;
} & Base;
export type CategoryTree = Category & {
children?: Category[]
}
export const list = async () => {
console.log('vào category service')
try {
const { site, apiUrl } = useRuntimeConfig().public;
const {items}:any = await $fetch(`${apiUrl}/cms/category/site`, {
const { items }: CategoryTree[] | any = await $fetch(`${apiUrl}/cms/category/tree/site:1`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
site: site,
site: 1,
},
});
return items;
return { items } ;
} catch (error) {
handleError(error);
}
+14 -2
View File
@@ -1,13 +1,25 @@
import { H3Event } from 'h3';
import Base from './base'
export type PollOption = {
id?: number; // Mã định danh
siteId?: number; // Mã hệ thống
pollId?: number; // Mã bình chọn
title?: string; // Tiêu đề
thumbnail?: string; // Ảnh đại diện
description?: string; // Mô tả
type?: number; // Phân loại
order?: number; // Sắp xếp
status?: number; // Trạng thái
responsesCount?: number //số lượng response của option
}
export const fetchByPollId = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { pollId}: any = getQuery(event)
const { items }: any = await $fetch(`${apiUrl}/cms/poll-option/poll:${pollId}`, {
const { pollId }: any = getQuery(event)
const { items }: PollOption[] | any = await $fetch(`${apiUrl}/cms/poll-option/poll:${pollId}`, {
method: 'GET',
headers: {
site: 1
+32 -6
View File
@@ -1,8 +1,17 @@
import { H3Event } from 'h3';
import Base from './base'
export type PollResponse = {
id?: number; // Mã định danh
siteId?: number; // Mã hệ thống
pollId?: number; // Mã bình chọn
optionId?: number; // Mã tùy chọn
responderId?: number; // Mã người phản hồi
responderInfo?: string; // Thông tin người phản hồi
status?: number; // Trạng thái
}
export const create = async (event: H3Event) => {
export const create = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const payload = await readBody<any>(event)
@@ -11,14 +20,31 @@ import Base from './base'
headers: {
site: 1
},
body: {
payload
}
body: payload
})
console.log(payload, 'payload')
return item
} catch (error) {
handleError(error);
}
}
}
export const fetchByPollId = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { pollId }: any = getQuery(event)
const { items }: PollResponse[] | any = await $fetch(`${apiUrl}/cms/poll-response/poll:${pollId}`, {
method: 'GET',
headers: {
site: 1
}
})
return items
} catch (error) {
handleError(error);
}
}
+7 -3
View File
@@ -1,6 +1,11 @@
import { H3Event } from 'h3';
import Base from './base'
export type PollSetting = {
participantType?: number; // Loại thành phần tham gia
resultPublication?: number; // Nguyên tắc công bố kết quả
}
export type Poll = {
id?: number; // Mã định danh
siteId?: number; // Mã hệ thống
@@ -12,7 +17,7 @@ export type Poll = {
startTime?: string; // Bắt đầu (string)
endTime?: string; // Kết thúc (string)
type?: number; // Phân loại
settings?: object; // Thiết lập: PollSettings (Json)
settings?: PollSetting; // Thiết lập: PollSettings (Json)
features?: string; // Đặc trưng: Featured (nổi bật)
taxonomy?: string; // Phân nhóm
isPublished?: boolean; // Đã xuất bản
@@ -25,10 +30,9 @@ export type Poll = {
export const fetchById = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { pollId}: any = getQuery(event)
const { item }: any = await $fetch(`${apiUrl}/cms/poll/${pollId}`, {
const { item }: Poll | any = await $fetch(`${apiUrl}/cms/poll/${pollId}`, {
method: 'GET',
headers: {
site: 1
+46
View File
@@ -0,0 +1,46 @@
import { H3Event } from 'h3';
export type QuizSetting = {
participantType?: number; // Loại thành phần tham gia
resultPublication?: number; // Nguyên tắc công bố kết quả
}
export type Quiz = {
id?: number; // Mã định danh
siteId?: number; // Mã hệ thống
title?: string; // Tiêu đề
code?: string; // Nhận diện
keywords?: string; // Từ khóa
thumbnail?: string; // Ảnh nhỏ
description?: string; // Mô tả
startTime?: string; // Bắt đầu
endTime?: string; // Kết thúc
type?: number; // Phân loại
settings?: object; // Thiết lập
features?: string; // Đặc trưng
taxonomy?: string; // Phân nhóm
isPublished?: boolean; // Đã xuất bản
publishedBy?: number; // Xuất bản bởi
publishedOn?: string; // Xuất bản vào lúc
expiresOn?: string; // Đã hết hạn vào lúc
order?: number; // Thứ tự sắp xếp
status?: number; // Trạng thái
}
export const fetchById = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { quizId }: any = getQuery(event)
const { item }: Quiz | any = await $fetch(`${apiUrl}/cms/quiz/${quizId}`, {
method: 'GET',
headers: {
site: 1
}
})
return item
} catch (error) {
handleError(error);
}
}
+46
View File
@@ -0,0 +1,46 @@
import { H3Event } from 'h3';
export type SurveySetting = {
participantType?: number; // Loại thành phần tham gia
resultPublication?: number; // Nguyên tắc công bố kết quả
}
export type Survey = {
id?: number; // Mã định danh
siteId?: number; // Mã hệ thống
title?: string; // Tiêu đề
code?: string; // Nhận diện
keywords?: string; // Từ khóa
thumbnail?: string; // Ảnh nhỏ
description?: string; // Mô tả
startTime?: string; // Bắt đầu, assuming date is handled as ISO string
endTime?: string; // Kết thúc, assuming date is handled as ISO string
type?: number; // Phân loại
settings?: SurveySetting; // Thiết lập, as a JSON string
features?: string; // Đặc trưng
taxonomy?: string; // Phân nhóm
isPublished?: boolean; // Đã xuất bản
publishedBy?: number; // Xuất bản bởi
publishedOn?: string; // Xuất bản vào lúc, assuming date is handled as ISO string
expiresOn?: string; // Đã hết hạn vào lúc, assuming date is handled as ISO string
order?: number; // Thứ tự sắp xếp
status?: number; // Trạng thái
}
export const fetchById = async (event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { surveyId }: any = getQuery(event)
const { item }: Survey | any = await $fetch(`${apiUrl}/cms/survey/${surveyId}`, {
method: 'GET',
headers: {
site: 1
}
})
return item
} catch (error) {
handleError(error);
}
}