Skip to content
Snippets Groups Projects
Commit c8ed1d95 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add Pinia note store

refs #127
parent ecd9efb3
No related branches found
No related tags found
No related merge requests found
import { defineStore } from 'pinia'
import { steeringAuthInit } from '@/stores/auth'
import {
APICreate,
APIListPaginated,
APIRemove,
APIRetrieve,
APIUpdate,
createExtendableAPI,
createSteeringURL,
} from '@/api'
export type Note = {
id: number
title: string
slug: string
summary: string
content: string
image: number | null
cba_id: number | null
contributors: number[]
links: { type: string; url: string }[]
owner: number
playlist: string
tags: string
timeslot: number
created_at: string
created_by: string
updated_at: string
updated_by: string
}
type ReadonlyAttrs = 'id' | 'created_at' | 'created_by' | 'updated_at' | 'updated_by' | 'owner'
export type NewNote = Omit<Note, ReadonlyAttrs>
type NoteCreateData = Omit<Note, ReadonlyAttrs>
type NoteUpdateData = Partial<Omit<Note, ReadonlyAttrs>>
export function newNote(timeslotID: number): NewNote {
return {
title: '',
slug: '',
summary: '',
content: '',
image: null,
cba_id: null,
contributors: [],
links: [],
timeslot: timeslotID,
tags: '',
playlist: '',
}
}
export const useNoteStore = defineStore('notes', () => {
const endpoint = createSteeringURL.prefix('notes')
const { base, ...api } = createExtendableAPI<Note>(endpoint, steeringAuthInit)
return {
...base,
...APIListPaginated(api),
...APIRetrieve(api),
...APICreate<Note, NoteCreateData>(api),
...APIUpdate<Note, NoteUpdateData>(api),
...APIRemove(api),
}
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment