mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(api-user): add basic User Entity and basic routing to fetch all users
This commit is contained in:
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@@ -6,5 +6,13 @@
|
|||||||
"typescript",
|
"typescript",
|
||||||
"typescriptreact"
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
16
ormconfig.js
16
ormconfig.js
@@ -3,11 +3,11 @@ const devConfig = {
|
|||||||
database: 'db/db.sqlite3',
|
database: 'db/db.sqlite3',
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: true,
|
logging: true,
|
||||||
entities: ['src/entity/**/*.ts'],
|
entities: ['server/entity/**/*.ts'],
|
||||||
migrations: ['src/migration/**/*.ts'],
|
migrations: ['server/migration/**/*.ts'],
|
||||||
cli: {
|
cli: {
|
||||||
entitiesDir: 'src/entity',
|
entitiesDir: 'server/entity',
|
||||||
migrationsDir: 'src/migration',
|
migrationsDir: 'server/migration',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,12 +16,12 @@ const prodConfig = {
|
|||||||
database: 'db/db.sqlite3',
|
database: 'db/db.sqlite3',
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging: false,
|
logging: false,
|
||||||
entities: ['dist/entity/**/*.js'],
|
entities: ['dist/server/entity/**/*.js'],
|
||||||
migrations: ['dist/migration/**/*.js'],
|
migrations: ['dist/server/migration/**/*.js'],
|
||||||
migrationsRun: true,
|
migrationsRun: true,
|
||||||
cli: {
|
cli: {
|
||||||
entitiesDir: 'dist/entity',
|
entitiesDir: 'dist/server/entity',
|
||||||
migrationsDir: 'dist/migration',
|
migrationsDir: 'dist/server/migration',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon -e ts -x ts-node --project tsconfig.server.json server/index.ts",
|
"dev": "nodemon -e ts -x ts-node --project server/tsconfig.json server/index.ts",
|
||||||
"build:server": "tsc --project tsconfig.server.json",
|
"build:server": "tsc --project server/tsconfig.json",
|
||||||
"build:next": "next build",
|
"build:next": "next build",
|
||||||
"build": "yarn build:next && yarn build:server",
|
"build": "yarn build:next && yarn build:server",
|
||||||
"start": "NODE_ENV=production node dist/server/index.js"
|
"start": "NODE_ENV=production node dist/server/index.js"
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
"next": "9.5.2",
|
"next": "9.5.2",
|
||||||
"react": "16.13.1",
|
"react": "16.13.1",
|
||||||
"react-dom": "16.13.1",
|
"react-dom": "16.13.1",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
"sqlite3": "^5.0.0",
|
"sqlite3": "^5.0.0",
|
||||||
"typeorm": "^0.2.25"
|
"typeorm": "^0.2.25"
|
||||||
},
|
},
|
||||||
|
29
server/entity/User.ts
Normal file
29
server/entity/User.ts
Normal file
@@ -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 express from 'express';
|
||||||
import next from 'next';
|
import next from 'next';
|
||||||
import { createConnection } from 'typeorm';
|
import { createConnection } from 'typeorm';
|
||||||
|
import routes from './routes';
|
||||||
|
|
||||||
const dev = process.env.NODE_ENV !== 'production';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
const app = next({ dev });
|
const app = next({ dev });
|
||||||
@@ -12,9 +13,7 @@ app
|
|||||||
.prepare()
|
.prepare()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const server = express();
|
const server = express();
|
||||||
server.get('/api', (req, res) => {
|
server.use('/api', routes);
|
||||||
res.json({ worked: true });
|
|
||||||
});
|
|
||||||
server.get('*', (req, res) => handle(req, res));
|
server.get('*', (req, res) => handle(req, res));
|
||||||
|
|
||||||
const port = Number(process.env.PORT) || 3000;
|
const port = Number(process.env.PORT) || 3000;
|
||||||
|
15
server/routes/index.ts
Normal file
15
server/routes/index.ts
Normal file
@@ -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;
|
15
server/routes/user.ts
Normal file
15
server/routes/user.ts
Normal file
@@ -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;
|
11
server/tsconfig.json
Normal file
11
server/tsconfig.json
Normal file
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user