fix: sort chronologically
This commit is contained in:
@@ -74,7 +74,11 @@ export const clientsRouter = createTRPCRouter({
|
||||
where: eq(clients.id, input.id),
|
||||
with: {
|
||||
invoices: {
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.createdAt)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -105,7 +105,11 @@ export const dashboardRouter = createTRPCRouter({
|
||||
// Recent Activity
|
||||
const recentInvoices = await ctx.db.query.invoices.findMany({
|
||||
where: eq(invoices.createdById, userId),
|
||||
orderBy: [desc(invoices.issueDate)],
|
||||
orderBy: [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
limit: 5,
|
||||
with: {
|
||||
client: {
|
||||
|
||||
@@ -132,9 +132,19 @@ export const invoicesRouter = createTRPCRouter({
|
||||
with: {
|
||||
business: true,
|
||||
client: true,
|
||||
items: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.issueDate)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
@@ -188,10 +198,18 @@ export const invoicesRouter = createTRPCRouter({
|
||||
business: true,
|
||||
client: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.createdAt)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
// Return null if no draft invoice exists
|
||||
@@ -219,7 +237,11 @@ export const invoicesRouter = createTRPCRouter({
|
||||
business: true,
|
||||
client: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -684,7 +706,17 @@ export const invoicesRouter = createTRPCRouter({
|
||||
.query(async ({ ctx, input }) => {
|
||||
const invoice = await ctx.db.query.invoices.findFirst({
|
||||
where: eq(invoices.publicToken, input.token),
|
||||
with: { client: true, business: true, items: { orderBy: (i, { asc }) => [asc(i.position)] } },
|
||||
with: {
|
||||
client: true,
|
||||
business: true,
|
||||
items: {
|
||||
orderBy: (i, { asc }) => [
|
||||
asc(i.date),
|
||||
asc(i.position),
|
||||
asc(i.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!invoice) throw new TRPCError({ code: "NOT_FOUND" });
|
||||
if (invoice.publicTokenExpiresAt && new Date(invoice.publicTokenExpiresAt) < new Date()) {
|
||||
|
||||
@@ -541,9 +541,18 @@ export const settingsRouter = createTRPCRouter({
|
||||
amount: true,
|
||||
position: true,
|
||||
},
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
// Format the data for export
|
||||
|
||||
@@ -83,7 +83,11 @@ async function addEntryToLatestInvoice(
|
||||
or(eq(invoices.status, "draft"), eq(invoices.status, "sent")),
|
||||
),
|
||||
with: { items: true },
|
||||
orderBy: [desc(invoices.createdAt)],
|
||||
orderBy: [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
if (!invoice) return null;
|
||||
|
||||
Reference in New Issue
Block a user