Getting Started
Applied Actions
Model Schemas
Components
SingleLineDiagram Actions
This file contains functions to interact with a database for managing SingleLineDiagrams. It provides functionalities such as retrieving SingleLineDiagrams with pagination and search, creating, updating, and deleting individual SingleLineDiagrams, as well as uploading data from Excel files. Additionally, it maintains a modification history for tracking changes made to SingleLineDiagrams.
In the src/lib/actions directory, You can find the singleLineDiagram.actions.ts
Functions
export const getAllSingleLineDiagrams = async (
limit = 10,
page = 1,
query = "",
columns: IColumn[]
): Promise<{
data: ISingleLineDiagram[];
status: number;
totalPages: number;
totalDocuments: number;
completeData: ISingleLineDiagram[];
}> => {
try {
await connectToDatabase();
// Implementation code to retrieve SingleLineDiagrams based on parameters
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function retrieves SingleLineDiagrams 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 createSingleLineDiagram = async (req: ICreateUpdateParams, userId: string) => {
const { defaultFields, additionalFields } = req;
try {
await connectToDatabase();
// Implementation code to create a new SingleLineDiagram
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function creates a new SingleLineDiagram 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 SingleLineDiagram.
export const getSingleLineDiagramById = async (id: string) => {
try {
await connectToDatabase();
// Implementation code to retrieve a SingleLineDiagram by its ID
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function fetches a specific SingleLineDiagram from the database by its unique ID. If the SingleLineDiagram exists, it returns its details; otherwise, it returns a "not found" message.
export const updateSingleLineDiagram = async (req: ICreateUpdateParams, id: string, userId: string) => {
const { defaultFields, additionalFields } = req;
try {
await connectToDatabase();
// Implementation code to update a SingleLineDiagram
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function updates an existing SingleLineDiagram in the database based on the provided parameters. It logs the changes made to the SingleLineDiagram in the modification history and returns the updated SingleLineDiagram.
export const deleteSingleLineDiagram = async (id: string, path: string, userId: string) => {
try {
await connectToDatabase();
// Implementation code to delete a SingleLineDiagram
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function deletes a SingleLineDiagram 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 uploadSingleLineDiagramFromExcel = async (data: any, userId: string) => {
try {
await connectToDatabase();
// Implementation code to upload SingleLineDiagrams from an Excel file
} catch (error) {
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
}
};
This function uploads SingleLineDiagrams from an Excel file into the database. It inserts the data from the file into the singleLineDiagram collection and logs the upload in the modification history.