Skip to content
Closed
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,29 @@ jobs:
run: npm run api:prisma:migrate:deploy
env:
DATABASE_URL: postgresql://test:test@localhost:5432/fintrack_test

- name: Run API tests
run: npm --prefix apps/api run test
env:
DATABASE_URL: postgresql://test:test@localhost:5432/fintrack_test
DATABASE_URL: postgresql://test:test@localhost:5432/fintrack_test

docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image (web)
uses: docker/build-push-action@v5
with:
context: .
file: apps/web/Dockerfile
push: false
build-args: |
NEXT_PUBLIC_API_URL=http://localhost:8000/api
tags: fintrack-web:ci
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "rimraf dist && npx tsc",
"start": "node dist/server.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --runInBand",
"test:watch": "jest --watch",
"predev": "npm run build",
"dev": "concurrently \"npx tsc -w\" \"nodemon --ext js,yml dist/server.js\"",
Expand Down
25 changes: 3 additions & 22 deletions apps/api/src/modules/ai/controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Request, Response, NextFunction } from "express";
import { AppError } from "../../middleware/errorHandler.js";
import { prisma } from "../../prisma/client.js";
import {
getAiResponse,
getAIHistory as getAIHistoryFromService,
AiServiceError,
ensureAiAccessOrThrow,
getAiAccessStatus,
Expand All @@ -19,27 +19,8 @@ export async function getAIHistory(
if (!userId)
throw new AppError("Unauthorized: User not found in request", 401);

const messages = await prisma.message.findMany({
where: { userId },
orderBy: { created_at: "asc" },
});

const paired = [];
for (let i = 0; i < messages.length; i++) {
const currentMsg = messages[i];
if (currentMsg && currentMsg.role === "user") {
const nextMsg = messages[i + 1];
paired.push({
id: currentMsg.id,
prompt: currentMsg.content,
result: nextMsg?.role === "assistant" ? nextMsg.content : "",
created_at: currentMsg.created_at,
});
if (nextMsg?.role === "assistant") i++;
}
}

return res.json(paired.reverse());
const history = await getAIHistoryFromService(userId);
return res.json(history);
} catch (err) {
next(err);
}
Expand Down
24 changes: 24 additions & 0 deletions apps/api/src/modules/ai/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ export async function incrementAiAnalysisUsage(
});
}

export async function getAIHistory(userId: string) {
const messages = await prisma.message.findMany({
where: { userId },
orderBy: { created_at: "asc" },
});

const paired = [];
for (let i = 0; i < messages.length; i++) {
const currentMsg = messages[i];
if (currentMsg && currentMsg.role === "user") {
const nextMsg = messages[i + 1];
paired.push({
id: currentMsg.id,
prompt: currentMsg.content,
result: nextMsg?.role === "assistant" ? nextMsg.content : "",
created_at: currentMsg.created_at,
});
if (nextMsg?.role === "assistant") i++;
}
}

return paired.reverse();
}

async function callGroq(
apiKey: string,
modelToUse: string,
Expand Down
9 changes: 1 addition & 8 deletions apps/api/src/modules/donation/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Stripe from "stripe";
import { Prisma } from "@prisma/client";
import type { DonationLeaderboardItem } from "@fintrack/types";
import { ENV } from "../../config/env.js";
import { prisma } from "../../prisma/client.js";
import { AppError } from "../../middleware/errorHandler.js";
Expand Down Expand Up @@ -180,14 +181,6 @@ export async function createDonationCheckoutSession(
};
}

export interface DonationLeaderboardItem {
userId: string;
name: string;
photoUrl: string | null;
totalAmountMinor: number;
currency: string;
}

export async function getDonationLeaderboard(
limit = 20,
): Promise<DonationLeaderboardItem[]> {
Expand Down
Loading
Loading