-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from midday-ai/feature/user-categories
Feature/user categories
- Loading branch information
Showing
96 changed files
with
3,829 additions
and
1,852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use server"; | ||
|
||
import { ChatPromptTemplate } from "@langchain/core/prompts"; | ||
import { ChatGroq } from "@langchain/groq"; | ||
import { getCountry } from "@midday/location"; | ||
import { z } from "zod"; | ||
import { action } from "../safe-action"; | ||
import { getVatRateSchema } from "../schema"; | ||
|
||
const model = new ChatGroq({ | ||
temperature: 0, | ||
model: "mixtral-8x7b-32768", | ||
apiKey: process.env.GROQ_API_KEY, | ||
}); | ||
|
||
const vatSchema = z.object({ | ||
vat: z.number().min(5).max(100), | ||
}); | ||
|
||
const modelWithStructuredOutput = model.withStructuredOutput(vatSchema); | ||
|
||
export const getVatRateAction = action(getVatRateSchema, async ({ name }) => { | ||
const country = getCountry(); | ||
|
||
const prompt = ChatPromptTemplate.fromMessages([ | ||
[ | ||
"system", | ||
"You are an expert in VAT rates for the specific country and category", | ||
], | ||
["human", `What's the VAT rate for category ${name} in ${country.name}?`], | ||
]); | ||
|
||
const chain = prompt.pipe(modelWithStructuredOutput); | ||
const result = await chain.invoke({}); | ||
|
||
return { | ||
vat: result.vat, | ||
country: country.name, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { createCategoriesSchema } from "./schema"; | ||
|
||
export const createCategoriesAction = action( | ||
createCategoriesSchema, | ||
async ({ categories }) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
const teamId = user?.data?.team_id; | ||
|
||
const { data, error } = await supabase | ||
.from("transaction_categories") | ||
.insert( | ||
categories.map((category) => ({ | ||
...category, | ||
team_id: teamId, | ||
})) | ||
) | ||
.select("id, name, color, vat, slug"); | ||
|
||
if (error) { | ||
throw Error(error.message); | ||
} | ||
|
||
revalidateTag(`transaction_categories_${teamId}`); | ||
|
||
return data; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { | ||
revalidatePath as revalidatePathFunc, | ||
revalidateTag, | ||
} from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { deleteCategoriesSchema } from "./schema"; | ||
|
||
export const deleteCategoriesAction = action( | ||
deleteCategoriesSchema, | ||
async ({ ids, revalidatePath }) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
|
||
const teamId = user?.data?.team_id; | ||
|
||
const response = await supabase | ||
.from("transaction_categories") | ||
.delete() | ||
.in("id", ids) | ||
.eq("system", false) | ||
.select(); | ||
|
||
revalidatePathFunc(revalidatePath); | ||
revalidateTag(`transactions_${teamId}`); | ||
revalidateTag(`spending_${teamId}`); | ||
|
||
return response; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { updateCategorySchema } from "./schema"; | ||
|
||
export const updateCategoryAction = action( | ||
updateCategorySchema, | ||
async ({ id, name, color, description, vat }) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
const teamId = user?.data.team_id; | ||
|
||
await supabase | ||
.from("transaction_categories") | ||
.update({ name, color, description, vat }) | ||
.eq("id", id); | ||
|
||
revalidateTag(`transaction_categories_${teamId}`); | ||
revalidateTag(`transactions_${teamId}`); | ||
revalidateTag(`spending_${teamId}`); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.