import { location_service } from './Location.service.js' import { resource_service } from './Resource.service.js' class ActionService { async perform({ text = '', action, ...args }) { if ( action === 'redirect' ) { if ( args.next ) { return location_service.redirect(args.next, args.delay || 0) } } else if ( action === 'back' ) { return location_service.back() } else if ( args.type === 'resource' ) { const { resource } = args if ( action === 'insert' ) { return location_service.redirect(`/dash/c/form/${resource}`, 0) } else if ( action === 'update' ) { const { id } = args return location_service.redirect(`/dash/c/form/${resource}?id=${id}`, 0) } else if ( action === 'delete' ) { const { id } = args const rsc = await resource_service.get(resource) await rsc.delete(id) } else if ( action === 'list' ) { return location_service.redirect(`/dash/c/listing/${resource}`, 0) } } else { throw new TypeError(`Unknown action type: ${action}`) } } } const action_service = new ActionService() export { action_service }