Fix #113
This commit is contained in:
@@ -59,6 +59,44 @@ const parseId = (value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function resourceHistoryRoutes(server: FastifyInstance) {
|
export default async function resourceHistoryRoutes(server: FastifyInstance) {
|
||||||
|
server.get("/history", {
|
||||||
|
schema: {
|
||||||
|
tags: ["History"],
|
||||||
|
summary: "Get all history entries for the active tenant",
|
||||||
|
},
|
||||||
|
}, async (req: any) => {
|
||||||
|
const data = await server.db
|
||||||
|
.select()
|
||||||
|
.from(historyitems)
|
||||||
|
.where(eq(historyitems.tenant, req.user?.tenant_id))
|
||||||
|
.orderBy(asc(historyitems.createdAt));
|
||||||
|
|
||||||
|
const userIds = Array.from(
|
||||||
|
new Set(data.map((item) => item.createdBy).filter(Boolean))
|
||||||
|
) as string[];
|
||||||
|
|
||||||
|
const profiles = userIds.length > 0
|
||||||
|
? await server.db
|
||||||
|
.select()
|
||||||
|
.from(authProfiles)
|
||||||
|
.where(and(
|
||||||
|
eq(authProfiles.tenant_id, req.user?.tenant_id),
|
||||||
|
inArray(authProfiles.user_id, userIds)
|
||||||
|
))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const profileByUserId = new Map(
|
||||||
|
profiles.map((profile) => [profile.user_id, profile])
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.map((historyitem) => ({
|
||||||
|
...historyitem,
|
||||||
|
created_at: historyitem.createdAt,
|
||||||
|
created_by: historyitem.createdBy,
|
||||||
|
created_by_profile: historyitem.createdBy ? profileByUserId.get(historyitem.createdBy) || null : null,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
server.get<{
|
server.get<{
|
||||||
Params: { resource: string; id: string }
|
Params: { resource: string; id: string }
|
||||||
}>("/resource/:resource/:id/history", {
|
}>("/resource/:resource/:id/history", {
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import dayjs from "dayjs"
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: false,
|
||||||
|
default: null
|
||||||
},
|
},
|
||||||
elementId: {
|
elementId: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: false,
|
||||||
|
default: null
|
||||||
},
|
},
|
||||||
renderHeadline: {
|
renderHeadline: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -25,13 +27,11 @@ const items = ref([])
|
|||||||
const platform = ref("default")
|
const platform = ref("default")
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
|
|
||||||
|
|
||||||
if(props.type && props.elementId){
|
if(props.type && props.elementId){
|
||||||
items.value = await useNuxtApp().$api(`/api/resource/${props.type}/${props.elementId}/history`)
|
items.value = await useNuxtApp().$api(`/api/resource/${props.type}/${props.elementId}/history`)
|
||||||
} /*else {
|
} else {
|
||||||
|
items.value = await useNuxtApp().$api(`/api/history`)
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
@@ -43,6 +43,10 @@ const addHistoryItemData = ref({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const addHistoryItem = async () => {
|
const addHistoryItem = async () => {
|
||||||
|
if (!props.type || !props.elementId) {
|
||||||
|
toast.add({ title: "Im zentralen Logbuch können keine direkten Einträge erstellt werden." })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const res = await useNuxtApp().$api(`/api/resource/${props.type}/${props.elementId}/history`, {
|
const res = await useNuxtApp().$api(`/api/resource/${props.type}/${props.elementId}/history`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -161,4 +165,4 @@ const renderText = (text) => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ const links = computed(() => {
|
|||||||
id: 'historyitems',
|
id: 'historyitems',
|
||||||
label: "Logbuch",
|
label: "Logbuch",
|
||||||
to: "/historyitems",
|
to: "/historyitems",
|
||||||
icon: "i-heroicons-book-open",
|
icon: "i-heroicons-book-open"
|
||||||
disabled: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Organisation",
|
label: "Organisation",
|
||||||
|
|||||||
Reference in New Issue
Block a user