feat(api-user): add basic User Entity and basic routing to fetch all users

pull/3/head
sct 4 years ago
parent ccfd223f0f
commit d902ef7277

@ -6,5 +6,13 @@
"typescript",
"typescriptreact"
],
"typescript.tsdk": "./app/node_modules/typescript/lib"
"typescript.tsdk": "./app/node_modules/typescript/lib",
"sqltools.connections": [
{
"previewLimit": 50,
"driver": "SQLite",
"name": "Local SQLite",
"database": "./db/db.sqlite3"
}
]
}

@ -3,11 +3,11 @@ const devConfig = {
database: 'db/db.sqlite3',
synchronize: true,
logging: true,
entities: ['src/entity/**/*.ts'],
migrations: ['src/migration/**/*.ts'],
entities: ['server/entity/**/*.ts'],
migrations: ['server/migration/**/*.ts'],
cli: {
entitiesDir: 'src/entity',
migrationsDir: 'src/migration',
entitiesDir: 'server/entity',
migrationsDir: 'server/migration',
},
};
@ -16,12 +16,12 @@ const prodConfig = {
database: 'db/db.sqlite3',
synchronize: false,
logging: false,
entities: ['dist/entity/**/*.js'],
migrations: ['dist/migration/**/*.js'],
entities: ['dist/server/entity/**/*.js'],
migrations: ['dist/server/migration/**/*.js'],
migrationsRun: true,
cli: {
entitiesDir: 'dist/entity',
migrationsDir: 'dist/migration',
entitiesDir: 'dist/server/entity',
migrationsDir: 'dist/server/migration',
},
};

@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "nodemon -e ts -x ts-node --project tsconfig.server.json server/index.ts",
"build:server": "tsc --project tsconfig.server.json",
"dev": "nodemon -e ts -x ts-node --project server/tsconfig.json server/index.ts",
"build:server": "tsc --project server/tsconfig.json",
"build:next": "next build",
"build": "yarn build:next && yarn build:server",
"start": "NODE_ENV=production node dist/server/index.js"
@ -14,6 +14,7 @@
"next": "9.5.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.0",
"typeorm": "^0.2.25"
},

@ -0,0 +1,29 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
public id: number;
@Column({ unique: true })
public email: string;
@Column({ nullable: true })
public plexToken: string;
@CreateDateColumn()
public createdAt: Date;
@UpdateDateColumn()
public updatedAt: Date;
constructor(init?: Partial<User>) {
Object.assign(this, init);
}
}

@ -1,6 +1,7 @@
import express from 'express';
import next from 'next';
import { createConnection } from 'typeorm';
import routes from './routes';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
@ -12,9 +13,7 @@ app
.prepare()
.then(() => {
const server = express();
server.get('/api', (req, res) => {
res.json({ worked: true });
});
server.use('/api', routes);
server.get('*', (req, res) => handle(req, res));
const port = Number(process.env.PORT) || 3000;

@ -0,0 +1,15 @@
import { Router } from 'express';
import user from './user';
const router = Router();
router.use('/user', user);
router.get('/', (req, res) => {
return res.status(200).json({
api: 'Overseerr API',
version: '1.0',
});
});
export default router;

@ -0,0 +1,15 @@
import { Router } from 'express';
import { getRepository } from 'typeorm';
import { User } from '../entity/User';
const router = Router();
router.get('/', async (req, res) => {
const userRepository = getRepository(User);
const users = await userRepository.find();
return res.status(200).json(users);
});
export default router;

@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../dist",
"noEmit": false,
"strictPropertyInitialization": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}

@ -1,8 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"noEmit": false
}
}
Loading…
Cancel
Save