diff --git a/src/stores/hosts.ts b/src/stores/hosts.ts new file mode 100644 index 0000000000000000000000000000000000000000..b2370cf1b7a423d8d553d1bbae75e69062d4e6ed --- /dev/null +++ b/src/stores/hosts.ts @@ -0,0 +1,29 @@ +import { + APIListPaginated, + APIRemove, + APIRetrieve, + APIUpdate, + createExtendableAPI, +} from '@rokoli/bnb/drf' +import { defineStore } from 'pinia' + +import { createSteeringURL } from '@/api' +import { components } from '@/steering-types' +import { steeringAuthInit } from '@/stores/auth' +import { KeysFrom, Host } from '@/types' + +type ReadonlyAttrs = KeysFrom<Host, 'id'> +type HostUpdateData = Omit<Host, ReadonlyAttrs> +type HostPartialUpdateData = components['schemas']['PatchedHost'] + +export const useHostStore = defineStore('hosts', () => { + const endpoint = createSteeringURL.prefix('hosts') + const { api, base } = createExtendableAPI<Host>(endpoint, steeringAuthInit) + return { + ...base, + ...APIListPaginated(api), + ...APIRetrieve(api), + ...APIUpdate<Host, HostUpdateData, HostPartialUpdateData>(api), + ...APIRemove(api), + } +}) diff --git a/src/stores/index.ts b/src/stores/index.ts index 8ce6e37b8c06cb8aace4de09a2d868a679957893..a318496fe9e703b45e6d9476c38a4d7312ccd99b 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -1,18 +1,10 @@ import { createSteeringURL } from '@/api' -import { - Category, - FundingCategory, - Host, - Language, - LinkType, - MusicFocus, - Topic, - Type, -} from '@/types' +import { Category, FundingCategory, Language, LinkType, MusicFocus, Topic, Type } from '@/types' import { steeringAuthInit } from '@/stores/auth' import { createUnpaginatedAPIStore } from '@/stores/util' export { useAuthStore, useUserStore } from '@/stores/auth' +export { useHostStore } from '@/stores/hosts' export { useImageStore } from '@/stores/images' export { useLicenseStore } from '@/stores/licenses' export { useNoteStore } from '@/stores/notes' @@ -61,12 +53,6 @@ export const useMusicFocusStore = createUnpaginatedAPIStore<MusicFocus>( steeringAuthInit, { syncOnAuth: true }, ) -export const useHostStore = createUnpaginatedAPIStore<Host>( - 'hosts', - createSteeringURL.prefix('hosts'), - steeringAuthInit, - { syncOnAuth: true }, -) export const useLinkTypeStore = createUnpaginatedAPIStore<LinkType>( 'linkTypes',