diff --git a/src/api/routes/wishlist/index.ts b/src/api/routes/wishlist/index.ts index 13ad069..a26fd49 100644 --- a/src/api/routes/wishlist/index.ts +++ b/src/api/routes/wishlist/index.ts @@ -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) } diff --git a/src/api/routes/wishlist/update.ts b/src/api/routes/wishlist/update.ts index 9eb2efc..8e9b07b 100644 --- a/src/api/routes/wishlist/update.ts +++ b/src/api/routes/wishlist/update.ts @@ -73,3 +73,25 @@ export const updateItem = { reply.send(await wishlist.updateItem(request.params.itemId, request.body)) }, } + +export const itemBought = { + 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 }) + ) + }, +} diff --git a/src/composables/useWishlistStore.ts b/src/composables/useWishlistStore.ts index caac117..f4eb658 100644 --- a/src/composables/useWishlistStore.ts +++ b/src/composables/useWishlistStore.ts @@ -17,14 +17,14 @@ const fetch = async (slugText: string): Promise => { } } -const updateItem = async (item: WishlistItem): Promise => { - await client.put(`/wishlist/${item.wishlistId}/item/${item.id}`, item) +const itemBought = async (item: WishlistItem): Promise => { + await client.post(`/wishlist/${item.wishlistId}/item/${item.id}/bought`, item) } export const useWishlistStore = () => { return { list, fetch, - updateItem, + itemBought, } } diff --git a/src/views/DetailView.vue b/src/views/DetailView.vue index 7f19bb8..50c777b 100644 --- a/src/views/DetailView.vue +++ b/src/views/DetailView.vue @@ -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 => { ) if (confirmed) { item.bought = true - updateItem(item) + itemBought(item) } }