#3 add new endpoint to mark item as bought

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2022-02-09 22:21:43 +01:00
parent bb5099d7d4
commit dc920360dc
4 changed files with 29 additions and 6 deletions

View file

@ -1,6 +1,6 @@
import { FastifyInstance } from 'fastify'
import { getAll, getBySlugUrl } from './read'
import { updateList, updateItem } from './update'
import { updateList, updateItem, itemBought } from './update'
import { createList, createItem } from './create'
import { deleteList, deleteItem } from './delete'
@ -11,6 +11,7 @@ export default async (app: FastifyInstance) => {
await app.route(createItem)
await app.route(updateList)
await app.route(updateItem)
await app.route(itemBought)
await app.route(deleteList)
await app.route(deleteItem)
}

View file

@ -73,3 +73,25 @@ export const updateItem = <RouteOptions>{
reply.send(await wishlist.updateItem(request.params.itemId, request.body))
},
}
export const itemBought = <RouteOptions>{
method: 'POST',
url: '/:wishlistId/item/:itemId/bought',
schema: {
params: {
type: 'object',
properties: {
wishlistId: { type: 'string' },
itemId: { type: 'number' },
},
},
response: {
200: wishlistItemResponseSchema,
},
},
handler: async (request: updateItemRequest, reply: FastifyReply) => {
reply.send(
await wishlist.updateItem(request.params.itemId, { bought: true })
)
},
}

View file

@ -17,14 +17,14 @@ const fetch = async (slugText: string): Promise<void> => {
}
}
const updateItem = async (item: WishlistItem): Promise<void> => {
await client.put(`/wishlist/${item.wishlistId}/item/${item.id}`, item)
const itemBought = async (item: WishlistItem): Promise<void> => {
await client.post(`/wishlist/${item.wishlistId}/item/${item.id}/bought`, item)
}
export const useWishlistStore = () => {
return {
list,
fetch,
updateItem,
itemBought,
}
}

View file

@ -13,7 +13,7 @@ const modal = useModal()
const { t } = useI18n()
const { list, fetch, updateItem } = useWishlistStore()
const { list, fetch, itemBought } = useWishlistStore()
await fetch(route.params.slug as string)
const notBoughtItems = computed(() => {
@ -31,7 +31,7 @@ const bought = async (item: WishlistItemType): Promise<void> => {
)
if (confirmed) {
item.bought = true
updateItem(item)
itemBought(item)
}
}
</script>