WIP: Implement backend in express
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
03bfd1bed3
commit
621782a3a8
13 changed files with 218 additions and 0 deletions
29
src/server/budget/controller.ts
Normal file
29
src/server/budget/controller.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import express from 'express';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id/balance', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.put('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
export { router };
|
8
src/server/budget/model.ts
Normal file
8
src/server/budget/model.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { randomId } from '../utils';
|
||||
|
||||
export class Budget {
|
||||
id: string = randomId();
|
||||
name: string;
|
||||
description: string;
|
||||
currencyCode: string;
|
||||
}
|
4
src/server/budget/repository.ts
Normal file
4
src/server/budget/repository.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
export class BudgetRepository {
|
||||
|
||||
}
|
25
src/server/categories/controller.ts
Normal file
25
src/server/categories/controller.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import express from 'express';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.put('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
export { router };
|
16
src/server/db/index.ts
Normal file
16
src/server/db/index.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import path from 'path';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import * as migrations from './migrations';
|
||||
|
||||
|
||||
export function db(dataDir: string): sqlite3.Database {
|
||||
const db = new sqlite3.Database(path.join(dataDir, "twigs.db"), (err) => {
|
||||
if (err != null) {
|
||||
console.error("Failed to open db");
|
||||
console.error(err);
|
||||
throw 'Failed to open db';
|
||||
}
|
||||
|
||||
});
|
||||
return db
|
||||
}
|
0
src/server/db/migrations.ts
Normal file
0
src/server/db/migrations.ts
Normal file
34
src/server/index.ts
Normal file
34
src/server/index.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import express from 'express';
|
||||
import { router as budgetRouter } from './budget/controller'
|
||||
import { router as categoryRouter } from './categories/controller'
|
||||
import { router as permissionsRouter } from './permissions/controller'
|
||||
import { router as transactionRouter } from './transactions/controller'
|
||||
import { router as userRouter } from './users/controller'
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
const app = express();
|
||||
|
||||
const dataDir = process.env.TWIGS_DATA || __dirname;
|
||||
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
// app.get('/', (req, res) => {
|
||||
// console.log('hit: /');
|
||||
// res.send('test');
|
||||
// })
|
||||
|
||||
app.use('/api/budgets', budgetRouter);
|
||||
app.use('/api/categories', categoryRouter);
|
||||
app.use('/api/permissions', permissionsRouter);
|
||||
app.use('/api/transactions', transactionRouter);
|
||||
app.use('/api/users', userRouter);
|
||||
|
||||
app.get('/*', (req, res) => {
|
||||
res.sendFile(__dirname + '/public/index.html');
|
||||
});
|
||||
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Twigs server listening at http://localhost:${port}`)
|
||||
console.log(`Serving static content from ${__dirname}/public`)
|
||||
});
|
25
src/server/permissions/controller.ts
Normal file
25
src/server/permissions/controller.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import express from 'express';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.put('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
export { router };
|
25
src/server/transactions/controller.ts
Normal file
25
src/server/transactions/controller.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import express from 'express';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.put('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
export { router };
|
20
src/server/tsconfig.json
Normal file
20
src/server/tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "../../dist",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": [
|
||||
"node_modules/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"**/*"
|
||||
]
|
||||
}
|
0
src/server/tslint.json
Normal file
0
src/server/tslint.json
Normal file
25
src/server/users/controller.ts
Normal file
25
src/server/users/controller.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import express from 'express';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.put('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
export { router };
|
7
src/server/utils.ts
Normal file
7
src/server/utils.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { randomInt } from 'crypto';
|
||||
|
||||
const CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
|
||||
export function randomId(length = 32): string {
|
||||
return Array.from(new Array(length), () => { CHARACTERS[randomInt(CHARACTERS.length)] }).join('');
|
||||
}
|
Loading…
Reference in a new issue