Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | import { uniq } from 'lodash-es'; import { type SetRequired } from 'type-fest'; import { http } from '@amalia/core/http/client'; import { type EngineError } from '@amalia/core/types'; import { bufferCalls } from '@amalia/ext/typescript'; import { type PlanTemplateDehydrated } from '@amalia/payout-calculation/types'; import { type BadgeConfiguration, type CreatePlanBadgeConfigurationRequest, type CreatePlanCategoryRequest, type CreatePlanRequest, type DuplicatePlanRequest, type ImportTokenFromOtherPlanRequest, type PatchPlanBadgeConfigurationRequest, type PatchPlanForecastingConfigurationRequest, type PatchPlanRequest, type PatchPlanVisibility, type PatchPlanWorkflowRequest, type Plan, type PlanCategory, type PlanVisibility, type PutPlanHighlightedKpisRequest, type PutPlanRulesOrderRequest, type UpdatePlanCategoryRequest, } from '@amalia/payout-definition/plans/types'; const e = encodeURIComponent; export class PlansApiClient { public static async list(filters?: { userIds?: string[]; planIds?: string[]; planStatus?: PlanVisibility | null; search?: string; showArchived?: boolean; periodId?: string; }): Promise<SetRequired<Plan, 'planAssignements'>[]> { const { data } = await http.get<SetRequired<Plan, 'planAssignements'>[]>(`/plans`, { params: { userIds: filters?.userIds, planIds: filters?.planIds, planStatus: filters?.planStatus, search: filters?.search, periodId: filters?.periodId, showArchived: filters?.showArchived, }, }); return data; } public static async get(planId: string): Promise<Plan> { const { data } = await http.get<Plan>(`/plans/${e(planId)}`); return data; } public static async getPlanTemplate( planId: string, ): Promise<{ template?: PlanTemplateDehydrated; error?: EngineError }> { const { data } = await http.get<{ template?: PlanTemplateDehydrated; error?: EngineError }>( `/plans/${e(planId)}/template`, ); return data; } public static async create(plan: CreatePlanRequest): Promise<Plan> { const { data } = await http.post<Plan>('/plans/', plan); return data; } public static async patchPlanVisibility(planId: string, patch: PatchPlanVisibility): Promise<Plan> { const { data } = await http.patch<Plan>(`/plans/${planId}/visibility`, patch); return data; } public static async patchPlanWorkflow({ planId, ...patchPlanWorkflowRequest }: PatchPlanWorkflowRequest & { planId: Plan['id']; }): Promise<Plan> { return (await http.patch<Plan>(`/plans/${e(planId)}/workflow`, patchPlanWorkflowRequest)).data; } public static async patchPlan({ planId, ...patchPlanRequest }: PatchPlanRequest & { planId: Plan['id']; }): Promise<Plan> { return (await http.patch<Plan>(`/plans/${e(planId)}`, patchPlanRequest)).data; } public static async patchPlanForecastingConfiguration({ planId, ...patchPlanForecastingConfigurationRequest }: PatchPlanForecastingConfigurationRequest & { planId: Plan['id']; }): Promise<Plan> { return ( await http.patch<Plan>(`/plans/${e(planId)}/forecasting-configuration`, patchPlanForecastingConfigurationRequest) ).data; } public static async putPlanHighlightedKpis({ planId, ...request }: PutPlanHighlightedKpisRequest & { planId: Plan['id']; }): Promise<Plan> { return (await http.put<Plan>(`/plans/${e(planId)}/highlighted-kpis`, request)).data; } public static async archive(planId: Plan['id']): Promise<Plan> { const { data } = await http.put<Plan>(`/plans/archive/${e(planId)}`, { archived: true }); return data; } public static async unarchive(planId: Plan['id']): Promise<Plan> { const { data } = await http.put<Plan>(`/plans/archive/${e(planId)}`, { archived: false }); return data; } public static async delete(planId: Plan['id']): Promise<void> { await http.delete(`/plans/${e(planId)}`); } public static readonly bufferedGetModifiers = bufferCalls< [Plan['id']], { isDeletable: boolean; isUnpublishable: boolean }, Record<Plan['id'], { isDeletable: boolean; isUnpublishable: boolean }> >( async (planIds) => { const { data } = await http.get<Record<Plan['id'], { isDeletable: boolean; isUnpublishable: boolean }>>( `/plans/modifiers`, { params: { planIds: uniq(planIds.map(([planId]) => planId)) } }, ); return data; }, ([planId], result) => result[planId], ); public static async duplicatePlan({ planId, ...duplicatePlanRequest }: DuplicatePlanRequest & { planId: Plan['id'] }): Promise<Plan> { const { data: newPlan } = await http.post<Plan>(`/plans/${e(planId)}/duplicate`, duplicatePlanRequest); return newPlan; } public static async importTokenFromOtherPlan({ planId, ...importTokenFromOtherPlanRequest }: ImportTokenFromOtherPlanRequest & { planId: Plan['id']; }): Promise<void> { await http.post(`/plans/${e(planId)}/import-token-from-other-plan`, { ...importTokenFromOtherPlanRequest, }); } public static async createPlanBadgeConfiguration( planId: Plan['id'], createBadgeConfigurationRequest: CreatePlanBadgeConfigurationRequest, ): Promise<void> { await http.post(`/plans/${e(planId)}/badges`, createBadgeConfigurationRequest); } public static async patchPlanBadgeConfiguration( planId: Plan['id'], badgeId: BadgeConfiguration['id'], patchBadgeConfigurationRequest: PatchPlanBadgeConfigurationRequest, ): Promise<void> { await http.patch(`/plans/${e(planId)}/badges/${e(badgeId)}`, patchBadgeConfigurationRequest); } public static async deletePlanBadgeConfiguration(planId: Plan['id'], badgeId: string): Promise<void> { await http.delete(`/plans/${e(planId)}/badges/${e(badgeId)}`); } public static async createCategory({ planId, ...createPlanCategoryRequest }: CreatePlanCategoryRequest & { planId: Plan['id'] }): Promise<Plan> { return (await http.post<Plan>(`/plans/${e(planId)}/categories`, createPlanCategoryRequest)).data; } public static async updateCategory({ planId, categoryName, ...updatePlanCategoryRequest }: UpdatePlanCategoryRequest & { planId: Plan['id']; categoryName: PlanCategory['name'] }): Promise<Plan> { return (await http.put<Plan>(`/plans/${e(planId)}/categories/${e(categoryName)}`, updatePlanCategoryRequest)).data; } public static async deleteCategory({ planId, categoryName, }: { planId: Plan['id']; categoryName: PlanCategory['name']; }): Promise<Plan> { return (await http.delete<Plan>(`/plans/${e(planId)}/categories/${e(categoryName)}`)).data; } public static async putRulesOrder({ planId, ...request }: PutPlanRulesOrderRequest & { planId: Plan['id'] }) { await http.put(`/plans/${e(planId)}/rules-order`, request); } } |