Skip to content
Snippets Groups Projects
notes.ts 1.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • import {
      APICreate,
      APIListPaginated,
      APIRemove,
      APIRetrieve,
      APIUpdate,
      createExtendableAPI,
    
    } from '@rokoli/bnb/drf'
    import { defineStore } from 'pinia'
    
    import { createSteeringURL } from '@/api'
    import { steeringAuthInit } from '@/stores/auth'
    
    import { Note, Show } from '@/types'
    
    type ReadonlyAttrs = 'id' | 'createdAt' | 'createdBy' | 'updatedAt' | 'updatedBy' | 'ownerId'
    
    export type NewNote = Omit<Note, ReadonlyAttrs>
    type NoteCreateData = Omit<Note, ReadonlyAttrs>
    type NoteUpdateData = Partial<Omit<Note, ReadonlyAttrs>>
    
    
    export function newNote(timeslotId: number, show?: Show): NewNote {
    
      return {
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        timeslotId,
    
        title: '',
        slug: '',
        summary: '',
        content: '',
    
        imageId: null,
        cbaId: null,
    
        contributorIds: show?.hostIds ?? [],
    
    Konrad Mohrfeldt's avatar
    Konrad Mohrfeldt committed
        languageIds: [],
        topicIds: [],
    
        links: [],
    
      }
    }
    
    export const useNoteStore = defineStore('notes', () => {
      const endpoint = createSteeringURL.prefix('notes')
    
      const { api, base } = createExtendableAPI<Note>(endpoint, steeringAuthInit)
    
      return {
        ...base,
        ...APIListPaginated(api),
        ...APIRetrieve(api),
        ...APICreate<Note, NoteCreateData>(api),
        ...APIUpdate<Note, NoteUpdateData>(api),
        ...APIRemove(api),
      }
    })