I have identified the data type I am receiving from the server action, yet an error persists indicating that it cannot be assigned to a type that does not exist.
type Package = {
productName: string;
};
type BuddyShield = {
remarks: string | null;
buddyShieldUploadProof: boolean;
rtoStarted: Date | null;
};
type User = {
fullname: string;
};
export type OrderSecondSchema = {
id: number;
awbNumber: string | null;
ChannelOrder_Id: string | null;
deliveryPartner: string | null;
shippingDate: Date;
status: OrderStatus;
Packages: Package[];
buddyShield: BuddyShield | null;
Users: User;
};
export type OrderQueryResult = OrderSecondSchema[];
export async function getFilteredOrders(filters: OrderFilters) {
const { startDate, endDate, partner, page, searchQuery } = filters;
const itemsPerPage = 10;
const skip = (page - 1) * itemsPerPage;
const userIdString = getCurrentUser();
> userIdString, gets the string id.
const whereClause: any = {
status: {
in: ['RTO_IN_TRANSIT', 'RTO_DELIVERED']
}
}
whereClause.usersId = userIdString
const allOrders : OrderQueryResult = await prisma.orders.findMany({
where: whereClause,
select: {
id: true,
awbNumber: true,
ChannelOrder_Id: true,
deliveryPartner: true,
shippingDate: true,
status: true,
Packages : {
select: {
productName: true,
}
},
buddyShield : {
select: {
remarks: true,
buddyShieldUploadProof: true,
rtoStarted: true,
}
},
Users: {
select: {
fullname: true,
}
},
}
});
// console.log('Line 81 ', allOrders);
// Apply date and partner filters
console.log('Line 122 startdate ', startDate, ' enddate ', endDate);
let filteredOrders = allOrders.filter((order) => {
const orderDate = new Date(order.shippingDate);
const dateFilter =
(!startDate || orderDate >= new Date(startDate)) &&
(!endDate || orderDate <= new Date(endDate));
const partnerFilter =
partner === "All" ||
(order.deliveryPartner?.toLowerCase() ?? "") === partner.toLowerCase();
return dateFilter && partnerFilter;
});
// Apply fuzzy search if searchQuery is provided
if (searchQuery) {
console.log('Line 137 ', searchQuery);
const fuse = new Fuse(filteredOrders, {
keys: ['awbNumber'],
threshold: 0.3,
});
filteredOrders = fuse.search(searchQuery).map(result => result.item);
console.log('Fuse Search ', filteredOrders);
}
const totalOrders = filteredOrders.length;
const totalPages = Math.ceil(totalOrders / itemsPerPage);
// Apply pagination
filteredOrders = filteredOrders.slice(skip, skip + itemsPerPage);
return {
orders: filteredOrders,
totalPages,
currentPage: page,
totalOrders,
};
}
I attempted to define types specifying the expected return values and checked the line number where the error occurred to determine if it was related to the type or not, but unfortunately, I could not resolve it.