Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into feature/config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
remko48 committed Oct 22, 2024
2 parents 4194d30 + 57577d3 commit 52a2a0a
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 260 deletions.
6 changes: 4 additions & 2 deletions src/modals/zaken/ZaakForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { navigationStore, zaakStore, zaakTypeStore } from '../../store/store.js'
</div>

<NcButton v-if="success === null"
:disabled="loading || !zaak.identificatie || !zaakTypeLoading || !zaak.bronorganisatie || !zaak.verantwoordelijkeOrganisatie || !zaak.startdatum"
:disabled="loading || !zaak.identificatie || zaakTypeLoading || !zaak.bronorganisatie || !zaak.verantwoordelijkeOrganisatie || !zaak.startdatum"
type="primary"
@click="saveZaak()">
<template #icon>
Expand Down Expand Up @@ -122,7 +122,9 @@ export default {
archiefstatus: '',
},
loading: false,
success: false,
success: null,
error: null,
zaakLoading: false,
zaakType: {},
zaakTypeLoading: false,
archiefstatus: {
Expand Down
125 changes: 0 additions & 125 deletions src/store/modules/zaakTypen.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { setActivePinia, createPinia } from 'pinia'

import { useZaakTypeStore } from './zaakTypen.js'
import { ZaakType, mockZaakTypen } from '../../entities/index.js'
import { ZaakType, mockZaakType } from '../../entities/index.js'

describe('ZaakTypen Store', () => {
beforeEach(() => {
Expand All @@ -12,24 +12,24 @@ describe('ZaakTypen Store', () => {
it('sets zaakType item correctly', () => {
const store = useZaakTypeStore()

store.setZaakTypeItem(mockZaakTypen()[0])
store.setZaakTypeItem(mockZaakType()[0])

expect(store.zaakTypeItem).toBeInstanceOf(ZaakType)
expect(store.zaakTypeItem).toEqual(mockZaakTypen()[0])
expect(store.zaakTypeItem).toEqual(mockZaakType()[0])

expect(store.zaakTypeItem.validate().success).toBe(true)
})

it('sets zaakTypen list correctly', () => {
const store = useZaakTypeStore()

store.setZaakTypeList(mockZaakTypen())
store.setZaakTypeList(mockZaakType())

expect(store.zaakTypeList).toHaveLength(mockZaakTypen().length)
expect(store.zaakTypeList).toHaveLength(mockZaakType().length)

store.zaakTypeList.forEach((item, index) => {
expect(item).toBeInstanceOf(ZaakType)
expect(item).toEqual(mockZaakTypen()[index])
expect(item).toEqual(mockZaakType()[index])
expect(item.validate().success).toBe(true)
})
})
Expand Down
176 changes: 176 additions & 0 deletions src/store/modules/zaakTypen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import { defineStore } from 'pinia'
import { TZaakType, ZaakType } from '../../entities/index.js'

const apiEndpoint = '/index.php/apps/zaakafhandelapp/api/ztc/zaaktypen'

type TOptions = {
/**
* Save the zaaktype item to the store in 'zaakTypeItem'
*/
setItem?: boolean
}

export const useZaakTypeStore = defineStore('zaakTypen', {
state: () => ({
zaakTypeItem: null,
zaakTypeList: [],
}),
actions: {
setZaakTypeItem(zaakTypeItem: ZaakType | TZaakType) {
this.zaakTypeItem = zaakTypeItem && new ZaakType(zaakTypeItem)
console.info('Active zaaktype item set to ' + zaakTypeItem)
},
setZaakTypeList(zaakTypeList: ZaakType[] | TZaakType[]) {
this.zaakTypeList = zaakTypeList.map(
(zaakTypeItem) => new ZaakType(zaakTypeItem),
)
console.info('Zaaktypen list set to ' + zaakTypeList.length + ' items')
},
/**
* Refresh the list of zaaktype items.
*
* @param search - Optional search query to filter the zaaktypen list. (default: `null`)
* @throws If the HTTP request fails.
* @return {Promise<{ response: Response, data: TZaakType[], entities: ZaakType[] }>} The response, raw data, and entities.
*/
async refreshZaakTypeList(search: string = null): Promise<{ response: Response, data: TZaakType[], entities: ZaakType[] }> {
let endpoint = apiEndpoint

if (search !== null && search !== '') {
endpoint = endpoint + '?_search=' + search
}

console.info('Refreshing zaaktypen list with search: ' + search)

const response = await fetch(endpoint, {
method: 'GET',
})

if (!response.ok) {
console.error(response)
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = (await response.json()).results as TZaakType[]
const entities = data.map((zaakTypeItem: TZaakType) => new ZaakType(zaakTypeItem))

this.setZaakTypeList(data)

return { response, data, entities }
},
/**
* Fetch a single zaaktype item by its ID.
*
* @param id - The ID of the zaaktype item to fetch.
* @param options - Options for fetching the zaaktype item. (default: `{}`)
* @throws If the HTTP request fails.
* @return {Promise<{ response: Response, data: TZaakType, entity: ZaakType }>} The response, raw data, and entity.
*/
async getZaakType(
id: string,
options: TOptions = {},
): Promise<{ response: Response, data: TZaakType, entity: ZaakType }> {
const endpoint = `${apiEndpoint}/${id}`

console.info('Fetching zaaktype item with id: ' + id)

const response = await fetch(endpoint, {
method: 'GET',
})

if (!response.ok) {
console.error(response)
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json()
const entity = new ZaakType(data)

options.setItem && this.setZaakTypeItem(data)

return { response, data, entity }
},
/**
* Delete a zaaktype item from the store.
*
* @param zaakTypeItem - The zaaktype item to delete.
* @throws If there is no zaaktype item to delete or if the zaaktype item does not have an id.
* @throws If the HTTP request fails.
* @return {Promise<{ response: Response }>} The response from the delete request.
*/
async deleteZaakType(zaakTypeItem: ZaakType | TZaakType): Promise<{ response: Response }> {
if (!zaakTypeItem) {
throw new Error('No zaaktype item to delete')
}
if (!zaakTypeItem.id) {
throw new Error('No id for zaaktype item to delete')
}

const endpoint = `${apiEndpoint}/${zaakTypeItem.id}`

console.info('Deleting zaaktype item with id: ' + zaakTypeItem.id)

const response = await fetch(endpoint, {
method: 'DELETE',
})

if (!response.ok) {
console.error(response)
throw new Error(`HTTP error! status: ${response.status}`)
}

this.refreshZaakTypeList()

return { response }
},
/**
* Save a zaaktype item to the store. If the zaaktype item does not have an id, it will be created.
* Otherwise, it will be updated.
*
* @param zaakTypeItem - The zaaktype item to save.
* @param options - Options for saving the zaaktype item. (default: `{ setItem: true }`)
* @throws If there is no zaaktype item to save or if the HTTP request fails.
* @return {Promise<{ response: Response, data: TZaakType, entity: ZaakType }>} The response, raw data, and entity.
*/
async saveZaakType(
zaakTypeItem: ZaakType | TZaakType,
options: TOptions = { setItem: true },
): Promise<{ response: Response, data: TZaakType, entity: ZaakType }> {
if (!zaakTypeItem) {
throw new Error('No zaaktype item to save')
}

const isNewZaakType = !zaakTypeItem.id
const endpoint = isNewZaakType
? `${apiEndpoint}`
: `${apiEndpoint}/${zaakTypeItem.id}`
const method = isNewZaakType ? 'POST' : 'PUT'

console.info('Saving zaaktype item with id: ' + zaakTypeItem.id)

const response = await fetch(
endpoint,
{
method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(zaakTypeItem),
},
)

if (!response.ok) {
console.error(response)
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json() as TZaakType
const entity = new ZaakType(data)

options.setItem && this.setZaakTypeItem(data)
this.refreshZaakTypeList()

return { response, data, entity }
},
},
})
8 changes: 4 additions & 4 deletions src/store/modules/zaken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type TOptions = {
/**
* Save the zaak item to the store in 'zaakItem'
*/
setZaakItem?: boolean
setItem?: boolean
}

export const useZaakStore = defineStore('zaken', {
Expand Down Expand Up @@ -86,7 +86,7 @@ export const useZaakStore = defineStore('zaken', {
const data = await response.json()
const entity = new Zaak(data)

options.setZaakItem && this.setZaakItem(data)
options.setItem && this.setZaakItem(data)

return { response, data, entity }
},
Expand Down Expand Up @@ -134,7 +134,7 @@ export const useZaakStore = defineStore('zaken', {
*/
async saveZaak(
zaakItem: Zaak | TZaak,
options: TOptions = { setZaakItem: true },
options: TOptions = { setItem: true },
): Promise<{ response: Response, data: TZaak, entity: Zaak }> {
if (!zaakItem) {
throw new Error('No zaak item to save')
Expand Down Expand Up @@ -167,7 +167,7 @@ export const useZaakStore = defineStore('zaken', {
const data = await response.json() as TZaak
const entity = new Zaak(data)

options.setZaakItem && this.setZaakItem(data)
options.setItem && this.setZaakItem(data)
this.refreshZakenList()

return { response, data, entity }
Expand Down
Loading

0 comments on commit 52a2a0a

Please sign in to comment.