Skip to content

Commit

Permalink
wip: refactor thread publication mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
jbuget committed Sep 11, 2023
1 parent ccd1c43 commit 1034988
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/ThreadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function publishThread(): Promise<void> {
if (thread.value && thread.value.messages) {
thread.value.id = await doSaveThread(thread.value)
const nonEmptyMessages = thread.value.messages.filter((message: any) => message.text.trim().length > 0 || message.attachments.length > 0)
await $fetch('/api/publications', { method: 'post', body: { messages: nonEmptyMessages } })
await $fetch(`/api/threads/${thread.value.id}/publication`, { method: 'post', body: { messages: nonEmptyMessages } })
toast.add({ severity: 'success', summary: 'Thread published', detail: `${nonEmptyMessages.length} posts published`, life: 3000 });
}
}
Expand Down
3 changes: 1 addition & 2 deletions server/api/threads.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CreateThreadRequest = {
}

export default defineEventHandler(async (event: any) => {
console.log(`GET /api/threads`)
console.log(`POST /api/threads`)

const threadData: CreateThreadRequest = await readBody(event)
const now = new Date()
Expand All @@ -41,6 +41,5 @@ export default defineEventHandler(async (event: any) => {
const [latest] = thread.versions.slice(-1)
result.latest = latest
}
console.log(result)
return result;
})
7 changes: 7 additions & 0 deletions server/api/threads/[id]/publication.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default defineEventHandler(async (event: any) => {
const threadId = parseInt(getRouterParam(event, 'id') || '')

console.log(`POST /api/threads/${threadId}/publication`)

return 'ok'
})

0 comments on commit 1034988

Please sign in to comment.