// DO NOT EDIT THIS FILE. AUTO-GENERATED BY mobiletto-orm-typedef-gen import { Ref } from "vue"; import { defineStore } from "pinia"; import { MobilettoOrmValidationErrors } from "mobiletto-orm"; import { DestinationType, DestinationTypeDef } from "yuebing-model"; import { destinationService } from "~/utils/services/model/destinationService"; import { MobilettoOrmFindApiOpts } from "~/utils/search"; import { updateOrmList } from "~/utils/orm"; const updateList = (list: DestinationType[] | null, id: string, opts?: { object?: DestinationType; remove?: boolean }) => { return updateOrmList(DestinationTypeDef, list, id, opts); }; export const useDestinationStore = defineStore("destination", { state: () => ({ finding: false, found: null as DestinationType | null, creating: false, created: null as DestinationType | null, updating: false, updated: null as DestinationType | null, deleting: false, deleted: null as boolean | null, searching: false, destinationList: null as DestinationType[] | null, }), getters: { destinationBusy: (state) => state.finding || state.creating || state.updating || state.deleting || state.searching, }, actions: { async lookup(id: string, serverErrors: Ref): Promise { this.found = null; this.finding = true; try { this.found = await destinationService.findDestination(id, serverErrors); if (this.found) { updateList(this.destinationList, DestinationTypeDef.id(this.found), {object: this.found}); } return this.found; } finally { this.finding = false; } }, async search(query?: MobilettoOrmFindApiOpts): Promise { try { this.searching = true; this.destinationList = await destinationService.searchDestination(query); return this.destinationList || []; } finally { this.searching = false; } }, async create(object: DestinationType, serverErrors: Ref): Promise { try { this.created = null; this.creating = true; this.created = await destinationService.createDestination(object, serverErrors); return this.created; } finally { this.creating = false; } }, async update(object: DestinationType, serverErrors: Ref): Promise { try { this.updated = null; this.updating = true; this.updated = await destinationService.updateDestination(object, serverErrors); if (this.updated) { updateList(this.destinationList, DestinationTypeDef.id(this.updated), {object: this.updated}); } return this.updated; } finally { this.updating = false; } }, async delete(id: string, serverErrors: Ref, purge?: boolean): Promise { try { this.deleted = null; this.deleting = true; const deleteResult = await destinationService.deleteDestination(id, serverErrors, !!purge); if (deleteResult) { updateList(this.destinationList, id, { remove: true }); this.deleted = true; } else { this.deleted = false; } return this.deleted; } finally { this.deleting = false; } }, }, });