Fix #113
This commit is contained in:
@@ -59,6 +59,44 @@ const parseId = (value: string) => {
|
||||
}
|
||||
|
||||
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<{
|
||||
Params: { resource: string; id: string }
|
||||
}>("/resource/:resource/:id/history", {
|
||||
|
||||
@@ -3,11 +3,13 @@ import dayjs from "dayjs"
|
||||
const props = defineProps({
|
||||
type: {
|
||||
type: String,
|
||||
required: true
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
elementId: {
|
||||
type: String,
|
||||
required: true
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
renderHeadline: {
|
||||
type: Boolean,
|
||||
@@ -25,13 +27,11 @@ const items = ref([])
|
||||
const platform = ref("default")
|
||||
|
||||
const setup = async () => {
|
||||
|
||||
|
||||
if(props.type && props.elementId){
|
||||
items.value = await useNuxtApp().$api(`/api/resource/${props.type}/${props.elementId}/history`)
|
||||
} /*else {
|
||||
|
||||
}*/
|
||||
} else {
|
||||
items.value = await useNuxtApp().$api(`/api/history`)
|
||||
}
|
||||
}
|
||||
|
||||
setup()
|
||||
@@ -43,6 +43,10 @@ const addHistoryItemData = ref({
|
||||
})
|
||||
|
||||
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`, {
|
||||
method: "POST",
|
||||
@@ -161,4 +165,4 @@ const renderText = (text) => {
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -47,8 +47,7 @@ const links = computed(() => {
|
||||
id: 'historyitems',
|
||||
label: "Logbuch",
|
||||
to: "/historyitems",
|
||||
icon: "i-heroicons-book-open",
|
||||
disabled: true
|
||||
icon: "i-heroicons-book-open"
|
||||
},
|
||||
{
|
||||
label: "Organisation",
|
||||
|
||||
Reference in New Issue
Block a user