mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 10:13:32 -04:00 
			
		
		
		
	* cleanup oversized buttons * add get all by category function to reciep repos * fix shopping-list can_merge logic * use randomized data for testing * add random getter to repository for meal-planner * add stub route for random meals * cleanup global namespace * add rules database type * fix type * add plan rules schema * test plan rules methods * add mealplan rules controller * add new repository * update frontend types * formatting * fix regression * update autogenerated types * add api class for mealplan rules * add tests and fix bugs * fix data returns * proof of concept rules editor * add tag support * remove old group categories * add tag support * implement random by rules api * change snack to sides * remove incorrect typing * split repo for custom methods * fix query and use and_ clause * use repo function * remove old test * update changelog
		
			
				
	
	
		
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { useAsync, ref } from "@nuxtjs/composition-api";
 | |
| import { useAsyncKey } from "./use-utils";
 | |
| import { useUserApi } from "~/composables/api";
 | |
| import { CreateGroup } from "~/api/class-interfaces/groups";
 | |
| 
 | |
| export const useGroupSelf = function () {
 | |
|   const api = useUserApi();
 | |
| 
 | |
|   const actions = {
 | |
|     get() {
 | |
|       const group = useAsync(async () => {
 | |
|         const { data } = await api.groups.getCurrentUserGroup();
 | |
| 
 | |
|         return data;
 | |
|       }, useAsyncKey());
 | |
| 
 | |
|       return group;
 | |
|     },
 | |
|     async updatePreferences() {
 | |
|       if (!group.value) {
 | |
|         return;
 | |
|       }
 | |
| 
 | |
|       const { data } = await api.groups.setPreferences(group.value.preferences);
 | |
| 
 | |
|       if (data) {
 | |
|         group.value.preferences = data;
 | |
|       }
 | |
|     },
 | |
|   };
 | |
| 
 | |
|   const group = actions.get();
 | |
| 
 | |
|   return { actions, group };
 | |
| };
 | |
| 
 | |
| export const useGroups = function () {
 | |
|   const api = useUserApi();
 | |
|   const loading = ref(false);
 | |
| 
 | |
|   function getAllGroups() {
 | |
|     loading.value = true;
 | |
|     const asyncKey = String(Date.now());
 | |
|     const groups = useAsync(async () => {
 | |
|       const { data } = await api.groups.getAll();
 | |
|       return data;
 | |
|     }, asyncKey);
 | |
| 
 | |
|     loading.value = false;
 | |
|     return groups;
 | |
|   }
 | |
| 
 | |
|   async function refreshAllGroups() {
 | |
|     loading.value = true;
 | |
|     const { data } = await api.groups.getAll();
 | |
|     groups.value = data;
 | |
|     loading.value = false;
 | |
|   }
 | |
| 
 | |
|   async function deleteGroup(id: string | number) {
 | |
|     loading.value = true;
 | |
|     const { data } = await api.groups.deleteOne(id);
 | |
|     loading.value = false;
 | |
|     refreshAllGroups();
 | |
|     return data;
 | |
|   }
 | |
| 
 | |
|   async function createGroup(payload: CreateGroup) {
 | |
|     loading.value = true;
 | |
|     const { data } = await api.groups.createOne(payload);
 | |
| 
 | |
|     if (data && groups.value) {
 | |
|       groups.value.push(data);
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const groups = getAllGroups();
 | |
| 
 | |
|   return { groups, getAllGroups, refreshAllGroups, deleteGroup, createGroup };
 | |
| };
 |