Getting Started
Applied Actions
Model Schemas
Components
Shunt Fact Actions
This file contains functions to manage shunt facts in a database. It includes functions to retrieve all shunt facts, create a new shunt Fact record, retrieve a shunt fact by its ID, update an existing shunt Fact, delete a shunt fact, and upload shunt fact from an Excel file. Each function interacts with the database, performs the specified operation, and handles any errors that may occur during the process.
In the src/lib/actions directory, You can find the shuntFact.actions.ts
Functions
export const getAllshuntFacts = async (
limit = 10,
page = 1,
query = "",
columns: IColumn[]
): Promise<{
data: INonDefaultDatabases[];
status: number;
totalPages: number;
totalDocuments: number;
completeData: INonDefaultDatabases[];
}> => {
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function retrieves shunt facts from the database based on specified criteria such as pagination, search query, and columns to display. It returns paginated results along with total counts and complete data matching the query.
export const createshuntFact = async (req: ICreateUpdateParams, userId: string) => {
const { defaultFields, additionalFields } = req;
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function creates a new shunt fact in the database using the provided parameters, including default and additional fields. It logs the creation of the new record in the modification history and returns the newly created shunt fact.
export const getshuntFactById = async (id: string) => {
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function fetches a specific shunt fact from the database by its unique ID. If the shunt fact exists, it returns its details; otherwise, it returns a "not found" message.
export const updateshuntFact = async (req: ICreateUpdateParams, id: string, userId: string) => {
const { defaultFields, additionalFields } = req;
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function updates an existing shunt fact in the database based on the provided parameters. It logs the changes made to the shunt fact in the modification history and returns the updated shunt fact.
export const deleteshuntFact = async (id: string, path: string, userId: string) => {
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function deletes a shunt fact from the database by its ID. It also logs the deletion in the modification history and revalidates the specified path, presumably for cache invalidation.
export const uploadshuntFactFromExcel = async (data: any, userId: string) => {
try {
await connectToDatabase();
// Implementation code here
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function uploads shunt facts from an Excel file into the database. It inserts the data from the file into the shuntFact collection and logs the upload in the modification history.