Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Added parameters to the db requests to fit usage #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/server/services/invoice/invoice.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { Transaction } from 'sequelize/types';
@singleton()
export class InvoiceDB {
async getAllInvoices(): Promise<InvoiceModel[]> {
return await InvoiceModel.findAll();
return await InvoiceModel.findAll({ order: [['status', 'DESC'], ['createdAt', 'DESC']]});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What value does status have here again?

Copy link
Author

@lexinor lexinor Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to filter on the status which are "PAID", "PENDING", etc.. Like that we can view the pending invoices and the earliest ones instead of the oldest and paid ones

}

async getAllReceivingInvoices(
identifier: string,
pagination: GetInvoicesInput,
): Promise<InvoiceModel[]> {
return await InvoiceModel.findAll({ where: { toIdentifier: identifier }, ...pagination });
return await InvoiceModel.findAll({ order: [["status", "DESC"], ["createdAt", "DESC"]], where: { toIdentifier: identifier }, ...pagination });
}

async getReceivedInvoicesCount(identifier: string): Promise<number> {
Expand All @@ -34,7 +34,7 @@ export class InvoiceDB {
async createInvoice(input: CreateInvoiceInput): Promise<InvoiceModel> {
const expiresAt = input.expiresAt
? input.expiresAt
: new Date(Date.now() + MS_TWO_WEEKS).toString();
: new Date(Date.now() + MS_ONE_WEEK).toString();

return await InvoiceModel.create({ ...input, expiresAt });
}
Expand Down