Skip to main content

Animal Project Actions

Animal project server actions are functions which interact with the animal project data in the database. These functions are used to perform operations on the animal project data, such as creating, updating, and deleting animal project data.

Animal Functions

async getAnimalDocs(projectId)

Gets all animal documents for a animal project.

Example usage:

import { getAnimalDocs } from "@/app/_db/srvactions/projects/animalProject";
...
const [animals, setAnimals] = useState(null);

useEffect(() => {
try {
getAnimalDocs(projectId).then((data) => {
setAnimals(data);
});
} catch (error) {
console.error("Error fetching animals:", error);
}
}, []);
...

async getAnimal(animalId)

Gets a animal document by its ID.

Example usage:

import { getAnimal } from "@/app/_db/srvactions/projects/animalProject";
...
const [animal, setAnimal] = useState(null);

useEffect(() => {
try {
getAnimal(animalId).then((data) => {
setAnimal(data);
});
} catch (error) {
console.error("Error fetching animal:", error);
}
}, []);
...

async addAnimal(prevState, formData)

Add a new animal document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addAnimal } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(addAnimal, null);
...

async updateAnimal(prevState, formData)

Update an animal document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateAnimal } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateAnimal, null);
...

async updateRateOfGain(prevState, formData)

Update the rate of gain for an animal document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateRateOfGain } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateRateOfGain, null);
...

Feed Functions

async getFeedDocs(projectId)

Gets all feed documents for a animal project.

Example usage:

import { getFeedDocs } from "@/app/_db/srvactions/projects/animalProject";
...
const [feeds, setFeeds] = useState(null);

useEffect(() => {
try {
getFeedDocs(projectId).then((data) => {
setFeeds(data);
});
} catch (error) {
console.error("Error fetching feeds:", error);
}
}, []);
...

async getFeed(feedId)

Gets a feed document by its ID.

Example usage:

import { getFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [feed, setFeed] = useState(null);

useEffect(() => {
try {
getFeed(feedId).then((data) => {
setFeed(data);
});
} catch (error) {
console.error("Error fetching feed:", error);
}
}, []);
...

async addFeed(prevState, formData)

Add a new feed document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(addFeed, null);
...

async addFeedNoForm(feedName, projectId)

Add a new feed document to the database without using a form. This function is intended to be used when a form is not available. (Ex. adding a feed from a prompt)

Example usage:

import { addFeedNoForm } from "@/app/_db/srvactions/projects/animalProject";
...
addFeedNoForm("Feed Name", projectId);
...

async updateFeed(prevState, formData)

Update a feed document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateFeed, null);
...

Feed Purchase Functions

async getFeedPurchaseDocs(projectId)

Gets all feed purchase documents for a animal project.

Example usage:

import { getFeedPurchaseDocs } from "@/app/_db/srvactions/projects/animalProject";
...
const [feedPurchases, setFeedPurchases] = useState(null);

useEffect(() => {
try {
getFeedPurchaseDocs(projectId).then((data) => {
setFeedPurchases(data);
});
} catch (error) {
console.error("Error fetching feed purchases:", error);
}
}, []);
...

async getFeedPurchase(feedPurchaseId)

Gets a feed purchase document by its ID.

Example usage:

import { getFeedPurchase } from "@/app/_db/srvactions/projects/animalProject";
...
const [feedPurchase, setFeedPurchase] = useState(null);

useEffect(() => {
try {
getFeedPurchase(feedPurchaseId).then((data) => {
setFeedPurchase(data);
});
} catch (error) {
console.error("Error fetching feed purchase:", error);
}
}, []);
...

async addFeedPurchase(prevState, formData)

Add a new feed purchase document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addFeedPurchase } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(addFeedPurchase, null);
...

async updateFeedPurchase(prevState, formData)

Update a feed purchase document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateFeedPurchase } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateFeedPurchase, null);
...

Daily Feed Functions

async getDailyFeedDocs(projectId, animalId)

Gets all daily feed documents for a animal project.

Example usage:

import { getDailyFeedDocs } from "@/app/_db/srvactions/projects/animalProject";
...
const [dailyFeeds, setDailyFeeds] = useState(null);

useEffect(() => {
try {
getDailyFeedDocs(projectId, animalId).then((data) => {
setDailyFeeds(data);
});
} catch (error) {
console.error("Error fetching daily feeds:", error);
}
}, []);
...

async getDailyFeed(dailyFeedId)

Gets a daily feed document by its ID.

Example usage:

import { getDailyFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [dailyFeed, setDailyFeed] = useState(null);

useEffect(() => {
try {
getDailyFeed(dailyFeedId).then((data) => {
setDailyFeed(data);
});
} catch (error) {
console.error("Error fetching daily feed:", error);
}
}, []);
...

async addDailyFeed(prevState, formData)

Add a new daily feed document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addDailyFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(addDailyFeed, null);
...

async updateDailyFeed(prevState, formData)

Update a daily feed document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateDailyFeed } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateDailyFeed, null);
...

Expenses Functions

async getExpenseDocs(projectId)

Gets all expenses documents for a animal project.

Example usage:

import { getExpenseDocs } from "@/app/_db/srvactions/projects/animalProject";
...
const [expenses, setExpenses] = useState(null);

useEffect(() => {
try {
getExpenseDocs(projectId).then((data) => {
setExpenses(data);
});
} catch (error) {
console.error("Error fetching expenses:", error);
}
}, []);
...

async getExpense(expenseId)

Gets a expenses document by its ID.

Example usage:

import { getExpense } from "@/app/_db/srvactions/projects/animalProject";
...
const [expense, setExpense] = useState(null);

useEffect(() => {
try {
getExpense(expenseId).then((data) => {
setExpense(data);
});
} catch (error) {
console.error("Error fetching expense:", error);
}
}, []);
...

async addExpense(prevState, formData)

Add a new expenses document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addExpense } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(addExpense, null);
...

async updateExpense(prevState, formData)

Update an expenses document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateExpense } from "@/app/_db/srvactions/projects/animalProject";
...
const [formState, setFormState] = useFormState(updateExpense, null);
...