Skip to content

Commit

Permalink
adapt ci to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mikonse committed Oct 13, 2022
1 parent e187e91 commit 959a6f6
Show file tree
Hide file tree
Showing 46 changed files with 556 additions and 1,190 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,18 @@ jobs:
run: npm --prefix frontend install
- name: Check JavaScript formatting
run: make check-format-frontend

build-web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Nodejs
uses: actions/setup-node@v2
with:
node-version: "16"
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm --prefix frontend install
- name: Build web app
run: cd frontend && npx nx build web && cd ..
2 changes: 1 addition & 1 deletion abrechnung/application/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ async def sync_account(
conn=conn,
user=user,
group_id=account.group_id,
type=account.type,
type=account.type.value,
name=account.name,
description=account.description,
owning_user_id=account.owning_user_id,
Expand Down
4 changes: 2 additions & 2 deletions abrechnung/application/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ async def update_transaction(
billed_at=billed_at,
currency_symbol=currency_symbol,
currency_conversion_rate=currency_conversion_rate,
debitor_shares=debu,
debitor_shares=debitor_shares,
creditor_shares=creditor_shares,
positions=positions,
perform_commit=perform_commit,
Expand All @@ -850,7 +850,7 @@ async def update_transaction_positions(
user=user,
transaction_id=transaction_id,
can_write=True,
transaction_type=TransactionType.purchase.value(),
transaction_type=TransactionType.purchase.value,
)
revision_id = await self._get_or_create_revision(
conn=conn, user=user, transaction_id=transaction_id
Expand Down
2 changes: 1 addition & 1 deletion abrechnung/http/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def sync_accounts(request: web.Request):
updated_ids = await request.app["account_service"].sync_accounts(
user=request["user"],
group_id=int(request.match_info["group_id"]),
accounts=request["json"] # TODO: FIXME, convert to proper parameters
accounts=request["json"], # TODO: FIXME, convert to proper parameters
)

await json_response(data=updated_ids)
Expand Down
14 changes: 7 additions & 7 deletions abrechnung/http/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from marshmallow import Schema, fields

from abrechnung.http.openapi import docs, json_schema
from abrechnung.http.serializers import TransactionSchema, TransactionPositionSchema, SharesField
from abrechnung.http.serializers import (
TransactionSchema,
TransactionPositionSchema,
SharesField,
)
from abrechnung.http.utils import json_response, PrefixedRouteTableDef

routes = PrefixedRouteTableDef("/api")
Expand Down Expand Up @@ -75,17 +79,13 @@ async def list_transactions(request):


@routes.post(r"/v1/groups/{group_id:\d+}/transactions/sync")
@docs(
tags=["transactions"],
summary="sync a batch of transactions",
description=""
)
@docs(tags=["transactions"], summary="sync a batch of transactions", description="")
@json_schema(TransactionUpdateScheme(many=True))
async def sync_transactions(request: Request):
updated_ids = await request.app["transaction_service"].sync_transactions(
user=request["user"],
group_id=int(request.match_info["group_id"]),
transactions=request["json"] # TODO: FIXME, convert to proper parameters
transactions=request["json"], # TODO: FIXME, convert to proper parameters
)

await json_response(data=updated_ids)
Expand Down
4 changes: 2 additions & 2 deletions debian/build_virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ interest dh-virtualenv-interpreter-update
EOF

export DESTDIR="debian/abrechnung"
cd web && yarn install && yarn build && cd ..
cd frontend && npm install && npx nx build web && cd ..
mkdir -p $DESTDIR/usr/share/
mv web/build $DESTDIR/usr/share/abrechnung_web
mv frontend/dist/web $DESTDIR/usr/share/abrechnung_web

#mkdir -p $DESTDIR/etc/abrechnung
#mkdir -p $DESTDIR/etc/nginx/sites-available
Expand Down
3 changes: 1 addition & 2 deletions debian/source/options
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
tar-ignore = "web/node_modules"
tar-ignore = "frontend/node_modules"
tar-ignore = ".git"
tar-ignore = ".pybuild"
tar-ignore = "web/yarn-error.log"
tar-ignore = "config.yaml"
tar-ignore = ".idea"
tar-ignore = "docs/_build"
Expand Down
18 changes: 18 additions & 0 deletions frontend/apps/backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
16 changes: 16 additions & 0 deletions frontend/apps/backend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: "backend",
preset: "../../jest.preset.js",
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
},
},
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": "ts-jest",
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/apps/backend",
};
60 changes: 60 additions & 0 deletions frontend/apps/backend/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "backend",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/backend/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/backend",
"main": "apps/backend/src/main.ts",
"tsConfig": "apps/backend/tsconfig.app.json",
"assets": ["apps/backend/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/backend/src/environments/environment.ts",
"with": "apps/backend/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"executor": "@nrwl/js:node",
"options": {
"buildTarget": "backend:build"
},
"configurations": {
"production": {
"buildTarget": "backend:build:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/backend/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/backend"],
"options": {
"jestConfig": "apps/backend/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
3 changes: 3 additions & 0 deletions frontend/apps/backend/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true,
};
3 changes: 3 additions & 0 deletions frontend/apps/backend/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: false,
};
18 changes: 18 additions & 0 deletions frontend/apps/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import * as express from "express";

const app = express();

app.get("/api", (req, res) => {
res.send({ message: "Welcome to backend!" });
});

const port = process.env.port || 3333;
const server = app.listen(port, () => {
console.log(`Listening at http://localhost:${port}/api`);
});
server.on("error", console.error);
10 changes: 10 additions & 0 deletions frontend/apps/backend/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node", "express"]
},
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
13 changes: 13 additions & 0 deletions frontend/apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions frontend/apps/backend/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
1 change: 1 addition & 0 deletions frontend/apps/mobile/src/core/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { accountNotifier, getAccount, getAccounts } from "./database/accounts";
import { positionState, transactionState } from "./transactions";
import { computeAccountBalances } from "@abrechnung/core";
import { useNavigation } from "@react-navigation/native";
import { RootDrawerNavigationProp } from "../navigation/types";

function filterAccounts(account: Account[]): Account[] {
return account.filter((a) => !a.deleted);
Expand Down
36 changes: 26 additions & 10 deletions frontend/apps/mobile/src/core/database/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,29 @@ const saveAccountToDatabase = async (account: Account, conn?: Connection) => {
};

export const syncAccounts = async (groupID: number): Promise<Account[]> => {
const backendAccounts = await api.fetchAccounts(groupID);
let backendAccounts = await api.fetchAccounts(groupID);
await db.transaction((conn: Connection) => {
backendAccounts.forEach((account: Account) => {
saveAccountToDatabase(account, conn);
});
});
// TODO: upload pending changes to server

// TODO: resolve conflicts after fetching accounts
const accounts = await getAccounts(groupID);
const accountsWithLocalChanges = accounts.filter((a: Account) => a.hasLocalChanges);
if (accountsWithLocalChanges.length > 0) {
await api.syncAccountsBatch(groupID, accountsWithLocalChanges);
backendAccounts = await api.fetchAccounts(groupID);
await db.transaction(async (conn: Connection) => {
await Promise.all(
backendAccounts.map((account: Account) => {
return saveAccountToDatabase(account, conn);
})
);
await conn.execute(`delete from pending_account_changes where group_id = ?1`, [groupID]);
});
}

accountNotifier.emit("changed", { groupID: groupID });
return backendAccounts;
};
Expand Down Expand Up @@ -266,7 +282,7 @@ export const pushPendingAccountChanges = async (groupID: number): Promise<void>
});
};

export const pushLocalAccountChanges = async (account_id: number): Promise<Account> => {
export const pushLocalAccountChanges = async (accountID: number): Promise<Account> => {
if (!(await isOnline())) {
console.log("cannot push changes to server as we are offline");
throw Error("Cannot push local changes to server as we are offline");
Expand All @@ -284,15 +300,15 @@ export const pushLocalAccountChanges = async (account_id: number): Promise<Accou
order by
event_time desc
limit 1`,
[account_id]
[accountID]
);
if (accountQueryResult.rows.length === 0) {
return;
}

console.log("pushing transaction detail plus position changes to server");
const t = accountQueryResult.rows[0];
const account = accountFromEvent(account_id, t.group_id, t.event_time, JSON.parse(t.event_content));
const account = accountFromEvent(accountID, t.group_id, t.event_time, JSON.parse(t.event_content));
const updatedAccount = await api.pushAccountChanges(account);
await conn.execute(
`
Expand All @@ -302,7 +318,7 @@ export const pushLocalAccountChanges = async (account_id: number): Promise<Accou
where
account_id = ?1
`,
[account_id]
[accountID]
);
await saveAccountToDatabase(updatedAccount, conn);
console.log("successfully synced local changes with server and saved the result to local database");
Expand Down Expand Up @@ -410,12 +426,12 @@ export const createAccount = async (groupID: number, type: AccountType): Promise
});
};

export const deleteAccount = async (group_id: number, account_id: number) => {
if (account_id < 0) {
return await deleteLocalAccountChanges(group_id, account_id);
export const deleteAccount = async (groupID: number, accountID: number) => {
if (accountID < 0) {
return await deleteLocalAccountChanges(groupID, accountID);
}

const account = await getAccount(group_id, account_id);
const account = await getAccount(groupID, accountID);
account.deleted = true;
return await updateAccount(account);
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/apps/mobile/src/core/groups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { atom, selector, selectorFamily, useRecoilValue } from "recoil";
import { atom, RecoilState, selector, selectorFamily, useRecoilValue } from "recoil";
import { getGroups, groupNotifier } from "./database/groups";
import { Group } from "@abrechnung/types";
import { useNavigation } from "@react-navigation/native";
Expand All @@ -8,7 +8,7 @@ export const activeGroupIDState = atom<number | null>({
default: null,
});

export const groupState = atom<Group[]>({
export const groupState: RecoilState<Group[]> = atom<Group[]>({
key: "groupState",
default: getGroups(),
effects: [
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/mobile/src/core/sync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { syncGroups } from "./database/groups";
import { syncAccounts } from "./database/accounts";
import { syncTransactions } from "./database/transactions";
import { Group } from "@abrechnung/types";

export async function syncLocalState() {
await syncGroups();
export async function syncLocalState(): Promise<Group[]> {
return await syncGroups();
}

export async function syncLocalGroupState(groupID: number) {
Expand Down
Loading

0 comments on commit 959a6f6

Please sign in to comment.