Skip to content

Commit

Permalink
🗃️ refactor (finance): ID columns now have table name along with ID
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanprince committed Feb 28, 2024
1 parent 675a002 commit 424cd10
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 11 deletions.
10 changes: 5 additions & 5 deletions apps/finance/src/app/api/accounts/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export async function GET(
const id = params.id;

const account = await db.query.financeAccount.findFirst({
where: eq(financeAccount.id, id),
where: eq(financeAccount.financeAccountId, id),
columns: {
id: true,
financeAccountId: true,
studentId: true,
hasOutstandingBalance: true,
},
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function DELETE(

const deletedAccount = await db
.delete(financeAccount)
.where(eq(financeAccount.id, id))
.where(eq(financeAccount.financeAccountId, id))
.returning();

if (deletedAccount.length === 0) {
Expand Down Expand Up @@ -80,11 +80,11 @@ export async function PUT(
const updatedAccount = await db
.update(financeAccount)
.set({
id: requestBody.id,
financeAccountId: requestBody.financeAccountId,
studentId: requestBody.studentId,
hasOutstandingBalance: requestBody.hasOutstandingBalance,
})
.where(eq(financeAccount.id, params.id))
.where(eq(financeAccount.financeAccountId, params.id))
.returning();

if (updatedAccount.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion apps/finance/src/app/api/invoices/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function GET(
const id = params.id;

const currentInvoice = await db.query.invoice.findFirst({
where: eq(invoice.id, id),
where: eq(invoice.invoiceId, id),
});

return Response.json(currentInvoice, { status: 200 });
Expand Down
2 changes: 1 addition & 1 deletion apps/finance/src/app/api/invoices/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type RequestBody = typeof invoice.$inferInsert;

export async function GET(_request: Request) {
const allInvoices = await db.query.invoice.findMany({
orderBy: [asc(invoice.id)],
orderBy: [asc(invoice.invoiceId)],
});

return Response.json({ data: allInvoices }, { status: 200 });
Expand Down
3 changes: 3 additions & 0 deletions apps/finance/src/server/db/migrations/0005_late_whistler.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "finance_account" RENAME COLUMN "id" TO "finance_account_id";--> statement-breakpoint
ALTER TABLE "invoice" RENAME COLUMN "id" TO "invoice_id";--> statement-breakpoint
ALTER TABLE "transaction" RENAME COLUMN "id" TO "transaction_id";
Loading

0 comments on commit 424cd10

Please sign in to comment.