Shunt Reactor Actions

This file contains functions to interact with a database for managing shunt reactors. It provides functionalities such as retrieving shunt reactors with pagination and search, creating, updating, and deleting individual shunt reactors, as well as uploading data from Excel files. Additionally, it maintains a modification history for tracking changes made to shunt reactors.

In the src/lib/actions directory, You can find the shuntReactor.actions.ts

Functions

getAllShuntReactors

export const getAllShuntReactors = async (
  limit = 10,
  page = 1,
  query = "",
  columns: IColumn[]
): Promise<{
  data: IShuntReactor[];
  status: number;
  totalPages: number;
  totalDocuments: number;
  completeData: IShuntReactor[];
}> => {
  try {
    await connectToDatabase();
    // Implementation code to retrieve shunt reactors based on parameters
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};

This function retrieves shunt reactors 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.

createShuntReactor

export const createShuntReactor = async (req: ICreateUpdateParams, userId: string) => {
  const { defaultFields, additionalFields } = req;
  try {
    await connectToDatabase();
    // Implementation code to create a new shunt reactor
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};
 

This function creates a new shunt reactor 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 reactor.

getShuntReactorById

export const getShuntReactorById = async (id: string) => {
  try {
    await connectToDatabase();
    // Implementation code to retrieve a shunt reactor by its ID
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};


This function fetches a specific shunt reactor from the database by its unique ID. If the shunt reactor exists, it returns its details; otherwise, it returns a "not found" message.

updateShuntReactor

export const updateShuntReactor = async (req: ICreateUpdateParams, id: string, userId: string) => {
  const { defaultFields, additionalFields } = req;
  try {
    await connectToDatabase();
    // Implementation code to update a shunt reactor
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};

This function updates an existing shunt reactor in the database based on the provided parameters. It logs the changes made to the shunt reactor in the modification history and returns the updated shunt reactor.

deleteShuntReactor

export const deleteShuntReactor = async (id: string, path: string, userId: string) => {
  try {
    await connectToDatabase();
    // Implementation code to delete a shunt reactor
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};

This function deletes a shunt reactor from the database by its ID. It also logs the deletion in the modification history and revalidates the specified path, presumably for cache invalidation.

uploadShuntReactorFromExcel

export const uploadShuntReactorFromExcel = async (data: any, userId: string) => {
  try {
    await connectToDatabase();
    // Implementation code to upload shunt reactors from an Excel file
  } catch (error) {
    throw new Error(typeof error === "string" ? error : JSON.stringify(error));
  }
};

This function uploads shunt reactors from an Excel file into the database. It inserts the data from the file into the shuntreactor collection and logs the upload in the modification history.

  1. Functions
Scroll to top