mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-26 18:55:12 +02:00
feat: add development database
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export const NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
export const ENV = process.env.NODE_ENV || 'production';
|
||||
export const JWT_SECRET =
|
||||
process.env.SECRET ||
|
||||
(NODE_ENV === 'development'
|
||||
(ENV === 'development'
|
||||
? 'secret'
|
||||
: Math.random().toString(36).substring(2, 15));
|
||||
export const TMDB_API_KEY =
|
||||
@@ -9,7 +9,6 @@ export const TMDB_API_KEY =
|
||||
'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI0YTZiMDIxZTE5Y2YxOTljMTM1NGFhMGRiMDZiOTkzMiIsInN1YiI6IjY0ODYzYWRmMDI4ZjE0MDExZTU1MDkwMiIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.yyMkZlhGOGBHtw1yvpBVUUHhu7IKVYho49MvNNKt_wY';
|
||||
export const ADMIN_USERNAME = process.env.ADMIN_USERNAME;
|
||||
export const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
|
||||
export const ENV = process.env.NODE_ENV || 'development';
|
||||
export const TMDB_CACHE_TTL = Number.isNaN(Number(process.env.TMDB_CACHE_TTL))
|
||||
? 1000 * 60 * 60 * 24 * 3 // 3 days
|
||||
: Number(process.env.TMDB_CACHE_TTL);
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'reflect-metadata';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import * as fs from 'fs';
|
||||
import { UsersService } from './users/users.service';
|
||||
import { ADMIN_PASSWORD, ADMIN_USERNAME, ENV, NODE_ENV } from './consts';
|
||||
import { ADMIN_PASSWORD, ADMIN_USERNAME, ENV } from './consts';
|
||||
import { json, urlencoded } from 'express';
|
||||
// import * as proxy from 'express-http-proxy';
|
||||
require('ts-node/register'); // For importing plugins
|
||||
@@ -49,7 +49,7 @@ async function bootstrap() {
|
||||
|
||||
await app.listen(9494);
|
||||
console.log(
|
||||
`Application is running on: ${await app.getUrl()} in ${NODE_ENV} mode`,
|
||||
`Application is running on: ${await app.getUrl()} in ${ENV} mode`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export class UserDto extends OmitType(User, [
|
||||
// pluginSettings: entity.pluginSettings,
|
||||
};
|
||||
|
||||
delete out.password;
|
||||
delete (out as any).password;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,10 @@ export class UsersController {
|
||||
else throw new InternalServerErrorException();
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
|
||||
return UserDto.fromEntity(user);
|
||||
}
|
||||
|
||||
@@ -132,6 +136,10 @@ export class UsersController {
|
||||
} else throw new InternalServerErrorException();
|
||||
});
|
||||
|
||||
if (!updated) {
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
|
||||
return UserDto.fromEntity(updated);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,30 +33,34 @@ export class UsersService {
|
||||
);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<User> {
|
||||
return this.userRepository
|
||||
.findOne({
|
||||
where: { id },
|
||||
relations: {
|
||||
mediaSources: true,
|
||||
},
|
||||
})
|
||||
.then((u) => this.filterMediaSources(u));
|
||||
async findOne(id: string): Promise<User | undefined> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { id },
|
||||
relations: {
|
||||
mediaSources: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) return undefined;
|
||||
|
||||
return this.filterMediaSources(user);
|
||||
}
|
||||
|
||||
async findOneByName(name: string): Promise<User> {
|
||||
return this.userRepository
|
||||
.findOne({
|
||||
where: { name },
|
||||
relations: {
|
||||
mediaSources: true,
|
||||
},
|
||||
})
|
||||
.then((u) => this.filterMediaSources(u));
|
||||
async findOneByName(name: string): Promise<User | undefined> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { name },
|
||||
relations: {
|
||||
mediaSources: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) return undefined;
|
||||
|
||||
return this.filterMediaSources(user);
|
||||
}
|
||||
|
||||
// The rest
|
||||
async create(userCreateDto: CreateUserDto): Promise<User> {
|
||||
async create(userCreateDto: CreateUserDto): Promise<User | undefined> {
|
||||
if (!userCreateDto.name) throw UserServiceError.UsernameRequired;
|
||||
|
||||
const user = this.userRepository.create();
|
||||
@@ -67,7 +71,7 @@ export class UsersService {
|
||||
|
||||
try {
|
||||
user.profilePicture = Buffer.from(
|
||||
userCreateDto.profilePicture.split(';base64,').pop() as string,
|
||||
userCreateDto.profilePicture?.split(';base64,').pop() as string,
|
||||
'base64',
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -82,7 +86,7 @@ export class UsersService {
|
||||
userId: string,
|
||||
callerUser: User,
|
||||
updateUserDto: UpdateUserDto,
|
||||
): Promise<User> {
|
||||
): Promise<User | undefined> {
|
||||
const user = await this.userRepository.findOne({ where: { id: userId } });
|
||||
|
||||
if (!user) throw new Error('Update user: User not found');
|
||||
|
||||
Reference in New Issue
Block a user