Make all services readonly

This commit is contained in:
rubikscraft 2022-06-27 17:37:37 +02:00
parent 34eeb11930
commit ba47d0bff4
No known key found for this signature in database
GPG key ID: 1463EBE9200A5CD4
73 changed files with 201 additions and 185 deletions

View file

@ -11,13 +11,13 @@ import { EImageBackend } from '../../models/entities/image.entity';
export class ImageDBService {
constructor(
@InjectRepository(EImageBackend)
private imageRepo: Repository<EImageBackend>,
private readonly imageRepo: Repository<EImageBackend>,
@InjectRepository(EImageFileBackend)
private imageFileRepo: Repository<EImageFileBackend>,
private readonly imageFileRepo: Repository<EImageFileBackend>,
@InjectRepository(EImageDerivativeBackend)
private imageDerivativeRepo: Repository<EImageDerivativeBackend>,
private readonly imageDerivativeRepo: Repository<EImageDerivativeBackend>,
) {}
public async create(userid: string): AsyncFailable<EImageBackend> {

View file

@ -12,10 +12,10 @@ const A_DAY_IN_SECONDS = 24 * 60 * 60;
export class ImageFileDBService {
constructor(
@InjectRepository(EImageFileBackend)
private imageFileRepo: Repository<EImageFileBackend>,
private readonly imageFileRepo: Repository<EImageFileBackend>,
@InjectRepository(EImageDerivativeBackend)
private imageDerivativeRepo: Repository<EImageDerivativeBackend>,
private readonly imageDerivativeRepo: Repository<EImageDerivativeBackend>,
) {}
public async setFile(
@ -68,7 +68,7 @@ export class ImageFileDBService {
});
if (!found) return Fail('Image not found');
const result: { [key in ImageFileType]?: string } = {};
for (const file of found) {
result[file.type] = file.mime;

View file

@ -13,7 +13,7 @@ import { EarlyJwtConfigService } from '../../config/early/early-jwt.config.servi
export class PreferenceDefaultsService {
private readonly logger = new Logger('PreferenceDefaultsService');
constructor(private jwtConfigService: EarlyJwtConfigService) {}
constructor(private readonly jwtConfigService: EarlyJwtConfigService) {}
public readonly usrDefaults: {
[key in UsrPreference]: () => PrefValueType;

View file

@ -26,9 +26,9 @@ export class SysPreferenceService {
constructor(
@InjectRepository(ESysPreferenceBackend)
private sysPreferenceRepository: Repository<ESysPreferenceBackend>,
private defaultsService: PreferenceDefaultsService,
private prefCommon: PreferenceCommonService,
private readonly sysPreferenceRepository: Repository<ESysPreferenceBackend>,
private readonly defaultsService: PreferenceDefaultsService,
private readonly prefCommon: PreferenceCommonService,
) {}
public async setPreference(

View file

@ -26,9 +26,9 @@ export class UsrPreferenceService {
constructor(
@InjectRepository(EUsrPreferenceBackend)
private usrPreferenceRepository: Repository<EUsrPreferenceBackend>,
private defaultsService: PreferenceDefaultsService,
private prefCommon: PreferenceCommonService,
private readonly usrPreferenceRepository: Repository<EUsrPreferenceBackend>,
private readonly defaultsService: PreferenceDefaultsService,
private readonly prefCommon: PreferenceCommonService,
) {}
public async setPreference(

View file

@ -6,7 +6,7 @@ import { HostConfigService } from '../../config/early/host.config.service';
import {
ImmutableRolesList,
SystemRoleDefaults,
UndeletableRolesList,
UndeletableRolesList
} from '../../models/constants/roles.const';
import { ERoleBackend } from '../../models/entities/role.entity';
import { RolesService } from './role-db.service';
@ -20,8 +20,8 @@ export class RolesModule implements OnModuleInit {
private readonly logger = new Logger('RolesModule');
constructor(
private rolesService: RolesService,
private hostConfig: HostConfigService,
private readonly rolesService: RolesService,
private readonly hostConfig: HostConfigService,
) {}
async onModuleInit() {

View file

@ -5,14 +5,14 @@ import {
AsyncFailable,
Fail,
HasFailed,
HasSuccess,
HasSuccess
} from 'picsur-shared/dist/types';
import { makeUnique } from 'picsur-shared/dist/util/unique';
import { In, Repository } from 'typeorm';
import { Permissions } from '../../models/constants/permissions.const';
import {
ImmutableRolesList,
UndeletableRolesList,
UndeletableRolesList
} from '../../models/constants/roles.const';
import { ERoleBackend } from '../../models/entities/role.entity';
@ -22,7 +22,7 @@ export class RolesService {
constructor(
@InjectRepository(ERoleBackend)
private rolesRepository: Repository<ERoleBackend>,
private readonly rolesRepository: Repository<ERoleBackend>,
) {}
public async create(

View file

@ -23,8 +23,8 @@ export class UsersModule implements OnModuleInit {
private readonly logger = new Logger('UsersModule');
constructor(
private usersService: UsersService,
private authConfigService: AuthConfigService,
private readonly usersService: UsersService,
private readonly authConfigService: AuthConfigService,
) {}
async onModuleInit() {

View file

@ -32,9 +32,9 @@ export class UsersService {
constructor(
@InjectRepository(EUserBackend)
private usersRepository: Repository<EUserBackend>,
private rolesService: RolesService,
private prefService: SysPreferenceService,
private readonly usersRepository: Repository<EUserBackend>,
private readonly rolesService: RolesService,
private readonly prefService: SysPreferenceService,
) {}
// Creation and deletion

View file

@ -4,7 +4,7 @@ import { EnvPrefix } from '../config.static';
@Injectable()
export class AuthConfigService {
constructor(private configService: ConfigService) {}
constructor(private readonly configService: ConfigService) {}
public getDefaultAdminPassword(): string {
return this.configService.get<string>(

View file

@ -4,7 +4,7 @@ import { EnvPrefix } from '../config.static';
@Injectable()
export class EarlyJwtConfigService {
constructor(private configService: ConfigService) {}
constructor(private readonly configService: ConfigService) {}
public getJwtSecret(): string | undefined {
return this.configService.get<string>(`${EnvPrefix}JWT_SECRET`);

View file

@ -6,7 +6,7 @@ import { EnvPrefix } from '../config.static';
export class HostConfigService {
private readonly logger = new Logger('HostConfigService');
constructor(private configService: ConfigService) {
constructor(private readonly configService: ConfigService) {
this.logger.log('Host: ' + this.getHost());
this.logger.log('Port: ' + this.getPort());
this.logger.log('Demo: ' + this.isDemo());

View file

@ -6,7 +6,7 @@ import { EnvPrefix } from '../config.static';
export class MultipartConfigService {
private readonly logger = new Logger('MultipartConfigService');
constructor(private configService: ConfigService) {
constructor(private readonly configService: ConfigService) {
this.logger.log('Max file size: ' + this.getMaxFileSize());
}

View file

@ -2,7 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
ServeStaticModuleOptions,
ServeStaticModuleOptionsFactory,
ServeStaticModuleOptionsFactory
} from '@nestjs/serve-static';
import { join } from 'path';
import { EnvPrefix, PackageRoot } from '../config.static';
@ -15,7 +15,7 @@ export class ServeStaticConfigService
private defaultLocation = join(PackageRoot, '../frontend/dist');
constructor(private configService: ConfigService) {
constructor(private readonly configService: ConfigService) {
this.logger.log('Static directory: ' + this.getStaticDirectory());
}

View file

@ -10,8 +10,8 @@ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
private readonly logger = new Logger('TypeOrmConfigService');
constructor(
private configService: ConfigService,
private hostService: HostConfigService,
private readonly configService: ConfigService,
private readonly hostService: HostConfigService,
) {
const varOptions = this.getTypeOrmServerOptions();

View file

@ -7,7 +7,7 @@ import { SysPreferenceService } from '../../collections/preference-db/sys-prefer
export class JwtConfigService implements JwtOptionsFactory {
private readonly logger = new Logger('JwtConfigService');
constructor(private prefService: SysPreferenceService) {
constructor(private readonly prefService: SysPreferenceService) {
this.printDebug().catch(this.logger.error);
}

View file

@ -19,8 +19,8 @@ export class LateConfigModule implements OnModuleInit {
private readonly logger = new Logger('LateConfigModule');
constructor(
private envJwtConfigService: EarlyJwtConfigService,
private prefService: SysPreferenceService,
private readonly envJwtConfigService: EarlyJwtConfigService,
private readonly prefService: SysPreferenceService,
) {}
async onModuleInit() {

View file

@ -6,7 +6,7 @@ import {
InternalServerErrorException,
Logger,
PipeTransform,
Scope,
Scope
} from '@nestjs/common';
import { FastifyRequest } from 'fastify';
import { HasFailed } from 'picsur-shared/dist/types';
@ -14,14 +14,16 @@ import { ZodDtoStatic } from 'picsur-shared/dist/util/create-zod-dto';
import { MultipartConfigService } from '../../config/early/multipart.config.service';
import {
CreateMultiPartFieldDto,
CreateMultiPartFileDto,
CreateMultiPartFileDto
} from '../../models/dto/multipart.dto';
@Injectable({ scope: Scope.REQUEST })
export class MultiPartPipe implements PipeTransform {
private readonly logger = new Logger('MultiPartPipe');
constructor(private multipartConfigService: MultipartConfigService) {}
constructor(
private readonly multipartConfigService: MultipartConfigService,
) {}
async transform<T extends Object>(
req: FastifyRequest,

View file

@ -4,7 +4,7 @@ import {
Injectable,
Logger,
PipeTransform,
Scope,
Scope
} from '@nestjs/common';
import { FastifyRequest } from 'fastify';
import { MultipartConfigService } from '../../config/early/multipart.config.service';
@ -13,7 +13,9 @@ import { MultipartConfigService } from '../../config/early/multipart.config.serv
export class PostFilePipe implements PipeTransform {
private readonly logger = new Logger('PostFilePipe');
constructor(private multipartConfigService: MultipartConfigService) {}
constructor(
private readonly multipartConfigService: MultipartConfigService,
) {}
async transform({ req }: { req: FastifyRequest }) {
if (!req.isMultipart()) throw new BadRequestException('Invalid file');

View file

@ -5,7 +5,7 @@ import {
InternalServerErrorException,
Logger,
NestInterceptor,
Optional,
Optional
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { ApiAnySuccessResponse } from 'picsur-shared/dist/dto/api/api.dto';
@ -26,7 +26,7 @@ export class SuccessInterceptor<T> implements NestInterceptor {
private strict: boolean;
constructor(
private reflector: Reflector,
private readonly reflector: Reflector,
@Optional() options?: ZodValidationInterceptorOptions,
) {
this.strict = options?.strict ?? true;

View file

@ -8,7 +8,7 @@ import { AsyncFailable, Fail } from 'picsur-shared/dist/types';
export class AuthManagerService {
private readonly logger = new Logger('AuthService');
constructor(private jwtService: JwtService) {}
constructor(private readonly jwtService: JwtService) {}
async createToken(user: EUser): AsyncFailable<string> {
const jwtData = {

View file

@ -21,7 +21,7 @@ export class GuestStrategy extends PassportStrategy(
GuestPassportStrategy,
'guest',
) {
constructor(private guestService: GuestService) {
constructor(private readonly guestService: GuestService) {
super();
}

View file

@ -8,7 +8,7 @@ import { EUserBackend2EUser } from '../../../models/transformers/user.transforme
@Injectable()
export class LocalAuthStrategy extends PassportStrategy(Strategy, 'local') {
constructor(private usersService: UsersService) {
constructor(private readonly usersService: UsersService) {
super();
}

View file

@ -3,7 +3,7 @@ import {
ForbiddenException,
Injectable,
InternalServerErrorException,
Logger,
Logger
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
@ -22,8 +22,8 @@ export class MainAuthGuard extends AuthGuard(['jwt', 'guest']) {
private readonly logger = new Logger('MainAuthGuard');
constructor(
private reflector: Reflector,
private usersService: UsersService,
private readonly reflector: Reflector,
private readonly usersService: UsersService,
) {
super();
}

View file

@ -7,7 +7,7 @@ import { EUserBackend } from '../../models/entities/user.entity';
export class GuestService {
private fallBackUser: EUserBackend;
constructor(private usersService: UsersService) {
constructor(private readonly usersService: UsersService) {
this.fallBackUser = new EUserBackend();
this.fallBackUser.username = 'guest';
this.fallBackUser.roles = ['guest'];

View file

@ -15,7 +15,7 @@ export class DemoManagerModule implements OnModuleInit, OnModuleDestroy {
constructor(
private readonly demoManagerService: DemoManagerService,
private hostConfigService: HostConfigService,
private readonly hostConfigService: HostConfigService,
) {}
async onModuleInit() {

View file

@ -9,7 +9,7 @@ export class DemoManagerService {
constructor(
private readonly imagesService: ImageDBService,
private rolesService: RolesService,
private readonly rolesService: RolesService,
) {}
public async setupRoles() {

View file

@ -24,8 +24,8 @@ export class ImageManagerModule implements OnModuleInit, OnModuleDestroy {
private interval: NodeJS.Timeout;
constructor(
private prefManager: SysPreferenceService,
private imageFileDB: ImageFileDBService,
private readonly prefManager: SysPreferenceService,
private readonly imageFileDB: ImageFileDBService,
) {}
async onModuleInit() {

View file

@ -2,11 +2,11 @@ import { Controller, Get } from '@nestjs/common';
import {
AllFormatsResponse,
AllPermissionsResponse,
InfoResponse,
InfoResponse
} from 'picsur-shared/dist/dto/api/info.dto';
import {
AnimMime2ExtMap,
ImageMime2ExtMap,
ImageMime2ExtMap
} from 'picsur-shared/dist/dto/mimes.dto';
import { HostConfigService } from '../../../config/early/host.config.service';
import { NoPermissions } from '../../../decorators/permissions.decorator';
@ -16,7 +16,7 @@ import { PermissionsList } from '../../../models/constants/permissions.const';
@Controller('api/info')
@NoPermissions()
export class InfoController {
constructor(private hostConfig: HostConfigService) {}
constructor(private readonly hostConfig: HostConfigService) {}
@Get()
@Returns(InfoResponse)

View file

@ -24,7 +24,7 @@ import { Permission } from '../../../models/constants/permissions.const';
export class SysPrefController {
private readonly logger = new Logger('SysPrefController');
constructor(private prefService: SysPreferenceService) {}
constructor(private readonly prefService: SysPreferenceService) {}
@Get()
@Returns(MultiplePreferencesResponse)

View file

@ -25,7 +25,7 @@ import { Permission } from '../../../models/constants/permissions.const';
export class UsrPrefController {
private readonly logger = new Logger('UsrPrefController');
constructor(private prefService: UsrPreferenceService) {}
constructor(private readonly prefService: UsrPreferenceService) {}
@Get()
@Returns(MultiplePreferencesResponse)

View file

@ -38,8 +38,8 @@ export class RolesController {
private readonly logger = new Logger('RolesController');
constructor(
private rolesService: RolesService,
private usersService: UsersService,
private readonly rolesService: RolesService,
private readonly usersService: UsersService,
) {}
@Get('list')

View file

@ -36,7 +36,7 @@ import { EUserBackend2EUser } from '../../../models/transformers/user.transforme
export class UserAdminController {
private readonly logger = new Logger('UserAdminController');
constructor(private usersService: UsersService) {}
constructor(private readonly usersService: UsersService) {}
@Post('list')
@Returns(UserListResponse)

View file

@ -4,14 +4,14 @@ import {
Get,
InternalServerErrorException,
Logger,
Post,
Post
} from '@nestjs/common';
import {
UserLoginResponse,
UserMePermissionsResponse,
UserMeResponse,
UserRegisterRequest,
UserRegisterResponse,
UserRegisterResponse
} from 'picsur-shared/dist/dto/api/user.dto';
import type { EUser } from 'picsur-shared/dist/entities/user.entity';
import { HasFailed } from 'picsur-shared/dist/types';
@ -19,7 +19,7 @@ import { UsersService } from '../../../collections/user-db/user-db.service';
import {
NoPermissions,
RequiredPermissions,
UseLocalAuth,
UseLocalAuth
} from '../../../decorators/permissions.decorator';
import { ReqUser, ReqUserID } from '../../../decorators/request-user.decorator';
import { Returns } from '../../../decorators/returns.decorator';
@ -32,8 +32,8 @@ export class UserController {
private readonly logger = new Logger('UserController');
constructor(
private usersService: UsersService,
private authService: AuthManagerService,
private readonly usersService: UsersService,
private readonly authService: AuthManagerService,
) {}
@Post('login')

View file

@ -7,7 +7,7 @@ import {
AsyncFailable,
Fail,
Failable,
HasFailed,
HasFailed
} from 'picsur-shared/dist/types';
import { Sharp } from 'sharp';
import {
@ -16,7 +16,7 @@ import {
SharpWorkerRecieveMessage,
SharpWorkerResultMessage,
SharpWorkerSendMessage,
SupportedSharpWorkerFunctions,
SupportedSharpWorkerFunctions
} from './sharp/sharp.message';
import { SharpResult } from './sharp/universal-sharp';
@ -35,7 +35,10 @@ export class SharpWrapper {
private worker: ChildProcess | null = null;
constructor(private instance_timeout: number, private memory_limit: number) {}
constructor(
private readonly instance_timeout: number,
private readonly memory_limit: number,
) {}
public async start(image: Buffer, mime: FullMime): AsyncFailable<true> {
this.worker = fork(SharpWrapper.WORKER_PATH, {

View file

@ -5,13 +5,12 @@ import {
ActivatedRoute,
NavigationEnd,
NavigationError,
Router,
Router
} from '@angular/router';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';
import { RouteTransitionAnimations } from './app.animation';
import { PRouteData } from './models/dto/picsur-routes.dto';
import { BootstrapService } from './util/util-module/bootstrap.service';
import { UtilService } from './util/util-module/util.service';
@Component({
selector: 'app-root',
@ -20,7 +19,7 @@ import { UtilService } from './util/util-module/util.service';
animations: [RouteTransitionAnimations],
})
export class AppComponent implements OnInit {
readonly logger = console;
private readonly logger = console;
@ViewChild(MatSidenav) sidebar: MatSidenav;
@ -31,10 +30,9 @@ export class AppComponent implements OnInit {
hasSidebar: boolean = false;
public constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private utilService: UtilService,
private bootstrapService: BootstrapService,
private readonly router: Router,
private readonly activatedRoute: ActivatedRoute,
private readonly bootstrapService: BootstrapService,
) {}
public getRouteAnimData() {

View file

@ -13,7 +13,10 @@ export class CopyFieldComponent {
@Input() label: string = 'Loading...';
@Input() value: string = 'Loading...';
constructor(private utilService: UtilService, private clipboard: Clipboard) {}
constructor(
private readonly utilService: UtilService,
private readonly clipboard: Clipboard,
) {}
public copy() {
if (this.clipboard.copy(this.value)) {

View file

@ -8,7 +8,7 @@ import { InfoService } from 'src/app/services/api/info.service';
styleUrls: ['./footer.component.scss'],
})
export class FooterComponent implements OnInit {
constructor(private infoService: InfoService) {}
constructor(private readonly infoService: InfoService) {}
isDemo: boolean = false;
version: string = 'Unkown Version';

View file

@ -34,10 +34,10 @@ export class HeaderComponent implements OnInit {
}
constructor(
private router: Router,
private userService: UserService,
private permissionService: PermissionService,
private utilService: UtilService,
private readonly router: Router,
private readonly userService: UserService,
private readonly permissionService: PermissionService,
private readonly utilService: UtilService,
) {}
ngOnInit(): void {

View file

@ -30,8 +30,6 @@ export class PaginatorComponent implements OnInit {
lastPagesRange: [number, number] | null = null;
pagesRange: [number, number] = [0, 0];
constructor() {}
ngOnInit(): void {
this.calculateRanges();
}

View file

@ -41,9 +41,9 @@ export class PicsurImgComponent implements OnChanges {
public state: PicsurImgState = PicsurImgState.Loading;
constructor(
private qoiWorker: QoiWorkerService,
private apiService: ApiService,
private changeDetector: ChangeDetectorRef,
private readonly qoiWorker: QoiWorkerService,
private readonly apiService: ApiService,
private readonly changeDetector: ChangeDetectorRef,
) {}
ngOnChanges(changes: SimpleChanges): void {

View file

@ -2,7 +2,7 @@ import { Component, Input, OnInit } from '@angular/core';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';
import {
DecodedPref,
PrefValueType,
PrefValueType
} from 'picsur-shared/dist/dto/preferences.dto';
import { AsyncFailable, HasFailed } from 'picsur-shared/dist/types';
import { Subject } from 'rxjs';
@ -28,7 +28,7 @@ export class PrefOptionComponent implements OnInit {
private updateSubject = new Subject<PrefValueType>();
constructor(private utilService: UtilService) {}
constructor(private readonly utilService: UtilService) {}
ngOnInit(): void {
this.subscribeUpdate();

View file

@ -4,7 +4,7 @@ import {
CanActivate,
CanActivateChild,
Router,
RouterStateSnapshot,
RouterStateSnapshot
} from '@angular/router';
import { isPermissionsArray } from 'picsur-shared/dist/validators/permissions.validator';
import { PRouteData } from '../models/dto/picsur-routes.dto';
@ -20,9 +20,9 @@ export class PermissionGuard implements CanActivate, CanActivateChild {
private allPermissionsArray: string[] | null = null;
constructor(
private permissionService: PermissionService,
private staticInfo: StaticInfoService,
private router: Router,
private readonly permissionService: PermissionService,
private readonly staticInfo: StaticInfoService,
private readonly router: Router,
) {
this.setupAllPermissions().catch(this.logger.error);
}

View file

@ -10,9 +10,9 @@ import { UtilService } from 'src/app/util/util-module/util.service';
})
export class ProcessingComponent implements OnInit {
constructor(
private router: Router,
private imageService: ImageService,
private utilService: UtilService,
private readonly router: Router,
private readonly imageService: ImageService,
private readonly utilService: UtilService,
) {}
async ngOnInit() {

View file

@ -12,7 +12,7 @@ export class SettingsGeneralComponent {
preferences: Observable<DecodedPref[]>;
constructor(public usrPrefService: UsrPrefService) {
constructor(public readonly usrPrefService: UsrPrefService) {
this.preferences = usrPrefService.live;
}
}

View file

@ -35,11 +35,11 @@ export class SettingsRolesEditComponent implements OnInit {
}
constructor(
private route: ActivatedRoute,
private router: Router,
private utilService: UtilService,
private rolesService: RolesService,
private staticInfo: StaticInfoService,
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly utilService: UtilService,
private readonly rolesService: RolesService,
private readonly staticInfo: StaticInfoService,
) {}
ngOnInit() {

View file

@ -37,11 +37,12 @@ export class SettingsRolesComponent implements OnInit, AfterViewInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(
private utilService: UtilService,
private rolesService: RolesService,
private staticInfo: StaticInfoService,
private router: Router,
public bootstrapService: BootstrapService,
private readonly utilService: UtilService,
private readonly rolesService: RolesService,
private readonly staticInfo: StaticInfoService,
private readonly router: Router,
// Public because used in template
public readonly bootstrapService: BootstrapService,
) {}
ngOnInit(): void {

View file

@ -15,9 +15,9 @@ export class SettingsSidebarComponent implements OnInit {
systemRoutes: PRoutes = [];
constructor(
@Inject('SettingsRoutes') private settingsRoutes: PRoutes,
private permissionService: PermissionService,
private router: Router,
@Inject('SettingsRoutes') private readonly settingsRoutes: PRoutes,
private readonly permissionService: PermissionService,
private readonly router: Router,
) {}
ngOnInit() {

View file

@ -8,11 +8,11 @@ import { SysPrefService } from 'src/app/services/api/sys-pref.service';
templateUrl: './settings-sys-pref.component.html',
})
export class SettingsSysprefComponent {
public translator = SysPreferenceFriendlyNames;
public readonly translator = SysPreferenceFriendlyNames;
preferences: Observable<DecodedPref[]>;
constructor(public sysPrefService: SysPrefService) {
constructor(public readonly sysPrefService: SysPrefService) {
this.preferences = sysPrefService.live;
}
}

View file

@ -43,12 +43,12 @@ export class SettingsUsersEditComponent implements OnInit {
}
constructor(
private route: ActivatedRoute,
private router: Router,
private userManageService: UserAdminService,
private utilService: UtilService,
private rolesService: RolesService,
private staticInfo: StaticInfoService,
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly userManageService: UserAdminService,
private readonly utilService: UtilService,
private readonly rolesService: RolesService,
private readonly staticInfo: StaticInfoService,
) {}
ngOnInit() {

View file

@ -34,11 +34,12 @@ export class SettingsUsersComponent implements OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(
private utilService: UtilService,
private userManageService: UserAdminService,
private staticInfo: StaticInfoService,
private router: Router,
public bootstrapService: BootstrapService,
private readonly utilService: UtilService,
private readonly userManageService: UserAdminService,
private readonly staticInfo: StaticInfoService,
private readonly router: Router,
// Public because used in template
public readonly bootstrapService: BootstrapService,
) {}
ngOnInit() {

View file

@ -16,9 +16,9 @@ export class UploadComponent implements OnInit {
canUpload = true;
constructor(
private utilService: UtilService,
private permissionService: PermissionService,
private router: Router,
private readonly utilService: UtilService,
private readonly permissionService: PermissionService,
private readonly router: Router,
) {}
ngOnInit(): void {

View file

@ -18,15 +18,15 @@ import { LoginControl } from '../../../models/forms/login.control';
export class LoginComponent implements OnInit {
private readonly logger = new Logger('LoginComponent');
showRegister = false;
public showRegister = false;
model = new LoginControl();
public readonly model = new LoginControl();
constructor(
private userService: UserService,
private permissionService: PermissionService,
private router: Router,
private utilService: UtilService,
private readonly userService: UserService,
private readonly permissionService: PermissionService,
private readonly router: Router,
private readonly utilService: UtilService,
) {}
ngOnInit(): void {

View file

@ -18,15 +18,15 @@ import { RegisterControl } from '../../../models/forms/register.control';
export class RegisterComponent implements OnInit {
private readonly logger = new Logger('RegisterComponent');
showLogin = false;
public showLogin = false;
model = new RegisterControl();
public readonly model = new RegisterControl();
constructor(
private userService: UserService,
private permissionService: PermissionService,
private router: Router,
private utilService: UtilService,
private readonly userService: UserService,
private readonly permissionService: PermissionService,
private readonly router: Router,
private readonly utilService: UtilService,
) {}
ngOnInit(): void {

View file

@ -38,8 +38,8 @@ export class CustomizeDialogComponent implements OnInit {
public quality: number;
constructor(
public dialogRef: MatDialogRef<CustomizeDialogComponent>,
private imageService: ImageService,
public readonly dialogRef: MatDialogRef<CustomizeDialogComponent>,
private readonly imageService: ImageService,
@Inject(MAT_DIALOG_DATA) data: CustomizeDialogData,
) {
this.formatOptions = data.formatOptions;

View file

@ -1,5 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { ImageLinks } from 'picsur-shared/dist/dto/image-links.class';
import {
@ -29,11 +28,10 @@ import {
})
export class ViewComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private router: Router,
private imageService: ImageService,
private utilService: UtilService,
private dialog: MatDialog,
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly imageService: ImageService,
private readonly utilService: UtilService,
) {}
private id: string;

View file

@ -1,4 +1,5 @@
import { Inject, Injectable } from '@angular/core';
import { WINDOW } from '@ng-web-apis/common';
import { ApiResponseSchema } from 'picsur-shared/dist/dto/api/api.dto';
import { Mime2Ext } from 'picsur-shared/dist/dto/mimes.dto';
import { AsyncFailable, Fail, HasFailed } from 'picsur-shared/dist/types';
@ -10,7 +11,6 @@ import { z } from 'zod';
import { MultiPartRequest } from '../../models/dto/multi-part-request.dto';
import { Logger } from '../logger/logger.service';
import { KeyService } from '../storage/key.service';
import { WINDOW } from '@ng-web-apis/common';
/*
Proud of this, it works so smoooth
@ -30,7 +30,7 @@ export class ApiService {
constructor(
private readonly keyService: KeyService,
@Inject(WINDOW) readonly windowRef: Window,
@Inject(WINDOW) private readonly windowRef: Window,
) {}
public async get<T extends z.AnyZodObject>(

View file

@ -25,10 +25,10 @@ import { UserService } from './user.service';
})
export class ImageService {
constructor(
private api: ApiService,
@Inject(LOCATION) readonly location: Location,
private readonly api: ApiService,
@Inject(LOCATION) private readonly location: Location,
private userService: UserService,
private readonly userService: UserService,
) {}
public async UploadImage(image: File): AsyncFailable<string> {

View file

@ -38,9 +38,9 @@ export class PermissionService {
}
constructor(
private userService: UserService,
private api: ApiService,
private staticInfo: StaticInfoService,
private readonly userService: UserService,
private readonly api: ApiService,
private readonly staticInfo: StaticInfoService,
) {
this.subscribeUser();
this.loadAllPermissions().catch(this.logger.error);

View file

@ -19,7 +19,7 @@ import { ApiService } from './api.service';
providedIn: 'root',
})
export class RolesService {
constructor(private api: ApiService) {}
constructor(private readonly api: ApiService) {}
public async getRoles(): AsyncFailable<ERole[]> {
const response = await this.api.get(RoleListResponse, '/api/roles/list');

View file

@ -10,7 +10,10 @@ import { ApiService } from './api.service';
providedIn: 'root',
})
export class StaticInfoService {
constructor(private api: ApiService, private cache: CacheService) {}
constructor(
private readonly api: ApiService,
private readonly cache: CacheService,
) {}
public async getSpecialRoles(): Promise<SpecialRolesResponse> {
return this.cache.getFallback(

View file

@ -39,9 +39,9 @@ export class SysPrefService {
}
constructor(
private api: ApiService,
private permissionsService: PermissionService,
private utilService: UtilService,
private readonly api: ApiService,
private readonly permissionsService: PermissionService,
private readonly utilService: UtilService,
) {
this.subscribePermissions();
}

View file

@ -9,7 +9,7 @@ import {
UserListRequest,
UserListResponse,
UserUpdateRequest,
UserUpdateResponse,
UserUpdateResponse
} from 'picsur-shared/dist/dto/api/user-manage.dto';
import { EUser } from 'picsur-shared/dist/entities/user.entity';
import { AsyncFailable } from 'picsur-shared/dist/types';
@ -19,7 +19,7 @@ import { ApiService } from './api.service';
providedIn: 'root',
})
export class UserAdminService {
constructor(private api: ApiService) {}
constructor(private readonly api: ApiService) {}
public async getUser(id: string): AsyncFailable<EUser> {
return await this.api.post(

View file

@ -5,7 +5,7 @@ import {
UserLoginResponse,
UserMeResponse,
UserRegisterRequest,
UserRegisterResponse,
UserRegisterResponse
} from 'picsur-shared/dist/dto/api/user.dto';
import { JwtDataSchema } from 'picsur-shared/dist/dto/jwt.dto';
import { EUser } from 'picsur-shared/dist/entities/user.entity';
@ -34,7 +34,10 @@ export class UserService {
return this.userSubject.getValue() !== null;
}
constructor(private api: ApiService, private key: KeyService) {
constructor(
private readonly api: ApiService,
private readonly key: KeyService,
) {
this.init().catch(this.logger.error);
}

View file

@ -39,9 +39,9 @@ export class UsrPrefService {
}
constructor(
private api: ApiService,
private permissionsService: PermissionService,
private utilService: UtilService,
private readonly api: ApiService,
private readonly permissionsService: PermissionService,
private readonly utilService: UtilService,
) {
this.subscribePermissions();
}

View file

@ -13,7 +13,7 @@ import { PRouteData } from 'src/app/models/dto/picsur-routes.dto';
export class SidebarResolverService
implements Resolve<Portal<unknown> | undefined>
{
constructor(private injector: Injector) {}
constructor(private readonly injector: Injector) {}
resolve(route: ActivatedRouteSnapshot) {
const data: PRouteData = route.data;

View file

@ -12,12 +12,14 @@ export class ApiErrorService {
private readonly logger = new Logger('ApiErrorService');
constructor(
private apiSerivce: ApiService,
private utilService: UtilService,
private readonly apiSerivce: ApiService,
private readonly utilService: UtilService,
) {
this.subscribeErrors();
}
nothing(): void {}
@AutoUnsubscribe()
private subscribeErrors() {
return this.apiSerivce.networkErrors.subscribe((error) => {

View file

@ -1,7 +1,7 @@
import { BreakpointObserver } from '@angular/cdk/layout';
import { Injectable } from '@angular/core';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';
import { Observable, map, BehaviorSubject, zip, combineLatest } from 'rxjs';
import { BehaviorSubject, combineLatest, map, Observable } from 'rxjs';
import { Logger } from 'src/app/services/logger/logger.service';
export enum BSScreenSize {
@ -28,7 +28,7 @@ export class BootstrapService {
private screenSizeSubject: BehaviorSubject<BSScreenSize> =
new BehaviorSubject<BSScreenSize>(BSScreenSize.xs);
constructor(private breakPointObserver: BreakpointObserver) {
constructor(private readonly breakPointObserver: BreakpointObserver) {
this.smObservable = this.createObserver('(min-width: 576px)');
this.mdObservable = this.createObserver('(min-width: 768px)');
this.lgObservable = this.createObserver('(min-width: 992px)');

View file

@ -21,8 +21,8 @@ export interface ConfirmDialogData {
})
export class ConfirmDialogComponent {
constructor(
public dialogRef: MatDialogRef<ConfirmDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: ConfirmDialogData,
public readonly dialogRef: MatDialogRef<ConfirmDialogComponent>,
@Inject(MAT_DIALOG_DATA) public readonly data: ConfirmDialogData,
) {}
onButton(name: string) {

View file

@ -11,7 +11,7 @@ export interface DownloadDialogData {
})
export class DownloadDialogComponent {
constructor(
public dialogRef: MatDialogRef<DownloadDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: DownloadDialogData,
public readonly dialogRef: MatDialogRef<DownloadDialogComponent>,
@Inject(MAT_DIALOG_DATA) public readonly data: DownloadDialogData,
) {}
}

View file

@ -5,7 +5,7 @@ import { MatDialogModule } from '@angular/material/dialog';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import {
MatSnackBarModule,
MAT_SNACK_BAR_DEFAULT_OPTIONS,
MAT_SNACK_BAR_DEFAULT_OPTIONS
} from '@angular/material/snack-bar';
import { RouterModule } from '@angular/router';
import { ApiErrorService } from './api-error.service';
@ -39,6 +39,8 @@ export class UtilModule {
};
}
// Start apiErrorService
constructor(private apiErrorService: ApiErrorService) {}
// Start apiErrorService, the nothing function does nothing, but it silents the error.
constructor(apiErrorService: ApiErrorService) {
apiErrorService.nothing();
}
}

View file

@ -10,7 +10,7 @@ import { SnackBarType } from '../../models/dto/snack-bar-type.dto';
import { BootstrapService, BSScreenSize } from './bootstrap.service';
import {
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogData
} from './confirm-dialog/confirm-dialog.component';
import { DownloadDialogComponent } from './download-dialog/download-dialog.component';
@ -21,11 +21,11 @@ export class UtilService {
private readonly logger = new Logger('UtilService');
constructor(
private snackBar: MatSnackBar,
private dialog: MatDialog,
private router: Router,
private api: ApiService,
private bootstrap: BootstrapService,
private readonly snackBar: MatSnackBar,
private readonly dialog: MatDialog,
private readonly router: Router,
private readonly api: ApiService,
private readonly bootstrap: BootstrapService,
) {}
public quitError(message: string) {

View file

@ -10,7 +10,7 @@ export class QoiWorkerService {
private worker: Worker | null = null;
private job: Promise<QOIJob> | null = null;
constructor(private keyService: KeyService) {
constructor(private readonly keyService: KeyService) {
if (typeof Worker !== 'undefined') {
this.worker = new Worker(new URL('./qoi.worker', import.meta.url));
} else {