diff --git a/server/apps/cli/src/app.module.ts b/server/apps/cli/src/app.module.ts index b1b0de7ec8..91af971c7a 100644 --- a/server/apps/cli/src/app.module.ts +++ b/server/apps/cli/src/app.module.ts @@ -1,11 +1,17 @@ -import { DatabaseModule, SystemConfigEntity, UserEntity } from '@app/database'; +import { DomainModule } from '@app/domain'; +import { InfraModule, SystemConfigEntity } from '@app/infra'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './commands/password-login'; import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command'; @Module({ - imports: [DatabaseModule, TypeOrmModule.forFeature([UserEntity, SystemConfigEntity])], + imports: [ + DomainModule.register({ + imports: [InfraModule], + }), + TypeOrmModule.forFeature([SystemConfigEntity]), + ], providers: [ ResetAdminPasswordCommand, PromptPasswordQuestions, diff --git a/server/apps/cli/src/commands/password-login.ts b/server/apps/cli/src/commands/password-login.ts index a2a07a33e2..dd464e32c3 100644 --- a/server/apps/cli/src/commands/password-login.ts +++ b/server/apps/cli/src/commands/password-login.ts @@ -1,4 +1,4 @@ -import { SystemConfigEntity, SystemConfigKey } from '@app/database'; +import { SystemConfigEntity, SystemConfigKey } from '@app/infra'; import { InjectRepository } from '@nestjs/typeorm'; import axios from 'axios'; import { Command, CommandRunner } from 'nest-commander'; @@ -9,9 +9,7 @@ import { Repository } from 'typeorm'; description: 'Enable password login', }) export class EnablePasswordLoginCommand extends CommandRunner { - constructor( - @InjectRepository(SystemConfigEntity) private repository: Repository, // - ) { + constructor(@InjectRepository(SystemConfigEntity) private repository: Repository) { super(); } diff --git a/server/apps/cli/src/commands/reset-admin-password.command.ts b/server/apps/cli/src/commands/reset-admin-password.command.ts index 5062134890..2c66c8a961 100644 --- a/server/apps/cli/src/commands/reset-admin-password.command.ts +++ b/server/apps/cli/src/commands/reset-admin-password.command.ts @@ -1,40 +1,38 @@ -import { UserEntity } from '@app/database'; -import { InjectRepository } from '@nestjs/typeorm'; -import bcrypt from 'bcrypt'; +import { Inject } from '@nestjs/common'; import { Command, CommandRunner, InquirerService, Question, QuestionSet } from 'nest-commander'; import { randomBytes } from 'node:crypto'; -import { Repository } from 'typeorm'; +import { IUserRepository, UserCore } from '@app/domain'; @Command({ name: 'reset-admin-password', description: 'Reset the admin password', }) export class ResetAdminPasswordCommand extends CommandRunner { - constructor( - private readonly inquirer: InquirerService, - @InjectRepository(UserEntity) private userRepository: Repository, - ) { + userCore: UserCore; + + constructor(private readonly inquirer: InquirerService, @Inject(IUserRepository) userRepository: IUserRepository) { super(); + + this.userCore = new UserCore(userRepository); } async run(): Promise { - let { password } = await this.inquirer.ask<{ password: string }>('prompt-password', undefined); - password = password || randomBytes(24).toString('base64').replace(/\W/g, ''); - - const hashedPassword = await bcrypt.hash(password, 10); - - const user = await this.userRepository.findOne({ where: { isAdmin: true } }); + const user = await this.userCore.getAdmin(); if (!user) { console.log('Unable to reset password: no admin user.'); return; } - user.password = hashedPassword; - user.shouldChangePassword = true; + const { password: providedPassword } = await this.inquirer.ask<{ password: string }>('prompt-password', undefined); + const password = providedPassword || randomBytes(24).toString('base64').replace(/\W/g, ''); - await this.userRepository.save(user); + await this.userCore.updateUser(user, user.id, { password }); - console.log(`New password:\n${password}`); + if (providedPassword) { + console.log('The admin password has been updated.'); + } else { + console.log(`The admin password has been updated to:\n${password}`); + } } } diff --git a/server/apps/immich/src/api-v1/album/album-repository.ts b/server/apps/immich/src/api-v1/album/album-repository.ts index f504a5bd35..f9392fa166 100644 --- a/server/apps/immich/src/api-v1/album/album-repository.ts +++ b/server/apps/immich/src/api-v1/album/album-repository.ts @@ -1,4 +1,4 @@ -import { AlbumEntity, AssetAlbumEntity, UserAlbumEntity } from '@app/database'; +import { AlbumEntity, AssetAlbumEntity, UserAlbumEntity } from '@app/infra'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository, SelectQueryBuilder, DataSource, Brackets, Not, IsNull } from 'typeorm'; diff --git a/server/apps/immich/src/api-v1/album/album.module.ts b/server/apps/immich/src/api-v1/album/album.module.ts index aa1077d3fe..15cd73d33a 100644 --- a/server/apps/immich/src/api-v1/album/album.module.ts +++ b/server/apps/immich/src/api-v1/album/album.module.ts @@ -2,11 +2,10 @@ import { forwardRef, Module } from '@nestjs/common'; import { AlbumService } from './album.service'; import { AlbumController } from './album.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { AlbumEntity, AssetAlbumEntity, UserAlbumEntity } from '@app/database'; +import { AlbumEntity, AssetAlbumEntity, UserAlbumEntity } from '@app/infra'; import { AlbumRepository, IAlbumRepository } from './album-repository'; import { DownloadModule } from '../../modules/download/download.module'; import { AssetModule } from '../asset/asset.module'; -import { UserModule } from '../user/user.module'; import { ShareModule } from '../share/share.module'; const ALBUM_REPOSITORY_PROVIDER = { @@ -18,7 +17,6 @@ const ALBUM_REPOSITORY_PROVIDER = { imports: [ TypeOrmModule.forFeature([AlbumEntity, AssetAlbumEntity, UserAlbumEntity]), DownloadModule, - UserModule, forwardRef(() => AssetModule), ShareModule, ], diff --git a/server/apps/immich/src/api-v1/album/album.service.spec.ts b/server/apps/immich/src/api-v1/album/album.service.spec.ts index a14c6d2ba2..e78c64c6b7 100644 --- a/server/apps/immich/src/api-v1/album/album.service.spec.ts +++ b/server/apps/immich/src/api-v1/album/album.service.spec.ts @@ -1,7 +1,7 @@ import { AlbumService } from './album.service'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common'; -import { AlbumEntity } from '@app/database'; +import { AlbumEntity } from '@app/infra'; import { AlbumResponseDto } from './response-dto/album-response.dto'; import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; import { IAlbumRepository } from './album-repository'; diff --git a/server/apps/immich/src/api-v1/album/album.service.ts b/server/apps/immich/src/api-v1/album/album.service.ts index ffb364637d..7577abbba5 100644 --- a/server/apps/immich/src/api-v1/album/album.service.ts +++ b/server/apps/immich/src/api-v1/album/album.service.ts @@ -1,7 +1,7 @@ import { BadRequestException, Inject, Injectable, NotFoundException, ForbiddenException, Logger } from '@nestjs/common'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { CreateAlbumDto } from './dto/create-album.dto'; -import { AlbumEntity, SharedLinkType } from '@app/database'; +import { AlbumEntity, SharedLinkType } from '@app/infra'; import { AddUsersDto } from './dto/add-users.dto'; import { RemoveAssetsDto } from './dto/remove-assets.dto'; import { UpdateAlbumDto } from './dto/update-album.dto'; diff --git a/server/apps/immich/src/api-v1/album/response-dto/album-response.dto.ts b/server/apps/immich/src/api-v1/album/response-dto/album-response.dto.ts index cb71543a0e..5cac1bd5d6 100644 --- a/server/apps/immich/src/api-v1/album/response-dto/album-response.dto.ts +++ b/server/apps/immich/src/api-v1/album/response-dto/album-response.dto.ts @@ -1,5 +1,5 @@ -import { AlbumEntity } from '@app/database'; -import { UserResponseDto, mapUser } from '../../user/response-dto/user-response.dto'; +import { AlbumEntity } from '@app/infra'; +import { UserResponseDto, mapUser } from '@app/domain'; import { AssetResponseDto, mapAsset } from '../../asset/response-dto/asset-response.dto'; import { ApiProperty } from '@nestjs/swagger'; diff --git a/server/apps/immich/src/api-v1/api-key/api-key.module.ts b/server/apps/immich/src/api-v1/api-key/api-key.module.ts index 2f64e0262a..5823358b2c 100644 --- a/server/apps/immich/src/api-v1/api-key/api-key.module.ts +++ b/server/apps/immich/src/api-v1/api-key/api-key.module.ts @@ -1,4 +1,4 @@ -import { APIKeyEntity } from '@app/database'; +import { APIKeyEntity } from '@app/infra'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { APIKeyController } from './api-key.controller'; diff --git a/server/apps/immich/src/api-v1/api-key/api-key.repository.ts b/server/apps/immich/src/api-v1/api-key/api-key.repository.ts index ec203d4ea1..19a1fad067 100644 --- a/server/apps/immich/src/api-v1/api-key/api-key.repository.ts +++ b/server/apps/immich/src/api-v1/api-key/api-key.repository.ts @@ -1,4 +1,4 @@ -import { APIKeyEntity } from '@app/database'; +import { APIKeyEntity } from '@app/infra'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; diff --git a/server/apps/immich/src/api-v1/api-key/api-key.service.ts b/server/apps/immich/src/api-v1/api-key/api-key.service.ts index 60d7249743..48f7abc23d 100644 --- a/server/apps/immich/src/api-v1/api-key/api-key.service.ts +++ b/server/apps/immich/src/api-v1/api-key/api-key.service.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { BadRequestException, Inject, Injectable, UnauthorizedException } from '@nestjs/common'; import { compareSync, hash } from 'bcrypt'; import { randomBytes } from 'node:crypto'; diff --git a/server/apps/immich/src/api-v1/api-key/repsonse-dto/api-key-response.dto.ts b/server/apps/immich/src/api-v1/api-key/repsonse-dto/api-key-response.dto.ts index 31a43df1ba..706a618b10 100644 --- a/server/apps/immich/src/api-v1/api-key/repsonse-dto/api-key-response.dto.ts +++ b/server/apps/immich/src/api-v1/api-key/repsonse-dto/api-key-response.dto.ts @@ -1,4 +1,4 @@ -import { APIKeyEntity } from '@app/database'; +import { APIKeyEntity } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class APIKeyResponseDto { diff --git a/server/apps/immich/src/api-v1/asset/asset-repository.ts b/server/apps/immich/src/api-v1/asset/asset-repository.ts index 4efe35bb16..37893b4a4d 100644 --- a/server/apps/immich/src/api-v1/asset/asset-repository.ts +++ b/server/apps/immich/src/api-v1/asset/asset-repository.ts @@ -1,6 +1,6 @@ import { SearchPropertiesDto } from './dto/search-properties.dto'; import { CuratedLocationsResponseDto } from './response-dto/curated-locations-response.dto'; -import { AssetEntity, AssetType } from '@app/database'; +import { AssetEntity, AssetType } from '@app/infra'; import { BadRequestException, Inject, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm/repository/Repository'; diff --git a/server/apps/immich/src/api-v1/asset/asset.module.ts b/server/apps/immich/src/api-v1/asset/asset.module.ts index f987d8fc2d..79f7e28f90 100644 --- a/server/apps/immich/src/api-v1/asset/asset.module.ts +++ b/server/apps/immich/src/api-v1/asset/asset.module.ts @@ -2,7 +2,7 @@ import { forwardRef, Module } from '@nestjs/common'; import { AssetService } from './asset.service'; import { AssetController } from './asset.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { BullModule } from '@nestjs/bull'; import { BackgroundTaskModule } from '../../modules/background-task/background-task.module'; import { BackgroundTaskService } from '../../modules/background-task/background-task.service'; @@ -11,7 +11,6 @@ import { AssetRepository, IAssetRepository } from './asset-repository'; import { DownloadModule } from '../../modules/download/download.module'; import { TagModule } from '../tag/tag.module'; import { AlbumModule } from '../album/album.module'; -import { UserModule } from '../user/user.module'; import { StorageModule } from '@app/storage'; import { immichSharedQueues } from '@app/job/constants/bull-queue-registration.constant'; import { ShareModule } from '../share/share.module'; @@ -27,7 +26,6 @@ const ASSET_REPOSITORY_PROVIDER = { CommunicationModule, BackgroundTaskModule, DownloadModule, - UserModule, AlbumModule, TagModule, StorageModule, diff --git a/server/apps/immich/src/api-v1/asset/asset.service.spec.ts b/server/apps/immich/src/api-v1/asset/asset.service.spec.ts index 0778f80688..21dd774c6f 100644 --- a/server/apps/immich/src/api-v1/asset/asset.service.spec.ts +++ b/server/apps/immich/src/api-v1/asset/asset.service.spec.ts @@ -2,7 +2,7 @@ import { IAssetRepository } from './asset-repository'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { AssetService } from './asset.service'; import { Repository } from 'typeorm'; -import { AssetEntity, AssetType } from '@app/database'; +import { AssetEntity, AssetType } from '@app/infra'; import { CreateAssetDto } from './dto/create-asset.dto'; import { AssetCountByTimeBucket } from './response-dto/asset-count-by-time-group-response.dto'; import { TimeGroupEnum } from './dto/get-asset-count-by-time-bucket.dto'; diff --git a/server/apps/immich/src/api-v1/asset/asset.service.ts b/server/apps/immich/src/api-v1/asset/asset.service.ts index ad07db7b1c..aeae60da9d 100644 --- a/server/apps/immich/src/api-v1/asset/asset.service.ts +++ b/server/apps/immich/src/api-v1/asset/asset.service.ts @@ -13,7 +13,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { createHash, randomUUID } from 'node:crypto'; import { QueryFailedError, Repository } from 'typeorm'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; -import { AssetEntity, AssetType } from '@app/database'; +import { AssetEntity, AssetType } from '@app/infra'; import { constants, createReadStream, ReadStream, stat } from 'fs'; import { ServeFileDto } from './dto/serve-file.dto'; import { Response as Res } from 'express'; diff --git a/server/apps/immich/src/api-v1/asset/dto/create-asset.dto.ts b/server/apps/immich/src/api-v1/asset/dto/create-asset.dto.ts index 401a0c48a8..de5b42b234 100644 --- a/server/apps/immich/src/api-v1/asset/dto/create-asset.dto.ts +++ b/server/apps/immich/src/api-v1/asset/dto/create-asset.dto.ts @@ -1,5 +1,5 @@ import { IsNotEmpty, IsOptional } from 'class-validator'; -import { AssetType } from '@app/database'; +import { AssetType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class CreateAssetDto { diff --git a/server/apps/immich/src/api-v1/asset/response-dto/asset-response.dto.ts b/server/apps/immich/src/api-v1/asset/response-dto/asset-response.dto.ts index 481516a344..87014deb8b 100644 --- a/server/apps/immich/src/api-v1/asset/response-dto/asset-response.dto.ts +++ b/server/apps/immich/src/api-v1/asset/response-dto/asset-response.dto.ts @@ -1,4 +1,4 @@ -import { AssetEntity, AssetType } from '@app/database'; +import { AssetEntity, AssetType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; import { mapTag, TagResponseDto } from '../../tag/response-dto/tag-response.dto'; import { ExifResponseDto, mapExif } from './exif-response.dto'; diff --git a/server/apps/immich/src/api-v1/asset/response-dto/exif-response.dto.ts b/server/apps/immich/src/api-v1/asset/response-dto/exif-response.dto.ts index 92d209fecb..8e4b2e82de 100644 --- a/server/apps/immich/src/api-v1/asset/response-dto/exif-response.dto.ts +++ b/server/apps/immich/src/api-v1/asset/response-dto/exif-response.dto.ts @@ -1,4 +1,4 @@ -import { ExifEntity } from '@app/database'; +import { ExifEntity } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class ExifResponseDto { diff --git a/server/apps/immich/src/api-v1/asset/response-dto/smart-info-response.dto.ts b/server/apps/immich/src/api-v1/asset/response-dto/smart-info-response.dto.ts index e27b5e5cb2..00e6790031 100644 --- a/server/apps/immich/src/api-v1/asset/response-dto/smart-info-response.dto.ts +++ b/server/apps/immich/src/api-v1/asset/response-dto/smart-info-response.dto.ts @@ -1,4 +1,4 @@ -import { SmartInfoEntity } from '@app/database'; +import { SmartInfoEntity } from '@app/infra'; export class SmartInfoResponseDto { id?: string; diff --git a/server/apps/immich/src/api-v1/auth/auth.controller.ts b/server/apps/immich/src/api-v1/auth/auth.controller.ts index 53b6b02b97..9d10bfacec 100644 --- a/server/apps/immich/src/api-v1/auth/auth.controller.ts +++ b/server/apps/immich/src/api-v1/auth/auth.controller.ts @@ -5,7 +5,7 @@ import { AuthType, IMMICH_AUTH_TYPE_COOKIE } from '../../constants/jwt.constant' import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator'; import { Authenticated } from '../../decorators/authenticated.decorator'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; -import { UserResponseDto } from '../user/response-dto/user-response.dto'; +import { UserResponseDto } from '@app/domain'; import { AuthService } from './auth.service'; import { ChangePasswordDto } from './dto/change-password.dto'; import { LoginCredentialDto } from './dto/login-credential.dto'; diff --git a/server/apps/immich/src/api-v1/auth/auth.module.ts b/server/apps/immich/src/api-v1/auth/auth.module.ts index f1d93f067f..5aeeb31590 100644 --- a/server/apps/immich/src/api-v1/auth/auth.module.ts +++ b/server/apps/immich/src/api-v1/auth/auth.module.ts @@ -2,12 +2,11 @@ import { Module } from '@nestjs/common'; import { ImmichConfigModule } from '@app/immich-config'; import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module'; import { OAuthModule } from '../oauth/oauth.module'; -import { UserModule } from '../user/user.module'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; @Module({ - imports: [UserModule, ImmichJwtModule, OAuthModule, ImmichConfigModule], + imports: [ImmichJwtModule, OAuthModule, ImmichConfigModule], controllers: [AuthController], providers: [AuthService], }) diff --git a/server/apps/immich/src/api-v1/auth/auth.service.spec.ts b/server/apps/immich/src/api-v1/auth/auth.service.spec.ts index 9234171372..041daa2c5a 100644 --- a/server/apps/immich/src/api-v1/auth/auth.service.spec.ts +++ b/server/apps/immich/src/api-v1/auth/auth.service.spec.ts @@ -1,12 +1,12 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { BadRequestException, UnauthorizedException } from '@nestjs/common'; import * as bcrypt from 'bcrypt'; -import { SystemConfig } from '@app/database/entities/system-config.entity'; +import { SystemConfig } from '@app/infra'; import { ImmichConfigService } from '@app/immich-config'; import { AuthType } from '../../constants/jwt.constant'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { OAuthService } from '../oauth/oauth.service'; -import { IUserRepository } from '../user/user-repository'; +import { IUserRepository } from '@app/domain'; import { AuthService } from './auth.service'; import { SignUpDto } from './dto/sign-up.dto'; import { LoginResponseDto } from './response-dto/login-response.dto'; diff --git a/server/apps/immich/src/api-v1/auth/auth.service.ts b/server/apps/immich/src/api-v1/auth/auth.service.ts index 1721c7d31a..33773877dc 100644 --- a/server/apps/immich/src/api-v1/auth/auth.service.ts +++ b/server/apps/immich/src/api-v1/auth/auth.service.ts @@ -7,11 +7,11 @@ import { UnauthorizedException, } from '@nestjs/common'; import * as bcrypt from 'bcrypt'; -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { AuthType } from '../../constants/jwt.constant'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; -import { IUserRepository } from '../user/user-repository'; +import { IUserRepository } from '@app/domain'; import { ChangePasswordDto } from './dto/change-password.dto'; import { LoginCredentialDto } from './dto/login-credential.dto'; import { SignUpDto } from './dto/sign-up.dto'; @@ -19,9 +19,9 @@ import { AdminSignupResponseDto, mapAdminSignupResponse } from './response-dto/a import { LoginResponseDto } from './response-dto/login-response.dto'; import { LogoutResponseDto } from './response-dto/logout-response.dto'; import { OAuthService } from '../oauth/oauth.service'; -import { UserCore } from '../user/user.core'; +import { UserCore } from '@app/domain'; import { ImmichConfigService, INITIAL_SYSTEM_CONFIG } from '@app/immich-config'; -import { SystemConfig } from '@app/database/entities/system-config.entity'; +import { SystemConfig } from '@app/infra'; @Injectable() export class AuthService { diff --git a/server/apps/immich/src/api-v1/auth/response-dto/admin-signup-response.dto.ts b/server/apps/immich/src/api-v1/auth/response-dto/admin-signup-response.dto.ts index 0288400d55..0577f70a52 100644 --- a/server/apps/immich/src/api-v1/auth/response-dto/admin-signup-response.dto.ts +++ b/server/apps/immich/src/api-v1/auth/response-dto/admin-signup-response.dto.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; export class AdminSignupResponseDto { id!: string; diff --git a/server/apps/immich/src/api-v1/auth/response-dto/login-response.dto.ts b/server/apps/immich/src/api-v1/auth/response-dto/login-response.dto.ts index ea80cfde25..96986d1a1a 100644 --- a/server/apps/immich/src/api-v1/auth/response-dto/login-response.dto.ts +++ b/server/apps/immich/src/api-v1/auth/response-dto/login-response.dto.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { ApiResponseProperty } from '@nestjs/swagger'; export class LoginResponseDto { diff --git a/server/apps/immich/src/api-v1/communication/communication.gateway.ts b/server/apps/immich/src/api-v1/communication/communication.gateway.ts index 9915cf7c0c..52e40becd3 100644 --- a/server/apps/immich/src/api-v1/communication/communication.gateway.ts +++ b/server/apps/immich/src/api-v1/communication/communication.gateway.ts @@ -3,7 +3,7 @@ import { Socket, Server } from 'socket.io'; import { ImmichJwtService, JwtValidationResult } from '../../modules/immich-jwt/immich-jwt.service'; import { Logger } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { Repository } from 'typeorm'; import cookieParser from 'cookie'; import { IMMICH_ACCESS_COOKIE } from '../../constants/jwt.constant'; diff --git a/server/apps/immich/src/api-v1/communication/communication.module.ts b/server/apps/immich/src/api-v1/communication/communication.module.ts index b93ee0cdc6..73026dfb9b 100644 --- a/server/apps/immich/src/api-v1/communication/communication.module.ts +++ b/server/apps/immich/src/api-v1/communication/communication.module.ts @@ -6,7 +6,7 @@ import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { JwtModule } from '@nestjs/jwt'; import { jwtConfig } from '../../config/jwt.config'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; @Module({ imports: [TypeOrmModule.forFeature([UserEntity]), ImmichJwtModule, JwtModule.register(jwtConfig)], diff --git a/server/apps/immich/src/api-v1/device-info/device-info.module.ts b/server/apps/immich/src/api-v1/device-info/device-info.module.ts index c6c0db084a..b2982ceba9 100644 --- a/server/apps/immich/src/api-v1/device-info/device-info.module.ts +++ b/server/apps/immich/src/api-v1/device-info/device-info.module.ts @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common'; import { DeviceInfoService } from './device-info.service'; import { DeviceInfoController } from './device-info.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { DeviceInfoEntity } from '@app/database'; +import { DeviceInfoEntity } from '@app/infra'; @Module({ imports: [TypeOrmModule.forFeature([DeviceInfoEntity])], diff --git a/server/apps/immich/src/api-v1/device-info/device-info.service.spec.ts b/server/apps/immich/src/api-v1/device-info/device-info.service.spec.ts index be9ea3a4c3..565e38872b 100644 --- a/server/apps/immich/src/api-v1/device-info/device-info.service.spec.ts +++ b/server/apps/immich/src/api-v1/device-info/device-info.service.spec.ts @@ -1,4 +1,4 @@ -import { DeviceInfoEntity, DeviceType } from '@app/database'; +import { DeviceInfoEntity, DeviceType } from '@app/infra'; import { Repository } from 'typeorm'; import { DeviceInfoService } from './device-info.service'; diff --git a/server/apps/immich/src/api-v1/device-info/device-info.service.ts b/server/apps/immich/src/api-v1/device-info/device-info.service.ts index ff9243afb6..4c28d0b746 100644 --- a/server/apps/immich/src/api-v1/device-info/device-info.service.ts +++ b/server/apps/immich/src/api-v1/device-info/device-info.service.ts @@ -1,4 +1,4 @@ -import { DeviceInfoEntity } from '@app/database'; +import { DeviceInfoEntity } from '@app/infra'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; diff --git a/server/apps/immich/src/api-v1/device-info/dto/upsert-device-info.dto.ts b/server/apps/immich/src/api-v1/device-info/dto/upsert-device-info.dto.ts index 9d39e88838..88f480255e 100644 --- a/server/apps/immich/src/api-v1/device-info/dto/upsert-device-info.dto.ts +++ b/server/apps/immich/src/api-v1/device-info/dto/upsert-device-info.dto.ts @@ -1,5 +1,5 @@ import { IsNotEmpty, IsOptional } from 'class-validator'; -import { DeviceType } from '@app/database'; +import { DeviceType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class UpsertDeviceInfoDto { diff --git a/server/apps/immich/src/api-v1/device-info/response-dto/device-info-response.dto.ts b/server/apps/immich/src/api-v1/device-info/response-dto/device-info-response.dto.ts index 555049958d..3f2d3b4455 100644 --- a/server/apps/immich/src/api-v1/device-info/response-dto/device-info-response.dto.ts +++ b/server/apps/immich/src/api-v1/device-info/response-dto/device-info-response.dto.ts @@ -1,4 +1,4 @@ -import { DeviceInfoEntity, DeviceType } from '@app/database'; +import { DeviceInfoEntity, DeviceType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class DeviceInfoResponseDto { diff --git a/server/apps/immich/src/api-v1/job/job.module.ts b/server/apps/immich/src/api-v1/job/job.module.ts index 9e070fc8c1..1bd242fdcc 100644 --- a/server/apps/immich/src/api-v1/job/job.module.ts +++ b/server/apps/immich/src/api-v1/job/job.module.ts @@ -1,15 +1,11 @@ import { Module } from '@nestjs/common'; import { JobService } from './job.service'; import { JobController } from './job.controller'; -import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module'; -import { JwtModule } from '@nestjs/jwt'; -import { jwtConfig } from '../../config/jwt.config'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { ExifEntity } from '@app/database'; +import { ExifEntity } from '@app/infra'; import { TagModule } from '../tag/tag.module'; import { AssetModule } from '../asset/asset.module'; -import { UserModule } from '../user/user.module'; import { StorageModule } from '@app/storage'; import { BullModule } from '@nestjs/bull'; @@ -21,12 +17,10 @@ import { immichSharedQueues } from '@app/job/constants/bull-queue-registration.c ImmichJwtModule, TagModule, AssetModule, - UserModule, - JwtModule.register(jwtConfig), StorageModule, BullModule.registerQueue(...immichSharedQueues), ], controllers: [JobController], - providers: [JobService, ImmichJwtService], + providers: [JobService], }) export class JobModule {} diff --git a/server/apps/immich/src/api-v1/job/job.service.ts b/server/apps/immich/src/api-v1/job/job.service.ts index 421569dd34..42d34262c2 100644 --- a/server/apps/immich/src/api-v1/job/job.service.ts +++ b/server/apps/immich/src/api-v1/job/job.service.ts @@ -15,7 +15,7 @@ import { BadRequestException, Inject, Injectable } from '@nestjs/common'; import { AllJobStatusResponseDto } from './response-dto/all-job-status-response.dto'; import { randomUUID } from 'crypto'; import { IAssetRepository } from '../asset/asset-repository'; -import { AssetType } from '@app/database'; +import { AssetType } from '@app/infra'; import { GetJobDto, JobId } from './dto/get-job.dto'; import { JobStatusResponseDto } from './response-dto/job-status-response.dto'; import { IMachineLearningJob } from '@app/job/interfaces/machine-learning.interface'; diff --git a/server/apps/immich/src/api-v1/oauth/oauth.controller.ts b/server/apps/immich/src/api-v1/oauth/oauth.controller.ts index a733e59430..d90197208e 100644 --- a/server/apps/immich/src/api-v1/oauth/oauth.controller.ts +++ b/server/apps/immich/src/api-v1/oauth/oauth.controller.ts @@ -6,7 +6,7 @@ import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator'; import { Authenticated } from '../../decorators/authenticated.decorator'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { LoginResponseDto } from '../auth/response-dto/login-response.dto'; -import { UserResponseDto } from '../user/response-dto/user-response.dto'; +import { UserResponseDto } from '@app/domain'; import { OAuthCallbackDto } from './dto/oauth-auth-code.dto'; import { OAuthConfigDto } from './dto/oauth-config.dto'; import { MOBILE_REDIRECT, OAuthService } from './oauth.service'; diff --git a/server/apps/immich/src/api-v1/oauth/oauth.module.ts b/server/apps/immich/src/api-v1/oauth/oauth.module.ts index 8d43799c27..ef703b7a6e 100644 --- a/server/apps/immich/src/api-v1/oauth/oauth.module.ts +++ b/server/apps/immich/src/api-v1/oauth/oauth.module.ts @@ -1,12 +1,11 @@ import { ImmichConfigModule } from '@app/immich-config'; import { Module } from '@nestjs/common'; import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module'; -import { UserModule } from '../user/user.module'; import { OAuthController } from './oauth.controller'; import { OAuthService } from './oauth.service'; @Module({ - imports: [UserModule, ImmichJwtModule, ImmichConfigModule], + imports: [ImmichJwtModule, ImmichConfigModule], controllers: [OAuthController], providers: [OAuthService], exports: [OAuthService], diff --git a/server/apps/immich/src/api-v1/oauth/oauth.service.spec.ts b/server/apps/immich/src/api-v1/oauth/oauth.service.spec.ts index 645c49ef5e..2dc60d3f3f 100644 --- a/server/apps/immich/src/api-v1/oauth/oauth.service.spec.ts +++ b/server/apps/immich/src/api-v1/oauth/oauth.service.spec.ts @@ -1,4 +1,4 @@ -import { SystemConfig, UserEntity } from '@app/database'; +import { SystemConfig, UserEntity } from '@app/infra'; import { ImmichConfigService } from '@app/immich-config'; import { BadRequestException } from '@nestjs/common'; import { generators, Issuer } from 'openid-client'; @@ -6,7 +6,7 @@ import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { LoginResponseDto } from '../auth/response-dto/login-response.dto'; import { OAuthService } from '../oauth/oauth.service'; -import { IUserRepository } from '../user/user-repository'; +import { IUserRepository } from '@app/domain'; const email = 'user@immich.com'; const sub = 'my-auth-user-sub'; diff --git a/server/apps/immich/src/api-v1/oauth/oauth.service.ts b/server/apps/immich/src/api-v1/oauth/oauth.service.ts index 6097dcd6ff..5f65556cac 100644 --- a/server/apps/immich/src/api-v1/oauth/oauth.service.ts +++ b/server/apps/immich/src/api-v1/oauth/oauth.service.ts @@ -1,13 +1,11 @@ -import { SystemConfig } from '@app/database/entities/system-config.entity'; +import { SystemConfig } from '@app/infra'; import { ImmichConfigService, INITIAL_SYSTEM_CONFIG } from '@app/immich-config'; import { BadRequestException, Inject, Injectable, Logger } from '@nestjs/common'; import { ClientMetadata, custom, generators, Issuer, UserinfoResponse } from 'openid-client'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; import { LoginResponseDto } from '../auth/response-dto/login-response.dto'; -import { UserResponseDto } from '../user/response-dto/user-response.dto'; -import { IUserRepository } from '../user/user-repository'; -import { UserCore } from '../user/user.core'; +import { IUserRepository, UserResponseDto, UserCore } from '@app/domain'; import { OAuthCallbackDto } from './dto/oauth-auth-code.dto'; import { OAuthConfigDto } from './dto/oauth-config.dto'; import { OAuthConfigResponseDto } from './response-dto/oauth-config-response.dto'; diff --git a/server/apps/immich/src/api-v1/server-info/server-info.module.ts b/server/apps/immich/src/api-v1/server-info/server-info.module.ts index 897b787bab..02bbbc3ca3 100644 --- a/server/apps/immich/src/api-v1/server-info/server-info.module.ts +++ b/server/apps/immich/src/api-v1/server-info/server-info.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; import { ServerInfoService } from './server-info.service'; import { ServerInfoController } from './server-info.controller'; -import { AssetEntity, UserEntity } from '@app/database'; +import { AssetEntity, UserEntity } from '@app/infra'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module'; diff --git a/server/apps/immich/src/api-v1/server-info/server-info.service.ts b/server/apps/immich/src/api-v1/server-info/server-info.service.ts index b8c9ea17b4..df13f81ed2 100644 --- a/server/apps/immich/src/api-v1/server-info/server-info.service.ts +++ b/server/apps/immich/src/api-v1/server-info/server-info.service.ts @@ -4,7 +4,7 @@ import { ServerInfoResponseDto } from './response-dto/server-info-response.dto'; import diskusage from 'diskusage'; import { ServerStatsResponseDto } from './response-dto/server-stats-response.dto'; import { UsageByUserDto } from './response-dto/usage-by-user-response.dto'; -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { asHumanReadable } from '../../utils/human-readable.util'; diff --git a/server/apps/immich/src/api-v1/share/dto/create-shared-link.dto.ts b/server/apps/immich/src/api-v1/share/dto/create-shared-link.dto.ts index 388fa67e7d..0d9e420c10 100644 --- a/server/apps/immich/src/api-v1/share/dto/create-shared-link.dto.ts +++ b/server/apps/immich/src/api-v1/share/dto/create-shared-link.dto.ts @@ -1,5 +1,5 @@ -import { AlbumEntity, AssetEntity } from '@app/database'; -import { SharedLinkType } from '@app/database/entities/shared-link.entity'; +import { AlbumEntity, AssetEntity } from '@app/infra'; +import { SharedLinkType } from '@app/infra'; export class CreateSharedLinkDto { description?: string; diff --git a/server/apps/immich/src/api-v1/share/response-dto/shared-link-response.dto.ts b/server/apps/immich/src/api-v1/share/response-dto/shared-link-response.dto.ts index a0490698e0..f4cdd8e0b5 100644 --- a/server/apps/immich/src/api-v1/share/response-dto/shared-link-response.dto.ts +++ b/server/apps/immich/src/api-v1/share/response-dto/shared-link-response.dto.ts @@ -1,4 +1,4 @@ -import { SharedLinkEntity, SharedLinkType } from '@app/database'; +import { SharedLinkEntity, SharedLinkType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; import _ from 'lodash'; import { AlbumResponseDto, mapAlbumExcludeAssetInfo } from '../../album/response-dto/album-response.dto'; diff --git a/server/apps/immich/src/api-v1/share/share.core.ts b/server/apps/immich/src/api-v1/share/share.core.ts index af14f41553..aeadf5b7de 100644 --- a/server/apps/immich/src/api-v1/share/share.core.ts +++ b/server/apps/immich/src/api-v1/share/share.core.ts @@ -1,9 +1,9 @@ -import { SharedLinkEntity } from '@app/database/entities/shared-link.entity'; +import { SharedLinkEntity } from '@app/infra'; import { CreateSharedLinkDto } from './dto/create-shared-link.dto'; import { ISharedLinkRepository } from './shared-link.repository'; import crypto from 'node:crypto'; import { BadRequestException, InternalServerErrorException, Logger } from '@nestjs/common'; -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { EditSharedLinkDto } from './dto/edit-shared-link.dto'; export class ShareCore { diff --git a/server/apps/immich/src/api-v1/share/share.module.ts b/server/apps/immich/src/api-v1/share/share.module.ts index 4b164de51b..1a4b759c4c 100644 --- a/server/apps/immich/src/api-v1/share/share.module.ts +++ b/server/apps/immich/src/api-v1/share/share.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; import { ShareService } from './share.service'; import { ShareController } from './share.controller'; -import { SharedLinkEntity } from '@app/database/entities/shared-link.entity'; +import { SharedLinkEntity } from '@app/infra'; import { TypeOrmModule } from '@nestjs/typeorm'; import { SharedLinkRepository, ISharedLinkRepository } from './shared-link.repository'; diff --git a/server/apps/immich/src/api-v1/share/shared-link.repository.ts b/server/apps/immich/src/api-v1/share/shared-link.repository.ts index d0ca0edd19..bc3d1778ce 100644 --- a/server/apps/immich/src/api-v1/share/shared-link.repository.ts +++ b/server/apps/immich/src/api-v1/share/shared-link.repository.ts @@ -1,4 +1,4 @@ -import { SharedLinkEntity } from '@app/database/entities/shared-link.entity'; +import { SharedLinkEntity } from '@app/infra'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; diff --git a/server/apps/immich/src/api-v1/system-config/dto/system-config.dto.ts b/server/apps/immich/src/api-v1/system-config/dto/system-config.dto.ts index 1bb2e736f8..9fc0035270 100644 --- a/server/apps/immich/src/api-v1/system-config/dto/system-config.dto.ts +++ b/server/apps/immich/src/api-v1/system-config/dto/system-config.dto.ts @@ -1,4 +1,4 @@ -import { SystemConfig } from '@app/database'; +import { SystemConfig } from '@app/infra'; import { ValidateNested } from 'class-validator'; import { SystemConfigFFmpegDto } from './system-config-ffmpeg.dto'; import { SystemConfigOAuthDto } from './system-config-oauth.dto'; diff --git a/server/apps/immich/src/api-v1/system-config/system-config.module.ts b/server/apps/immich/src/api-v1/system-config/system-config.module.ts index daf851f1b4..20ae0355d9 100644 --- a/server/apps/immich/src/api-v1/system-config/system-config.module.ts +++ b/server/apps/immich/src/api-v1/system-config/system-config.module.ts @@ -1,4 +1,4 @@ -import { SystemConfigEntity } from '@app/database'; +import { SystemConfigEntity } from '@app/infra'; import { immichSharedQueues } from '@app/job/constants/bull-queue-registration.constant'; import { BullModule } from '@nestjs/bull'; import { Module } from '@nestjs/common'; diff --git a/server/apps/immich/src/api-v1/tag/dto/create-tag.dto.ts b/server/apps/immich/src/api-v1/tag/dto/create-tag.dto.ts index 625d8ea1e9..8e7425da22 100644 --- a/server/apps/immich/src/api-v1/tag/dto/create-tag.dto.ts +++ b/server/apps/immich/src/api-v1/tag/dto/create-tag.dto.ts @@ -1,4 +1,4 @@ -import { TagType } from '@app/database'; +import { TagType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; import { IsEnum, IsNotEmpty, IsString } from 'class-validator'; diff --git a/server/apps/immich/src/api-v1/tag/response-dto/tag-response.dto.ts b/server/apps/immich/src/api-v1/tag/response-dto/tag-response.dto.ts index e0629559ba..294f944371 100644 --- a/server/apps/immich/src/api-v1/tag/response-dto/tag-response.dto.ts +++ b/server/apps/immich/src/api-v1/tag/response-dto/tag-response.dto.ts @@ -1,4 +1,4 @@ -import { TagEntity, TagType } from '@app/database'; +import { TagEntity, TagType } from '@app/infra'; import { ApiProperty } from '@nestjs/swagger'; export class TagResponseDto { diff --git a/server/apps/immich/src/api-v1/tag/tag.module.ts b/server/apps/immich/src/api-v1/tag/tag.module.ts index d5cfccfd51..a44b055b0a 100644 --- a/server/apps/immich/src/api-v1/tag/tag.module.ts +++ b/server/apps/immich/src/api-v1/tag/tag.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; import { TagService } from './tag.service'; import { TagController } from './tag.controller'; -import { TagEntity } from '@app/database'; +import { TagEntity } from '@app/infra'; import { TypeOrmModule } from '@nestjs/typeorm'; import { TagRepository, ITagRepository } from './tag.repository'; diff --git a/server/apps/immich/src/api-v1/tag/tag.repository.ts b/server/apps/immich/src/api-v1/tag/tag.repository.ts index 716f59b793..09391d4e27 100644 --- a/server/apps/immich/src/api-v1/tag/tag.repository.ts +++ b/server/apps/immich/src/api-v1/tag/tag.repository.ts @@ -1,4 +1,4 @@ -import { TagEntity, TagType } from '@app/database'; +import { TagEntity, TagType } from '@app/infra'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository } from 'typeorm'; diff --git a/server/apps/immich/src/api-v1/tag/tag.service.spec.ts b/server/apps/immich/src/api-v1/tag/tag.service.spec.ts index 872742f3d6..7a906012af 100644 --- a/server/apps/immich/src/api-v1/tag/tag.service.spec.ts +++ b/server/apps/immich/src/api-v1/tag/tag.service.spec.ts @@ -1,4 +1,4 @@ -import { TagEntity, TagType, UserEntity } from '@app/database'; +import { TagEntity, TagType, UserEntity } from '@app/infra'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { ITagRepository } from './tag.repository'; import { TagService } from './tag.service'; diff --git a/server/apps/immich/src/api-v1/tag/tag.service.ts b/server/apps/immich/src/api-v1/tag/tag.service.ts index 596a76f5f3..929178c362 100644 --- a/server/apps/immich/src/api-v1/tag/tag.service.ts +++ b/server/apps/immich/src/api-v1/tag/tag.service.ts @@ -1,4 +1,4 @@ -import { TagEntity } from '@app/database'; +import { TagEntity } from '@app/infra'; import { BadRequestException, Inject, Injectable, Logger } from '@nestjs/common'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { CreateTagDto } from './dto/create-tag.dto'; diff --git a/server/apps/immich/src/api-v1/user/user.module.ts b/server/apps/immich/src/api-v1/user/user.module.ts deleted file mode 100644 index 388a38667d..0000000000 --- a/server/apps/immich/src/api-v1/user/user.module.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { UserEntity } from '@app/database'; -import { Module } from '@nestjs/common'; -import { JwtModule } from '@nestjs/jwt'; -import { TypeOrmModule } from '@nestjs/typeorm'; -import { jwtConfig } from '../../config/jwt.config'; -import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module'; -import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service'; -import { UserRepository, IUserRepository } from './user-repository'; -import { UserController } from './user.controller'; -import { UserService } from './user.service'; - -const USER_REPOSITORY_PROVIDER = { - provide: IUserRepository, - useClass: UserRepository, -}; - -@Module({ - imports: [TypeOrmModule.forFeature([UserEntity]), ImmichJwtModule, JwtModule.register(jwtConfig)], - controllers: [UserController], - providers: [UserService, ImmichJwtService, USER_REPOSITORY_PROVIDER], - exports: [USER_REPOSITORY_PROVIDER], -}) -export class UserModule {} diff --git a/server/apps/immich/src/app.module.ts b/server/apps/immich/src/app.module.ts index 46db47b402..cea3ef1998 100644 --- a/server/apps/immich/src/app.module.ts +++ b/server/apps/immich/src/app.module.ts @@ -1,6 +1,5 @@ import { immichAppConfig, immichBullAsyncConfig } from '@app/common/config'; import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; -import { UserModule } from './api-v1/user/user.module'; import { AssetModule } from './api-v1/asset/asset.module'; import { AuthModule } from './api-v1/auth/auth.module'; import { APIKeyModule } from './api-v1/api-key/api-key.module'; @@ -15,20 +14,23 @@ import { AlbumModule } from './api-v1/album/album.module'; import { AppController } from './app.controller'; import { ScheduleModule } from '@nestjs/schedule'; import { ScheduleTasksModule } from './modules/schedule-tasks/schedule-tasks.module'; -import { DatabaseModule } from '@app/database'; import { JobModule } from './api-v1/job/job.module'; import { SystemConfigModule } from './api-v1/system-config/system-config.module'; import { OAuthModule } from './api-v1/oauth/oauth.module'; import { TagModule } from './api-v1/tag/tag.module'; import { ImmichConfigModule } from '@app/immich-config'; import { ShareModule } from './api-v1/share/share.module'; +import { DomainModule } from '@app/domain'; +import { InfraModule } from '@app/infra'; +import { UserController } from './controllers'; @Module({ imports: [ ConfigModule.forRoot(immichAppConfig), - DatabaseModule, - UserModule, + DomainModule.register({ + imports: [InfraModule], + }), APIKeyModule, @@ -64,7 +66,11 @@ import { ShareModule } from './api-v1/share/share.module'; ShareModule, ], - controllers: [AppController], + controllers: [ + // + AppController, + UserController, + ], providers: [], }) export class AppModule implements NestModule { diff --git a/server/apps/immich/src/config/asset-upload.config.ts b/server/apps/immich/src/config/asset-upload.config.ts index 4aca54bb87..dcf8dfb6a7 100644 --- a/server/apps/immich/src/config/asset-upload.config.ts +++ b/server/apps/immich/src/config/asset-upload.config.ts @@ -51,7 +51,7 @@ function destination(req: Request, file: Express.Multer.File, cb: any) { const basePath = APP_UPLOAD_LOCATION; const sanitizedDeviceId = sanitize(String(req.body['deviceId'])); - const originalUploadFolder = join(basePath, req.user.id, 'original', sanitizedDeviceId); + const originalUploadFolder = join(basePath, user.id, 'original', sanitizedDeviceId); if (!existsSync(originalUploadFolder)) { mkdirSync(originalUploadFolder, { recursive: true }); diff --git a/server/apps/immich/src/config/profile-image-upload.config.ts b/server/apps/immich/src/config/profile-image-upload.config.ts index 05d9bcfc55..a9bcd47f5f 100644 --- a/server/apps/immich/src/config/profile-image-upload.config.ts +++ b/server/apps/immich/src/config/profile-image-upload.config.ts @@ -6,6 +6,7 @@ import { existsSync, mkdirSync } from 'fs'; import { diskStorage } from 'multer'; import { extname } from 'path'; import sanitize from 'sanitize-filename'; +import { AuthUserDto } from '../decorators/auth-user.decorator'; import { patchFormData } from '../utils/path-form-data.util'; export const profileImageUploadOption: MulterOptions = { @@ -35,8 +36,10 @@ function destination(req: Request, file: Express.Multer.File, cb: any) { return cb(new UnauthorizedException()); } + const user = req.user as AuthUserDto; + const basePath = APP_UPLOAD_LOCATION; - const profileImageLocation = `${basePath}/${req.user.id}/profile`; + const profileImageLocation = `${basePath}/${user.id}/profile`; if (!existsSync(profileImageLocation)) { mkdirSync(profileImageLocation, { recursive: true }); diff --git a/server/apps/immich/src/controllers/index.ts b/server/apps/immich/src/controllers/index.ts new file mode 100644 index 0000000000..edd3705c44 --- /dev/null +++ b/server/apps/immich/src/controllers/index.ts @@ -0,0 +1 @@ +export * from './user.controller'; diff --git a/server/apps/immich/src/api-v1/user/user.controller.ts b/server/apps/immich/src/controllers/user.controller.ts similarity index 81% rename from server/apps/immich/src/api-v1/user/user.controller.ts rename to server/apps/immich/src/controllers/user.controller.ts index 2d630625f9..364192203a 100644 --- a/server/apps/immich/src/api-v1/user/user.controller.ts +++ b/server/apps/immich/src/controllers/user.controller.ts @@ -15,20 +15,20 @@ import { StreamableFile, Header, } from '@nestjs/common'; -import { UserService } from './user.service'; -import { Authenticated } from '../../decorators/authenticated.decorator'; -import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator'; -import { CreateUserDto } from './dto/create-user.dto'; -import { UpdateUserDto } from './dto/update-user.dto'; +import { UserService } from '@app/domain'; +import { Authenticated } from '../decorators/authenticated.decorator'; +import { AuthUserDto, GetAuthUser } from '../decorators/auth-user.decorator'; +import { CreateUserDto } from '@app/domain'; +import { UpdateUserDto } from '@app/domain'; import { FileInterceptor } from '@nestjs/platform-express'; -import { profileImageUploadOption } from '../../config/profile-image-upload.config'; +import { profileImageUploadOption } from '../config/profile-image-upload.config'; import { Response as Res } from 'express'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; -import { UserResponseDto } from './response-dto/user-response.dto'; -import { UserCountResponseDto } from './response-dto/user-count-response.dto'; -import { CreateProfileImageDto } from './dto/create-profile-image.dto'; -import { CreateProfileImageResponseDto } from './response-dto/create-profile-image-response.dto'; -import { UserCountDto } from './dto/user-count.dto'; +import { UserResponseDto } from '@app/domain'; +import { UserCountResponseDto } from '@app/domain'; +import { CreateProfileImageDto } from '@app/domain'; +import { CreateProfileImageResponseDto } from '@app/domain'; +import { UserCountDto } from '@app/domain'; @ApiTags('User') @Controller('user') diff --git a/server/apps/immich/src/decorators/auth-user.decorator.ts b/server/apps/immich/src/decorators/auth-user.decorator.ts index 3b5ab6d199..0ccde28db5 100644 --- a/server/apps/immich/src/decorators/auth-user.decorator.ts +++ b/server/apps/immich/src/decorators/auth-user.decorator.ts @@ -1,14 +1,6 @@ +export { AuthUserDto } from '@app/domain'; +import { AuthUserDto } from '@app/domain'; import { createParamDecorator, ExecutionContext } from '@nestjs/common'; -// import { AuthUserDto } from './dto/auth-user.dto'; - -export class AuthUserDto { - id!: string; - email!: string; - isAdmin!: boolean; - isPublicUser?: boolean; - sharedLinkId?: string; - isAllowUpload?: boolean; -} export const GetAuthUser = createParamDecorator((data, ctx: ExecutionContext): AuthUserDto => { return ctx.switchToHttp().getRequest<{ user: AuthUserDto }>().user; diff --git a/server/apps/immich/src/global.d.ts b/server/apps/immich/src/global.d.ts index e37c9b5716..a5867b0ed6 100644 --- a/server/apps/immich/src/global.d.ts +++ b/server/apps/immich/src/global.d.ts @@ -1,8 +1,8 @@ -import { UserResponseDto } from './api-v1/user/response-dto/user-response.dto'; +import { AuthUserDto } from './decorators/auth-user.decorator'; declare global { namespace Express { // eslint-disable-next-line @typescript-eslint/no-empty-interface - interface User extends UserResponseDto {} + interface User extends AuthUserDto {} } } diff --git a/server/apps/immich/src/middlewares/admin-role-guard.middleware.ts b/server/apps/immich/src/middlewares/admin-role-guard.middleware.ts index ea22c0560e..37a3be1e4b 100644 --- a/server/apps/immich/src/middlewares/admin-role-guard.middleware.ts +++ b/server/apps/immich/src/middlewares/admin-role-guard.middleware.ts @@ -1,6 +1,6 @@ import { CanActivate, ExecutionContext, Injectable, Logger } from '@nestjs/common'; import { Request } from 'express'; -import { UserResponseDto } from '../api-v1/user/response-dto/user-response.dto'; +import { UserResponseDto } from '@app/domain'; interface UserRequest extends Request { user: UserResponseDto; diff --git a/server/apps/immich/src/modules/background-task/background-task.module.ts b/server/apps/immich/src/modules/background-task/background-task.module.ts index c418dd634f..b862e13601 100644 --- a/server/apps/immich/src/modules/background-task/background-task.module.ts +++ b/server/apps/immich/src/modules/background-task/background-task.module.ts @@ -1,7 +1,7 @@ import { BullModule } from '@nestjs/bull'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { AssetEntity, ExifEntity, SmartInfoEntity } from '@app/database'; +import { AssetEntity, ExifEntity, SmartInfoEntity } from '@app/infra'; import { BackgroundTaskProcessor } from './background-task.processor'; import { BackgroundTaskService } from './background-task.service'; diff --git a/server/apps/immich/src/modules/background-task/background-task.processor.ts b/server/apps/immich/src/modules/background-task/background-task.processor.ts index 3d4278de19..5d7eee1d9e 100644 --- a/server/apps/immich/src/modules/background-task/background-task.processor.ts +++ b/server/apps/immich/src/modules/background-task/background-task.processor.ts @@ -1,7 +1,7 @@ import { Process, Processor } from '@nestjs/bull'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; -import { AssetEntity, SmartInfoEntity } from '@app/database'; +import { AssetEntity, SmartInfoEntity } from '@app/infra'; import { Job } from 'bull'; import { AssetResponseDto } from '../../api-v1/asset/response-dto/asset-response.dto'; import { assetUtils } from '@app/common/utils'; diff --git a/server/apps/immich/src/modules/download/download.service.ts b/server/apps/immich/src/modules/download/download.service.ts index 168d5aff3f..7b541be9e2 100644 --- a/server/apps/immich/src/modules/download/download.service.ts +++ b/server/apps/immich/src/modules/download/download.service.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { BadRequestException, Injectable, InternalServerErrorException, Logger, StreamableFile } from '@nestjs/common'; import archiver from 'archiver'; import { extname } from 'path'; diff --git a/server/apps/immich/src/modules/immich-jwt/immich-jwt.module.ts b/server/apps/immich/src/modules/immich-jwt/immich-jwt.module.ts index c1d04f4c86..74cdfd15e9 100644 --- a/server/apps/immich/src/modules/immich-jwt/immich-jwt.module.ts +++ b/server/apps/immich/src/modules/immich-jwt/immich-jwt.module.ts @@ -4,7 +4,7 @@ import { JwtModule } from '@nestjs/jwt'; import { jwtConfig } from '../../config/jwt.config'; import { JwtStrategy } from './strategies/jwt.strategy'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { APIKeyModule } from '../../api-v1/api-key/api-key.module'; import { APIKeyStrategy } from './strategies/api-key.strategy'; import { ShareModule } from '../../api-v1/share/share.module'; diff --git a/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.spec.ts b/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.spec.ts index 904e1baf52..6ffe150247 100644 --- a/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.spec.ts +++ b/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.spec.ts @@ -1,7 +1,7 @@ import { Logger } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Request } from 'express'; -import { UserEntity } from '../../../../../libs/database/src/entities/user.entity'; +import { UserEntity } from '@app/infra'; import { LoginResponseDto } from '../../api-v1/auth/response-dto/login-response.dto'; import { AuthType } from '../../constants/jwt.constant'; import { ImmichJwtService } from './immich-jwt.service'; diff --git a/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.ts b/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.ts index 3b3c010bd6..6765d24123 100644 --- a/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.ts +++ b/server/apps/immich/src/modules/immich-jwt/immich-jwt.service.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { Injectable, Logger } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Request } from 'express'; diff --git a/server/apps/immich/src/modules/immich-jwt/strategies/jwt.strategy.ts b/server/apps/immich/src/modules/immich-jwt/strategies/jwt.strategy.ts index 551aa3a796..b11b79336c 100644 --- a/server/apps/immich/src/modules/immich-jwt/strategies/jwt.strategy.ts +++ b/server/apps/immich/src/modules/immich-jwt/strategies/jwt.strategy.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { InjectRepository } from '@nestjs/typeorm'; diff --git a/server/apps/immich/src/modules/immich-jwt/strategies/public-share.strategy.ts b/server/apps/immich/src/modules/immich-jwt/strategies/public-share.strategy.ts index f3e79eef5f..c4953e518b 100644 --- a/server/apps/immich/src/modules/immich-jwt/strategies/public-share.strategy.ts +++ b/server/apps/immich/src/modules/immich-jwt/strategies/public-share.strategy.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { InjectRepository } from '@nestjs/typeorm'; diff --git a/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.module.ts b/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.module.ts index 7e4dc13190..55b55a3785 100644 --- a/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.module.ts +++ b/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.module.ts @@ -1,7 +1,7 @@ import { BullModule } from '@nestjs/bull'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { AssetEntity, ExifEntity, UserEntity } from '@app/database'; +import { AssetEntity, ExifEntity, UserEntity } from '@app/infra'; import { ScheduleTasksService } from './schedule-tasks.service'; import { immichSharedQueues } from '@app/job/constants/bull-queue-registration.constant'; diff --git a/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.service.ts b/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.service.ts index e4ff8011e9..41c61cfcb7 100644 --- a/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.service.ts +++ b/server/apps/immich/src/modules/schedule-tasks/schedule-tasks.service.ts @@ -2,7 +2,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { Cron, CronExpression } from '@nestjs/schedule'; import { InjectRepository } from '@nestjs/typeorm'; import { IsNull, Not, Repository } from 'typeorm'; -import { AssetEntity, AssetType, ExifEntity, UserEntity } from '@app/database'; +import { AssetEntity, AssetType, ExifEntity, UserEntity } from '@app/infra'; import { InjectQueue } from '@nestjs/bull'; import { Queue } from 'bull'; import { randomUUID } from 'crypto'; diff --git a/server/apps/immich/test/album.e2e-spec.ts b/server/apps/immich/test/album.e2e-spec.ts index bd712935c0..f9436dda73 100644 --- a/server/apps/immich/test/album.e2e-spec.ts +++ b/server/apps/immich/test/album.e2e-spec.ts @@ -3,13 +3,12 @@ import { INestApplication } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import request from 'supertest'; import { clearDb, getAuthUser, authCustom } from './test-utils'; -import { databaseConfig } from '@app/database'; +import { databaseConfig } from '@app/infra'; import { AlbumModule } from '../src/api-v1/album/album.module'; import { CreateAlbumDto } from '../src/api-v1/album/dto/create-album.dto'; import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module'; import { AuthUserDto } from '../src/decorators/auth-user.decorator'; -import { UserService } from '../src/api-v1/user/user.service'; -import { UserModule } from '../src/api-v1/user/user.module'; +import { UserService } from '@app/domain'; import { DataSource } from 'typeorm'; function _createAlbum(app: INestApplication, data: CreateAlbumDto) { @@ -52,7 +51,7 @@ describe('Album', () => { beforeAll(async () => { const builder = Test.createTestingModule({ - imports: [AlbumModule, UserModule, TypeOrmModule.forRoot(databaseConfig)], + imports: [AlbumModule, TypeOrmModule.forRoot(databaseConfig)], }); authUser = getAuthUser(); // set default auth user const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile(); diff --git a/server/apps/immich/test/jest-e2e.json b/server/apps/immich/test/jest-e2e.json index 22d705c712..cdfdc853fb 100644 --- a/server/apps/immich/test/jest-e2e.json +++ b/server/apps/immich/test/jest-e2e.json @@ -7,15 +7,11 @@ "^.+\\.(t|j)s$": "ts-jest" }, "moduleNameMapper": { - "^@app/database(|/.*)$": "../../../libs/database/src/$1", - "@app/database/config": "../../../libs/database/src/config", - "@app/database/config/(.*)": "../../../libs/database/src/config/$1", - "@app/database/entities/(.*)": "../../../libs/database/src/entities/$1", - "@app/common": "../../../libs/common/src", - "@app/common/(.*)": "../../../libs/common/src/$1", + "^@app/common": "../../../libs/common/src", "^@app/job(|/.*)$": "../../../libs/job/src/$1", - "@app/job": "../../../libs/job/src", "^@app/immich-config(|/.*)$": "../../../libs/immich-config/src/$1", - "^@app/storage(|/.*)$": "../../../libs/storage/src/$1" + "^@app/storage(|/.*)$": "../../../libs/storage/src/$1", + "^@app/infra(|/.*)$": "../../../libs/infra/src/$1", + "^@app/domain(|/.*)$": "../../../libs/domain/src/$1" } } diff --git a/server/apps/immich/test/test-utils.ts b/server/apps/immich/test/test-utils.ts index c3fd091ad2..9ab27ff3c9 100644 --- a/server/apps/immich/test/test-utils.ts +++ b/server/apps/immich/test/test-utils.ts @@ -1,7 +1,6 @@ import { CanActivate, ExecutionContext } from '@nestjs/common'; import { TestingModuleBuilder } from '@nestjs/testing'; import { DataSource } from 'typeorm'; -import { IUserRepository } from '../src/api-v1/user/user-repository'; import { AuthUserDto } from '../src/decorators/auth-user.decorator'; import { AuthGuard } from '../src/modules/immich-jwt/guards/auth.guard'; @@ -15,20 +14,6 @@ export async function clearDb(db: DataSource) { } } -export function newUserRepositoryMock(): jest.Mocked { - return { - get: jest.fn(), - getAdmin: jest.fn(), - getByEmail: jest.fn(), - getByOAuthId: jest.fn(), - getList: jest.fn(), - create: jest.fn(), - update: jest.fn(), - delete: jest.fn(), - restore: jest.fn(), - }; -} - export function getAuthUser(): AuthUserDto { return { id: '3108ac14-8afb-4b7e-87fd-39ebb6b79750', diff --git a/server/apps/immich/test/user.e2e-spec.ts b/server/apps/immich/test/user.e2e-spec.ts index 5342897e6f..5d67689c47 100644 --- a/server/apps/immich/test/user.e2e-spec.ts +++ b/server/apps/immich/test/user.e2e-spec.ts @@ -3,12 +3,9 @@ import { INestApplication } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import request from 'supertest'; import { clearDb, authCustom } from './test-utils'; -import { databaseConfig } from '@app/database/config/database.config'; -import { UserModule } from '../src/api-v1/user/user.module'; +import { databaseConfig } from '@app/infra'; import { ImmichJwtModule } from '../src/modules/immich-jwt/immich-jwt.module'; -import { UserService } from '../src/api-v1/user/user.service'; -import { CreateAdminDto, CreateUserDto } from '../src/api-v1/user/dto/create-user.dto'; -import { UserResponseDto } from '../src/api-v1/user/response-dto/user-response.dto'; +import { CreateAdminDto, CreateUserDto, UserResponseDto, UserService } from '@app/domain'; import { DataSource } from 'typeorm'; function _createUser(userService: UserService, data: CreateUserDto | CreateAdminDto) { @@ -27,7 +24,7 @@ describe('User', () => { describe('without auth', () => { beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [UserModule, ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)], + imports: [ImmichJwtModule, TypeOrmModule.forRoot(databaseConfig)], }).compile(); app = moduleFixture.createNestApplication(); @@ -51,7 +48,7 @@ describe('User', () => { beforeAll(async () => { const builder = Test.createTestingModule({ - imports: [UserModule, TypeOrmModule.forRoot(databaseConfig)], + imports: [TypeOrmModule.forRoot(databaseConfig)], }); const moduleFixture: TestingModule = await authCustom(builder, () => authUser).compile(); diff --git a/server/apps/microservices/src/microservices.module.ts b/server/apps/microservices/src/microservices.module.ts index ebb2a9be38..ba447c656f 100644 --- a/server/apps/microservices/src/microservices.module.ts +++ b/server/apps/microservices/src/microservices.module.ts @@ -1,5 +1,5 @@ import { immichAppConfig, immichBullAsyncConfig } from '@app/common/config'; -import { DatabaseModule, AssetEntity, ExifEntity, SmartInfoEntity, UserEntity, APIKeyEntity } from '@app/database'; +import { AssetEntity, ExifEntity, SmartInfoEntity, UserEntity, APIKeyEntity, InfraModule } from '@app/infra'; import { StorageModule } from '@app/storage'; import { BullModule } from '@nestjs/bull'; import { Module } from '@nestjs/common'; @@ -17,11 +17,14 @@ import { ThumbnailGeneratorProcessor } from './processors/thumbnail.processor'; import { UserDeletionProcessor } from './processors/user-deletion.processor'; import { VideoTranscodeProcessor } from './processors/video-transcode.processor'; import { immichSharedQueues } from '@app/job/constants/bull-queue-registration.constant'; +import { DomainModule } from '@app/domain'; @Module({ imports: [ ConfigModule.forRoot(immichAppConfig), - DatabaseModule, + DomainModule.register({ + imports: [InfraModule], + }), ImmichConfigModule, TypeOrmModule.forFeature([UserEntity, ExifEntity, AssetEntity, SmartInfoEntity, APIKeyEntity]), StorageModule, diff --git a/server/apps/microservices/src/processors/asset-uploaded.processor.ts b/server/apps/microservices/src/processors/asset-uploaded.processor.ts index f92a2830b7..dc13e63ad6 100644 --- a/server/apps/microservices/src/processors/asset-uploaded.processor.ts +++ b/server/apps/microservices/src/processors/asset-uploaded.processor.ts @@ -1,4 +1,4 @@ -import { AssetType } from '@app/database'; +import { AssetType } from '@app/infra'; import { IAssetUploadedJob, IMetadataExtractionJob, diff --git a/server/apps/microservices/src/processors/generate-checksum.processor.ts b/server/apps/microservices/src/processors/generate-checksum.processor.ts index f6c1954ceb..b5e2f60c82 100644 --- a/server/apps/microservices/src/processors/generate-checksum.processor.ts +++ b/server/apps/microservices/src/processors/generate-checksum.processor.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { QueueNameEnum } from '@app/job'; import { Process, Processor } from '@nestjs/bull'; import { Logger } from '@nestjs/common'; diff --git a/server/apps/microservices/src/processors/machine-learning.processor.ts b/server/apps/microservices/src/processors/machine-learning.processor.ts index 807d1ad33c..a0a61f8fed 100644 --- a/server/apps/microservices/src/processors/machine-learning.processor.ts +++ b/server/apps/microservices/src/processors/machine-learning.processor.ts @@ -1,5 +1,5 @@ -import { AssetEntity } from '@app/database'; -import { SmartInfoEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; +import { SmartInfoEntity } from '@app/infra'; import { MachineLearningJobNameEnum, QueueNameEnum } from '@app/job'; import { IMachineLearningJob } from '@app/job/interfaces/machine-learning.interface'; import { Process, Processor } from '@nestjs/bull'; diff --git a/server/apps/microservices/src/processors/metadata-extraction.processor.ts b/server/apps/microservices/src/processors/metadata-extraction.processor.ts index ba38800a7b..e5428fb538 100644 --- a/server/apps/microservices/src/processors/metadata-extraction.processor.ts +++ b/server/apps/microservices/src/processors/metadata-extraction.processor.ts @@ -1,5 +1,5 @@ import { ImmichLogLevel } from '@app/common/constants/log-level.constant'; -import { AssetEntity, ExifEntity } from '@app/database'; +import { AssetEntity, ExifEntity } from '@app/infra'; import { IExifExtractionProcessor, IVideoLengthExtractionProcessor, diff --git a/server/apps/microservices/src/processors/storage-migration.processor.ts b/server/apps/microservices/src/processors/storage-migration.processor.ts index f5714c1dba..7dff2e1cb7 100644 --- a/server/apps/microservices/src/processors/storage-migration.processor.ts +++ b/server/apps/microservices/src/processors/storage-migration.processor.ts @@ -1,5 +1,5 @@ import { APP_UPLOAD_LOCATION } from '@app/common'; -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { ImmichConfigService } from '@app/immich-config'; import { QueueNameEnum, templateMigrationProcessorName, updateTemplateProcessorName } from '@app/job'; import { StorageService } from '@app/storage'; diff --git a/server/apps/microservices/src/processors/thumbnail.processor.ts b/server/apps/microservices/src/processors/thumbnail.processor.ts index 6cafab40bc..352fcd691b 100644 --- a/server/apps/microservices/src/processors/thumbnail.processor.ts +++ b/server/apps/microservices/src/processors/thumbnail.processor.ts @@ -1,5 +1,5 @@ import { APP_UPLOAD_LOCATION } from '@app/common'; -import { AssetEntity, AssetType } from '@app/database'; +import { AssetEntity, AssetType } from '@app/infra'; import { WebpGeneratorProcessor, generateJPEGThumbnailProcessorName, diff --git a/server/apps/microservices/src/processors/user-deletion.processor.ts b/server/apps/microservices/src/processors/user-deletion.processor.ts index 9b5ef4d5b4..4e7097a080 100644 --- a/server/apps/microservices/src/processors/user-deletion.processor.ts +++ b/server/apps/microservices/src/processors/user-deletion.processor.ts @@ -1,5 +1,5 @@ import { APP_UPLOAD_LOCATION, userUtils } from '@app/common'; -import { APIKeyEntity, AssetEntity, UserEntity } from '@app/database'; +import { APIKeyEntity, AssetEntity, UserEntity } from '@app/infra'; import { QueueNameEnum, userDeletionProcessorName } from '@app/job'; import { IUserDeletionJob } from '@app/job/interfaces/user-deletion.interface'; import { Process, Processor } from '@nestjs/bull'; diff --git a/server/apps/microservices/src/processors/video-transcode.processor.ts b/server/apps/microservices/src/processors/video-transcode.processor.ts index 793e68076d..891d9ecf54 100644 --- a/server/apps/microservices/src/processors/video-transcode.processor.ts +++ b/server/apps/microservices/src/processors/video-transcode.processor.ts @@ -1,5 +1,5 @@ import { APP_UPLOAD_LOCATION } from '@app/common/constants'; -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { QueueNameEnum } from '@app/job'; import { mp4ConversionProcessorName } from '@app/job/constants/job-name.constant'; import { IMp4ConversionProcessor } from '@app/job/interfaces/video-transcode.interface'; diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index 0329f2fe1c..ad7927fde2 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -473,147 +473,6 @@ ] } }, - "/share": { - "get": { - "operationId": "getAllSharedLinks", - "parameters": [], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/SharedLinkResponseDto" - } - } - } - } - } - }, - "tags": [ - "share" - ] - } - }, - "/share/me": { - "get": { - "operationId": "getMySharedLink", - "parameters": [], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SharedLinkResponseDto" - } - } - } - } - }, - "tags": [ - "share" - ] - } - }, - "/share/{id}": { - "get": { - "operationId": "getSharedLinkById", - "parameters": [ - { - "name": "id", - "required": true, - "in": "path", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SharedLinkResponseDto" - } - } - } - } - }, - "tags": [ - "share" - ] - }, - "delete": { - "operationId": "removeSharedLink", - "parameters": [ - { - "name": "id", - "required": true, - "in": "path", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "string" - } - } - } - } - }, - "tags": [ - "share" - ] - }, - "patch": { - "operationId": "editSharedLink", - "parameters": [ - { - "name": "id", - "required": true, - "in": "path", - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/EditSharedLinkDto" - } - } - } - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SharedLinkResponseDto" - } - } - } - } - }, - "tags": [ - "share" - ] - } - }, "/asset/upload": { "post": { "operationId": "uploadFile", @@ -1370,6 +1229,147 @@ ] } }, + "/share": { + "get": { + "operationId": "getAllSharedLinks", + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/SharedLinkResponseDto" + } + } + } + } + } + }, + "tags": [ + "share" + ] + } + }, + "/share/me": { + "get": { + "operationId": "getMySharedLink", + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SharedLinkResponseDto" + } + } + } + } + }, + "tags": [ + "share" + ] + } + }, + "/share/{id}": { + "get": { + "operationId": "getSharedLinkById", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SharedLinkResponseDto" + } + } + } + } + }, + "tags": [ + "share" + ] + }, + "delete": { + "operationId": "removeSharedLink", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + } + }, + "tags": [ + "share" + ] + }, + "patch": { + "operationId": "editSharedLink", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/EditSharedLinkDto" + } + } + } + }, + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SharedLinkResponseDto" + } + } + } + } + }, + "tags": [ + "share" + ] + } + }, "/album/count-by-user-id": { "get": { "operationId": "getAlbumCountByUserId", @@ -2879,11 +2879,114 @@ "name" ] }, - "SharedLinkType": { + "AssetFileUploadDto": { + "type": "object", + "properties": { + "assetData": { + "type": "string", + "format": "binary" + } + }, + "required": [ + "assetData" + ] + }, + "AssetFileUploadResponseDto": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + }, + "DownloadFilesDto": { + "type": "object", + "properties": { + "assetIds": { + "title": "Array of asset ids to be downloaded", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "assetIds" + ] + }, + "ThumbnailFormat": { "type": "string", "enum": [ - "ALBUM", - "INDIVIDUAL" + "JPEG", + "WEBP" + ] + }, + "CuratedObjectsResponseDto": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "object": { + "type": "string" + }, + "resizePath": { + "type": "string" + }, + "deviceAssetId": { + "type": "string" + }, + "deviceId": { + "type": "string" + } + }, + "required": [ + "id", + "object", + "resizePath", + "deviceAssetId", + "deviceId" + ] + }, + "CuratedLocationsResponseDto": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "city": { + "type": "string" + }, + "resizePath": { + "type": "string" + }, + "deviceAssetId": { + "type": "string" + }, + "deviceId": { + "type": "string" + } + }, + "required": [ + "id", + "city", + "resizePath", + "deviceAssetId", + "deviceId" + ] + }, + "SearchAssetDto": { + "type": "object", + "properties": { + "searchTerm": { + "type": "string" + } + }, + "required": [ + "searchTerm" ] }, "AssetTypeEnum": { @@ -3144,232 +3247,6 @@ "tags" ] }, - "AlbumResponseDto": { - "type": "object", - "properties": { - "assetCount": { - "type": "integer" - }, - "id": { - "type": "string" - }, - "ownerId": { - "type": "string" - }, - "albumName": { - "type": "string" - }, - "createdAt": { - "type": "string" - }, - "albumThumbnailAssetId": { - "type": "string", - "nullable": true - }, - "shared": { - "type": "boolean" - }, - "sharedUsers": { - "type": "array", - "items": { - "$ref": "#/components/schemas/UserResponseDto" - } - }, - "assets": { - "type": "array", - "items": { - "$ref": "#/components/schemas/AssetResponseDto" - } - } - }, - "required": [ - "assetCount", - "id", - "ownerId", - "albumName", - "createdAt", - "albumThumbnailAssetId", - "shared", - "sharedUsers", - "assets" - ] - }, - "SharedLinkResponseDto": { - "type": "object", - "properties": { - "type": { - "$ref": "#/components/schemas/SharedLinkType" - }, - "id": { - "type": "string" - }, - "description": { - "type": "string" - }, - "userId": { - "type": "string" - }, - "key": { - "type": "string" - }, - "createdAt": { - "type": "string" - }, - "expiresAt": { - "type": "string", - "nullable": true - }, - "assets": { - "type": "array", - "items": { - "$ref": "#/components/schemas/AssetResponseDto" - } - }, - "album": { - "$ref": "#/components/schemas/AlbumResponseDto" - }, - "allowUpload": { - "type": "boolean" - } - }, - "required": [ - "type", - "id", - "userId", - "key", - "createdAt", - "expiresAt", - "assets", - "allowUpload" - ] - }, - "EditSharedLinkDto": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "expiredAt": { - "type": "string" - }, - "allowUpload": { - "type": "boolean" - }, - "isEditExpireTime": { - "type": "boolean" - } - } - }, - "AssetFileUploadDto": { - "type": "object", - "properties": { - "assetData": { - "type": "string", - "format": "binary" - } - }, - "required": [ - "assetData" - ] - }, - "AssetFileUploadResponseDto": { - "type": "object", - "properties": { - "id": { - "type": "string" - } - }, - "required": [ - "id" - ] - }, - "DownloadFilesDto": { - "type": "object", - "properties": { - "assetIds": { - "title": "Array of asset ids to be downloaded", - "type": "array", - "items": { - "type": "string" - } - } - }, - "required": [ - "assetIds" - ] - }, - "ThumbnailFormat": { - "type": "string", - "enum": [ - "JPEG", - "WEBP" - ] - }, - "CuratedObjectsResponseDto": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "object": { - "type": "string" - }, - "resizePath": { - "type": "string" - }, - "deviceAssetId": { - "type": "string" - }, - "deviceId": { - "type": "string" - } - }, - "required": [ - "id", - "object", - "resizePath", - "deviceAssetId", - "deviceId" - ] - }, - "CuratedLocationsResponseDto": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "city": { - "type": "string" - }, - "resizePath": { - "type": "string" - }, - "deviceAssetId": { - "type": "string" - }, - "deviceId": { - "type": "string" - } - }, - "required": [ - "id", - "city", - "resizePath", - "deviceAssetId", - "deviceId" - ] - }, - "SearchAssetDto": { - "type": "object", - "properties": { - "searchTerm": { - "type": "string" - } - }, - "required": [ - "searchTerm" - ] - }, "TimeGroupEnum": { "type": "string", "enum": [ @@ -3596,6 +3473,129 @@ "existingIds" ] }, + "SharedLinkType": { + "type": "string", + "enum": [ + "ALBUM", + "INDIVIDUAL" + ] + }, + "AlbumResponseDto": { + "type": "object", + "properties": { + "assetCount": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "ownerId": { + "type": "string" + }, + "albumName": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "albumThumbnailAssetId": { + "type": "string", + "nullable": true + }, + "shared": { + "type": "boolean" + }, + "sharedUsers": { + "type": "array", + "items": { + "$ref": "#/components/schemas/UserResponseDto" + } + }, + "assets": { + "type": "array", + "items": { + "$ref": "#/components/schemas/AssetResponseDto" + } + } + }, + "required": [ + "assetCount", + "id", + "ownerId", + "albumName", + "createdAt", + "albumThumbnailAssetId", + "shared", + "sharedUsers", + "assets" + ] + }, + "SharedLinkResponseDto": { + "type": "object", + "properties": { + "type": { + "$ref": "#/components/schemas/SharedLinkType" + }, + "id": { + "type": "string" + }, + "description": { + "type": "string" + }, + "userId": { + "type": "string" + }, + "key": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "expiresAt": { + "type": "string", + "nullable": true + }, + "assets": { + "type": "array", + "items": { + "$ref": "#/components/schemas/AssetResponseDto" + } + }, + "album": { + "$ref": "#/components/schemas/AlbumResponseDto" + }, + "allowUpload": { + "type": "boolean" + } + }, + "required": [ + "type", + "id", + "userId", + "key", + "createdAt", + "expiresAt", + "assets", + "allowUpload" + ] + }, + "EditSharedLinkDto": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "expiredAt": { + "type": "string" + }, + "allowUpload": { + "type": "boolean" + }, + "isEditExpireTime": { + "type": "boolean" + } + } + }, "AlbumCountResponseDto": { "type": "object", "properties": { diff --git a/server/libs/common/src/utils/asset-utils.ts b/server/libs/common/src/utils/asset-utils.ts index cebbfad142..f130c49548 100644 --- a/server/libs/common/src/utils/asset-utils.ts +++ b/server/libs/common/src/utils/asset-utils.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; import { AssetResponseDto } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto'; import fs from 'fs'; diff --git a/server/libs/common/src/utils/user-utils.spec.ts b/server/libs/common/src/utils/user-utils.spec.ts index 849b84988c..c3aa242a22 100644 --- a/server/libs/common/src/utils/user-utils.spec.ts +++ b/server/libs/common/src/utils/user-utils.spec.ts @@ -1,6 +1,6 @@ // create unit test for user utils -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { userUtils } from './user-utils'; describe('User Utilities', () => { diff --git a/server/libs/common/src/utils/user-utils.ts b/server/libs/common/src/utils/user-utils.ts index 90aa022506..d0a3c2e48a 100644 --- a/server/libs/common/src/utils/user-utils.ts +++ b/server/libs/common/src/utils/user-utils.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; function createUserUtils() { const isReadyForDeletion = (user: UserEntity): boolean => { diff --git a/server/libs/database/src/database.module.ts b/server/libs/database/src/database.module.ts deleted file mode 100644 index df512ee62b..0000000000 --- a/server/libs/database/src/database.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Module } from '@nestjs/common'; -import { TypeOrmModule } from '@nestjs/typeorm'; -import { databaseConfig } from './config/database.config'; - -@Module({ - imports: [TypeOrmModule.forRoot(databaseConfig)], - providers: [], - exports: [TypeOrmModule], -}) -export class DatabaseModule {} diff --git a/server/libs/domain/src/auth/dto/auth-user.dto.ts b/server/libs/domain/src/auth/dto/auth-user.dto.ts new file mode 100644 index 0000000000..a135924a06 --- /dev/null +++ b/server/libs/domain/src/auth/dto/auth-user.dto.ts @@ -0,0 +1,8 @@ +export class AuthUserDto { + id!: string; + email!: string; + isAdmin!: boolean; + isPublicUser?: boolean; + sharedLinkId?: string; + isAllowUpload?: boolean; +} diff --git a/server/libs/domain/src/auth/dto/index.ts b/server/libs/domain/src/auth/dto/index.ts new file mode 100644 index 0000000000..8b7a427587 --- /dev/null +++ b/server/libs/domain/src/auth/dto/index.ts @@ -0,0 +1 @@ +export * from './auth-user.dto'; diff --git a/server/libs/domain/src/auth/index.ts b/server/libs/domain/src/auth/index.ts new file mode 100644 index 0000000000..dacfee3d06 --- /dev/null +++ b/server/libs/domain/src/auth/index.ts @@ -0,0 +1 @@ +export * from './dto'; diff --git a/server/libs/domain/src/domain.module.ts b/server/libs/domain/src/domain.module.ts new file mode 100644 index 0000000000..baea8e79f0 --- /dev/null +++ b/server/libs/domain/src/domain.module.ts @@ -0,0 +1,20 @@ +import { DynamicModule, Global, Module, ModuleMetadata, Provider } from '@nestjs/common'; +import { UserService } from './user'; + +const providers: Provider[] = [ + // + UserService, +]; + +@Global() +@Module({}) +export class DomainModule { + static register(options: Pick): DynamicModule { + return { + module: DomainModule, + imports: options.imports, + providers: [...providers], + exports: [...providers], + }; + } +} diff --git a/server/libs/domain/src/index.ts b/server/libs/domain/src/index.ts new file mode 100644 index 0000000000..9fda872c19 --- /dev/null +++ b/server/libs/domain/src/index.ts @@ -0,0 +1,3 @@ +export * from './auth'; +export * from './domain.module'; +export * from './user'; diff --git a/server/apps/immich/src/api-v1/user/dto/create-profile-image.dto.ts b/server/libs/domain/src/user/dto/create-profile-image.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/dto/create-profile-image.dto.ts rename to server/libs/domain/src/user/dto/create-profile-image.dto.ts diff --git a/server/apps/immich/src/api-v1/user/dto/create-user.dto.spec.ts b/server/libs/domain/src/user/dto/create-user.dto.spec.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/dto/create-user.dto.spec.ts rename to server/libs/domain/src/user/dto/create-user.dto.spec.ts diff --git a/server/apps/immich/src/api-v1/user/dto/create-user.dto.ts b/server/libs/domain/src/user/dto/create-user.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/dto/create-user.dto.ts rename to server/libs/domain/src/user/dto/create-user.dto.ts diff --git a/server/libs/domain/src/user/dto/index.ts b/server/libs/domain/src/user/dto/index.ts new file mode 100644 index 0000000000..f20bb94b0a --- /dev/null +++ b/server/libs/domain/src/user/dto/index.ts @@ -0,0 +1,4 @@ +export * from './create-profile-image.dto'; +export * from './create-user.dto'; +export * from './update-user.dto'; +export * from './user-count.dto'; diff --git a/server/apps/immich/src/api-v1/user/dto/update-user.dto.ts b/server/libs/domain/src/user/dto/update-user.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/dto/update-user.dto.ts rename to server/libs/domain/src/user/dto/update-user.dto.ts diff --git a/server/apps/immich/src/api-v1/user/dto/user-count.dto.ts b/server/libs/domain/src/user/dto/user-count.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/dto/user-count.dto.ts rename to server/libs/domain/src/user/dto/user-count.dto.ts diff --git a/server/libs/domain/src/user/index.ts b/server/libs/domain/src/user/index.ts new file mode 100644 index 0000000000..8c14adf5f6 --- /dev/null +++ b/server/libs/domain/src/user/index.ts @@ -0,0 +1,5 @@ +export * from './dto'; +export * from './response-dto'; +export * from './user.core'; +export * from './user.repository'; +export * from './user.service'; diff --git a/server/apps/immich/src/api-v1/user/response-dto/create-profile-image-response.dto.ts b/server/libs/domain/src/user/response-dto/create-profile-image-response.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/response-dto/create-profile-image-response.dto.ts rename to server/libs/domain/src/user/response-dto/create-profile-image-response.dto.ts diff --git a/server/libs/domain/src/user/response-dto/index.ts b/server/libs/domain/src/user/response-dto/index.ts new file mode 100644 index 0000000000..eea5d8c779 --- /dev/null +++ b/server/libs/domain/src/user/response-dto/index.ts @@ -0,0 +1,3 @@ +export * from './create-profile-image-response.dto'; +export * from './user-count-response.dto'; +export * from './user-response.dto'; diff --git a/server/apps/immich/src/api-v1/user/response-dto/user-count-response.dto.ts b/server/libs/domain/src/user/response-dto/user-count-response.dto.ts similarity index 100% rename from server/apps/immich/src/api-v1/user/response-dto/user-count-response.dto.ts rename to server/libs/domain/src/user/response-dto/user-count-response.dto.ts diff --git a/server/apps/immich/src/api-v1/user/response-dto/user-response.dto.ts b/server/libs/domain/src/user/response-dto/user-response.dto.ts similarity index 93% rename from server/apps/immich/src/api-v1/user/response-dto/user-response.dto.ts rename to server/libs/domain/src/user/response-dto/user-response.dto.ts index 6e11f78a20..d3670e49f5 100644 --- a/server/apps/immich/src/api-v1/user/response-dto/user-response.dto.ts +++ b/server/libs/domain/src/user/response-dto/user-response.dto.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; export class UserResponseDto { id!: string; diff --git a/server/apps/immich/src/api-v1/user/user.core.ts b/server/libs/domain/src/user/user.core.ts similarity index 95% rename from server/apps/immich/src/api-v1/user/user.core.ts rename to server/libs/domain/src/user/user.core.ts index a263b3b27e..126747f2a1 100644 --- a/server/apps/immich/src/api-v1/user/user.core.ts +++ b/server/libs/domain/src/user/user.core.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { BadRequestException, ForbiddenException, @@ -8,11 +8,11 @@ import { UnauthorizedException, } from '@nestjs/common'; import { hash } from 'bcrypt'; -import { createReadStream, constants, ReadStream } from 'fs'; +import { constants, createReadStream, ReadStream } from 'fs'; import fs from 'fs/promises'; -import { AuthUserDto } from '../../decorators/auth-user.decorator'; +import { AuthUserDto } from '../auth'; import { CreateAdminDto, CreateUserDto, CreateUserOAuthDto } from './dto/create-user.dto'; -import { IUserRepository, UserListFilter } from './user-repository'; +import { IUserRepository, UserListFilter } from './user.repository'; const SALT_ROUNDS = 10; diff --git a/server/libs/domain/src/user/user.repository.ts b/server/libs/domain/src/user/user.repository.ts new file mode 100644 index 0000000000..664a8f20eb --- /dev/null +++ b/server/libs/domain/src/user/user.repository.ts @@ -0,0 +1,19 @@ +import { UserEntity } from '@app/infra'; + +export interface UserListFilter { + excludeId?: string; +} + +export const IUserRepository = 'IUserRepository'; + +export interface IUserRepository { + get(id: string, withDeleted?: boolean): Promise; + getAdmin(): Promise; + getByEmail(email: string, withPassword?: boolean): Promise; + getByOAuthId(oauthId: string): Promise; + getList(filter?: UserListFilter): Promise; + create(user: Partial): Promise; + update(id: string, user: Partial): Promise; + delete(user: UserEntity): Promise; + restore(user: UserEntity): Promise; +} diff --git a/server/apps/immich/src/api-v1/user/user.service.spec.ts b/server/libs/domain/src/user/user.service.spec.ts similarity index 94% rename from server/apps/immich/src/api-v1/user/user.service.spec.ts rename to server/libs/domain/src/user/user.service.spec.ts index d7c8d6bd1f..d2aa81f35a 100644 --- a/server/apps/immich/src/api-v1/user/user.service.spec.ts +++ b/server/libs/domain/src/user/user.service.spec.ts @@ -1,8 +1,7 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; import { BadRequestException, ForbiddenException, NotFoundException } from '@nestjs/common'; -import { newUserRepositoryMock } from '../../../test/test-utils'; -import { AuthUserDto } from '../../decorators/auth-user.decorator'; -import { IUserRepository } from './user-repository'; +import { AuthUserDto } from '../auth'; +import { IUserRepository } from '@app/domain'; import { when } from 'jest-when'; import { UserService } from './user.service'; import { UpdateUserDto } from './dto/update-user.dto'; @@ -66,7 +65,17 @@ describe('UserService', () => { }); beforeEach(() => { - userRepositoryMock = newUserRepositoryMock(); + userRepositoryMock = { + get: jest.fn(), + getAdmin: jest.fn(), + getByEmail: jest.fn(), + getByOAuthId: jest.fn(), + getList: jest.fn(), + create: jest.fn(), + update: jest.fn(), + delete: jest.fn(), + restore: jest.fn(), + }; when(userRepositoryMock.get).calledWith(adminUser.id).mockResolvedValue(adminUser); when(userRepositoryMock.get).calledWith(adminUser.id, undefined).mockResolvedValue(adminUser); when(userRepositoryMock.get).calledWith(immichUser.id, undefined).mockResolvedValue(immichUser); diff --git a/server/apps/immich/src/api-v1/user/user.service.ts b/server/libs/domain/src/user/user.service.ts similarity index 96% rename from server/apps/immich/src/api-v1/user/user.service.ts rename to server/libs/domain/src/user/user.service.ts index b9a9bcd828..77d52c9087 100644 --- a/server/apps/immich/src/api-v1/user/user.service.ts +++ b/server/libs/domain/src/user/user.service.ts @@ -1,6 +1,7 @@ import { BadRequestException, Inject, Injectable, NotFoundException } from '@nestjs/common'; import { ReadStream } from 'fs'; -import { AuthUserDto } from '../../decorators/auth-user.decorator'; +import { AuthUserDto } from '../auth'; +import { IUserRepository } from '../user'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; import { UserCountDto } from './dto/user-count.dto'; @@ -10,7 +11,6 @@ import { } from './response-dto/create-profile-image-response.dto'; import { mapUserCountResponse, UserCountResponseDto } from './response-dto/user-count-response.dto'; import { mapUser, UserResponseDto } from './response-dto/user-response.dto'; -import { IUserRepository } from './user-repository'; import { UserCore } from './user.core'; @Injectable() diff --git a/server/libs/database/tsconfig.lib.json b/server/libs/domain/tsconfig.lib.json similarity index 81% rename from server/libs/database/tsconfig.lib.json rename to server/libs/domain/tsconfig.lib.json index 21c8d58b53..4e050b3d9e 100644 --- a/server/libs/database/tsconfig.lib.json +++ b/server/libs/domain/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "declaration": true, - "outDir": "../../dist/libs/database" + "outDir": "../../dist/libs/domain" }, "include": ["src/**/*"], "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] diff --git a/server/libs/immich-config/src/immich-config.module.ts b/server/libs/immich-config/src/immich-config.module.ts index 7a9d2e8ebd..c34c6e110a 100644 --- a/server/libs/immich-config/src/immich-config.module.ts +++ b/server/libs/immich-config/src/immich-config.module.ts @@ -1,4 +1,4 @@ -import { SystemConfigEntity } from '@app/database'; +import { SystemConfigEntity } from '@app/infra'; import { Module, Provider } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ImmichConfigService } from './immich-config.service'; diff --git a/server/libs/immich-config/src/immich-config.service.ts b/server/libs/immich-config/src/immich-config.service.ts index 856629dde1..73a04eb7c2 100644 --- a/server/libs/immich-config/src/immich-config.service.ts +++ b/server/libs/immich-config/src/immich-config.service.ts @@ -1,4 +1,4 @@ -import { SystemConfig, SystemConfigEntity, SystemConfigKey } from '@app/database'; +import { SystemConfig, SystemConfigEntity, SystemConfigKey } from '@app/infra'; import { BadRequestException, Injectable, Logger } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import * as _ from 'lodash'; diff --git a/server/libs/database/src/config/database.config.ts b/server/libs/infra/src/db/config/database.config.ts similarity index 100% rename from server/libs/database/src/config/database.config.ts rename to server/libs/infra/src/db/config/database.config.ts diff --git a/server/libs/database/src/config/index.ts b/server/libs/infra/src/db/config/index.ts similarity index 100% rename from server/libs/database/src/config/index.ts rename to server/libs/infra/src/db/config/index.ts diff --git a/server/libs/database/src/entities/album.entity.ts b/server/libs/infra/src/db/entities/album.entity.ts similarity index 100% rename from server/libs/database/src/entities/album.entity.ts rename to server/libs/infra/src/db/entities/album.entity.ts diff --git a/server/libs/database/src/entities/api-key.entity.ts b/server/libs/infra/src/db/entities/api-key.entity.ts similarity index 100% rename from server/libs/database/src/entities/api-key.entity.ts rename to server/libs/infra/src/db/entities/api-key.entity.ts diff --git a/server/libs/database/src/entities/asset-album.entity.ts b/server/libs/infra/src/db/entities/asset-album.entity.ts similarity index 100% rename from server/libs/database/src/entities/asset-album.entity.ts rename to server/libs/infra/src/db/entities/asset-album.entity.ts diff --git a/server/libs/database/src/entities/asset.entity.ts b/server/libs/infra/src/db/entities/asset.entity.ts similarity index 100% rename from server/libs/database/src/entities/asset.entity.ts rename to server/libs/infra/src/db/entities/asset.entity.ts diff --git a/server/libs/database/src/entities/device-info.entity.ts b/server/libs/infra/src/db/entities/device-info.entity.ts similarity index 100% rename from server/libs/database/src/entities/device-info.entity.ts rename to server/libs/infra/src/db/entities/device-info.entity.ts diff --git a/server/libs/database/src/entities/exif.entity.ts b/server/libs/infra/src/db/entities/exif.entity.ts similarity index 100% rename from server/libs/database/src/entities/exif.entity.ts rename to server/libs/infra/src/db/entities/exif.entity.ts diff --git a/server/libs/database/src/entities/index.ts b/server/libs/infra/src/db/entities/index.ts similarity index 100% rename from server/libs/database/src/entities/index.ts rename to server/libs/infra/src/db/entities/index.ts diff --git a/server/libs/database/src/entities/shared-link.entity.ts b/server/libs/infra/src/db/entities/shared-link.entity.ts similarity index 100% rename from server/libs/database/src/entities/shared-link.entity.ts rename to server/libs/infra/src/db/entities/shared-link.entity.ts diff --git a/server/libs/database/src/entities/smart-info.entity.ts b/server/libs/infra/src/db/entities/smart-info.entity.ts similarity index 100% rename from server/libs/database/src/entities/smart-info.entity.ts rename to server/libs/infra/src/db/entities/smart-info.entity.ts diff --git a/server/libs/database/src/entities/system-config.entity.ts b/server/libs/infra/src/db/entities/system-config.entity.ts similarity index 100% rename from server/libs/database/src/entities/system-config.entity.ts rename to server/libs/infra/src/db/entities/system-config.entity.ts diff --git a/server/libs/database/src/entities/tag.entity.ts b/server/libs/infra/src/db/entities/tag.entity.ts similarity index 100% rename from server/libs/database/src/entities/tag.entity.ts rename to server/libs/infra/src/db/entities/tag.entity.ts diff --git a/server/libs/database/src/entities/user-album.entity.ts b/server/libs/infra/src/db/entities/user-album.entity.ts similarity index 100% rename from server/libs/database/src/entities/user-album.entity.ts rename to server/libs/infra/src/db/entities/user-album.entity.ts diff --git a/server/libs/database/src/entities/user.entity.ts b/server/libs/infra/src/db/entities/user.entity.ts similarity index 100% rename from server/libs/database/src/entities/user.entity.ts rename to server/libs/infra/src/db/entities/user.entity.ts diff --git a/server/libs/database/src/index.ts b/server/libs/infra/src/db/index.ts similarity index 60% rename from server/libs/database/src/index.ts rename to server/libs/infra/src/db/index.ts index b8b25dc222..7ab3eb208b 100644 --- a/server/libs/database/src/index.ts +++ b/server/libs/infra/src/db/index.ts @@ -1,3 +1,3 @@ export * from './config'; -export * from './database.module'; export * from './entities'; +export * from './repository'; diff --git a/server/libs/database/src/migrations/1645130759468-CreateUserTable.ts b/server/libs/infra/src/db/migrations/1645130759468-CreateUserTable.ts similarity index 100% rename from server/libs/database/src/migrations/1645130759468-CreateUserTable.ts rename to server/libs/infra/src/db/migrations/1645130759468-CreateUserTable.ts diff --git a/server/libs/database/src/migrations/1645130777674-CreateDeviceInfoTable.ts b/server/libs/infra/src/db/migrations/1645130777674-CreateDeviceInfoTable.ts similarity index 100% rename from server/libs/database/src/migrations/1645130777674-CreateDeviceInfoTable.ts rename to server/libs/infra/src/db/migrations/1645130777674-CreateDeviceInfoTable.ts diff --git a/server/libs/database/src/migrations/1645130805273-CreateAssetsTable.ts b/server/libs/infra/src/db/migrations/1645130805273-CreateAssetsTable.ts similarity index 100% rename from server/libs/database/src/migrations/1645130805273-CreateAssetsTable.ts rename to server/libs/infra/src/db/migrations/1645130805273-CreateAssetsTable.ts diff --git a/server/libs/database/src/migrations/1645130817965-CreateExifTable.ts b/server/libs/infra/src/db/migrations/1645130817965-CreateExifTable.ts similarity index 100% rename from server/libs/database/src/migrations/1645130817965-CreateExifTable.ts rename to server/libs/infra/src/db/migrations/1645130817965-CreateExifTable.ts diff --git a/server/libs/database/src/migrations/1645130870184-CreateSmartInfoTable.ts b/server/libs/infra/src/db/migrations/1645130870184-CreateSmartInfoTable.ts similarity index 100% rename from server/libs/database/src/migrations/1645130870184-CreateSmartInfoTable.ts rename to server/libs/infra/src/db/migrations/1645130870184-CreateSmartInfoTable.ts diff --git a/server/libs/database/src/migrations/1646249209023-AddExifTextSearchColumn.ts b/server/libs/infra/src/db/migrations/1646249209023-AddExifTextSearchColumn.ts similarity index 100% rename from server/libs/database/src/migrations/1646249209023-AddExifTextSearchColumn.ts rename to server/libs/infra/src/db/migrations/1646249209023-AddExifTextSearchColumn.ts diff --git a/server/libs/database/src/migrations/1646249734844-CreateExifTextSearchIndex.ts b/server/libs/infra/src/db/migrations/1646249734844-CreateExifTextSearchIndex.ts similarity index 100% rename from server/libs/database/src/migrations/1646249734844-CreateExifTextSearchIndex.ts rename to server/libs/infra/src/db/migrations/1646249734844-CreateExifTextSearchIndex.ts diff --git a/server/libs/database/src/migrations/1646709533213-AddRegionCityToExIf.ts b/server/libs/infra/src/db/migrations/1646709533213-AddRegionCityToExIf.ts similarity index 100% rename from server/libs/database/src/migrations/1646709533213-AddRegionCityToExIf.ts rename to server/libs/infra/src/db/migrations/1646709533213-AddRegionCityToExIf.ts diff --git a/server/libs/database/src/migrations/1646710459852-AddLocationToExifTextSearch.ts b/server/libs/infra/src/db/migrations/1646710459852-AddLocationToExifTextSearch.ts similarity index 100% rename from server/libs/database/src/migrations/1646710459852-AddLocationToExifTextSearch.ts rename to server/libs/infra/src/db/migrations/1646710459852-AddLocationToExifTextSearch.ts diff --git a/server/libs/database/src/migrations/1648317474768-AddObjectColumnToSmartInfo.ts b/server/libs/infra/src/db/migrations/1648317474768-AddObjectColumnToSmartInfo.ts similarity index 100% rename from server/libs/database/src/migrations/1648317474768-AddObjectColumnToSmartInfo.ts rename to server/libs/infra/src/db/migrations/1648317474768-AddObjectColumnToSmartInfo.ts diff --git a/server/libs/database/src/migrations/1649643216111-CreateSharedAlbumAndRelatedTables.ts b/server/libs/infra/src/db/migrations/1649643216111-CreateSharedAlbumAndRelatedTables.ts similarity index 100% rename from server/libs/database/src/migrations/1649643216111-CreateSharedAlbumAndRelatedTables.ts rename to server/libs/infra/src/db/migrations/1649643216111-CreateSharedAlbumAndRelatedTables.ts diff --git a/server/libs/database/src/migrations/1652633525943-UpdateUserTableWithAdminAndName.ts b/server/libs/infra/src/db/migrations/1652633525943-UpdateUserTableWithAdminAndName.ts similarity index 100% rename from server/libs/database/src/migrations/1652633525943-UpdateUserTableWithAdminAndName.ts rename to server/libs/infra/src/db/migrations/1652633525943-UpdateUserTableWithAdminAndName.ts diff --git a/server/libs/database/src/migrations/1653214255670-UpdateAssetTableWithWebpPath.ts b/server/libs/infra/src/db/migrations/1653214255670-UpdateAssetTableWithWebpPath.ts similarity index 100% rename from server/libs/database/src/migrations/1653214255670-UpdateAssetTableWithWebpPath.ts rename to server/libs/infra/src/db/migrations/1653214255670-UpdateAssetTableWithWebpPath.ts diff --git a/server/libs/database/src/migrations/1654299904583-UpdateAssetTableWithEncodeVideoPath.ts b/server/libs/infra/src/db/migrations/1654299904583-UpdateAssetTableWithEncodeVideoPath.ts similarity index 100% rename from server/libs/database/src/migrations/1654299904583-UpdateAssetTableWithEncodeVideoPath.ts rename to server/libs/infra/src/db/migrations/1654299904583-UpdateAssetTableWithEncodeVideoPath.ts diff --git a/server/libs/database/src/migrations/1655401127251-RenameSharedAlbums.ts b/server/libs/infra/src/db/migrations/1655401127251-RenameSharedAlbums.ts similarity index 100% rename from server/libs/database/src/migrations/1655401127251-RenameSharedAlbums.ts rename to server/libs/infra/src/db/migrations/1655401127251-RenameSharedAlbums.ts diff --git a/server/libs/database/src/migrations/1656338626260-RenameIsFirstLoggedInColumn.ts b/server/libs/infra/src/db/migrations/1656338626260-RenameIsFirstLoggedInColumn.ts similarity index 100% rename from server/libs/database/src/migrations/1656338626260-RenameIsFirstLoggedInColumn.ts rename to server/libs/infra/src/db/migrations/1656338626260-RenameIsFirstLoggedInColumn.ts diff --git a/server/libs/database/src/migrations/1656888591977-RenameAssetAlbumIdSequence.ts b/server/libs/infra/src/db/migrations/1656888591977-RenameAssetAlbumIdSequence.ts similarity index 100% rename from server/libs/database/src/migrations/1656888591977-RenameAssetAlbumIdSequence.ts rename to server/libs/infra/src/db/migrations/1656888591977-RenameAssetAlbumIdSequence.ts diff --git a/server/libs/database/src/migrations/1656888918620-DropExifTextSearchableColumn.ts b/server/libs/infra/src/db/migrations/1656888918620-DropExifTextSearchableColumn.ts similarity index 100% rename from server/libs/database/src/migrations/1656888918620-DropExifTextSearchableColumn.ts rename to server/libs/infra/src/db/migrations/1656888918620-DropExifTextSearchableColumn.ts diff --git a/server/libs/database/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts b/server/libs/infra/src/db/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts similarity index 100% rename from server/libs/database/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts rename to server/libs/infra/src/db/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts diff --git a/server/libs/database/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts b/server/libs/infra/src/db/migrations/1658860470248-AddExifImageNameAsSearchableText.ts similarity index 100% rename from server/libs/database/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts rename to server/libs/infra/src/db/migrations/1658860470248-AddExifImageNameAsSearchableText.ts diff --git a/server/libs/database/src/migrations/1661011331242-AddCaption.ts b/server/libs/infra/src/db/migrations/1661011331242-AddCaption.ts similarity index 100% rename from server/libs/database/src/migrations/1661011331242-AddCaption.ts rename to server/libs/infra/src/db/migrations/1661011331242-AddCaption.ts diff --git a/server/libs/database/src/migrations/1661528919411-ChangeExifFileSizeInByteToBigInt.ts b/server/libs/infra/src/db/migrations/1661528919411-ChangeExifFileSizeInByteToBigInt.ts similarity index 100% rename from server/libs/database/src/migrations/1661528919411-ChangeExifFileSizeInByteToBigInt.ts rename to server/libs/infra/src/db/migrations/1661528919411-ChangeExifFileSizeInByteToBigInt.ts diff --git a/server/libs/database/src/migrations/1661881837496-AddAssetChecksum.ts b/server/libs/infra/src/db/migrations/1661881837496-AddAssetChecksum.ts similarity index 100% rename from server/libs/database/src/migrations/1661881837496-AddAssetChecksum.ts rename to server/libs/infra/src/db/migrations/1661881837496-AddAssetChecksum.ts diff --git a/server/libs/database/src/migrations/1661971370662-UpdateAssetTableWithNewUniqueConstraint.ts b/server/libs/infra/src/db/migrations/1661971370662-UpdateAssetTableWithNewUniqueConstraint.ts similarity index 100% rename from server/libs/database/src/migrations/1661971370662-UpdateAssetTableWithNewUniqueConstraint.ts rename to server/libs/infra/src/db/migrations/1661971370662-UpdateAssetTableWithNewUniqueConstraint.ts diff --git a/server/libs/database/src/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts b/server/libs/infra/src/db/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts similarity index 100% rename from server/libs/database/src/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts rename to server/libs/infra/src/db/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts diff --git a/server/libs/database/src/migrations/1665540663419-CreateSystemConfigTable.ts b/server/libs/infra/src/db/migrations/1665540663419-CreateSystemConfigTable.ts similarity index 100% rename from server/libs/database/src/migrations/1665540663419-CreateSystemConfigTable.ts rename to server/libs/infra/src/db/migrations/1665540663419-CreateSystemConfigTable.ts diff --git a/server/libs/database/src/migrations/1667762360744-AddingDeletedAtColumnInUserEntity.ts b/server/libs/infra/src/db/migrations/1667762360744-AddingDeletedAtColumnInUserEntity.ts similarity index 100% rename from server/libs/database/src/migrations/1667762360744-AddingDeletedAtColumnInUserEntity.ts rename to server/libs/infra/src/db/migrations/1667762360744-AddingDeletedAtColumnInUserEntity.ts diff --git a/server/libs/database/src/migrations/1668383120461-AddLivePhotosRelatedColumnToAssetTable.ts b/server/libs/infra/src/db/migrations/1668383120461-AddLivePhotosRelatedColumnToAssetTable.ts similarity index 100% rename from server/libs/database/src/migrations/1668383120461-AddLivePhotosRelatedColumnToAssetTable.ts rename to server/libs/infra/src/db/migrations/1668383120461-AddLivePhotosRelatedColumnToAssetTable.ts diff --git a/server/libs/database/src/migrations/1668835311083-UpdateUserTableForOIDC.ts b/server/libs/infra/src/db/migrations/1668835311083-UpdateUserTableForOIDC.ts similarity index 100% rename from server/libs/database/src/migrations/1668835311083-UpdateUserTableForOIDC.ts rename to server/libs/infra/src/db/migrations/1668835311083-UpdateUserTableForOIDC.ts diff --git a/server/libs/database/src/migrations/1670104716264-OAuthId.ts b/server/libs/infra/src/db/migrations/1670104716264-OAuthId.ts similarity index 100% rename from server/libs/database/src/migrations/1670104716264-OAuthId.ts rename to server/libs/infra/src/db/migrations/1670104716264-OAuthId.ts diff --git a/server/libs/database/src/migrations/1670257571385-CreateTagsTable.ts b/server/libs/infra/src/db/migrations/1670257571385-CreateTagsTable.ts similarity index 100% rename from server/libs/database/src/migrations/1670257571385-CreateTagsTable.ts rename to server/libs/infra/src/db/migrations/1670257571385-CreateTagsTable.ts diff --git a/server/libs/database/src/migrations/1670607437008-TruncateOldConfigItems.ts b/server/libs/infra/src/db/migrations/1670607437008-TruncateOldConfigItems.ts similarity index 100% rename from server/libs/database/src/migrations/1670607437008-TruncateOldConfigItems.ts rename to server/libs/infra/src/db/migrations/1670607437008-TruncateOldConfigItems.ts diff --git a/server/libs/database/src/migrations/1670633210032-AddUserEmailUniqueConstraint.ts b/server/libs/infra/src/db/migrations/1670633210032-AddUserEmailUniqueConstraint.ts similarity index 100% rename from server/libs/database/src/migrations/1670633210032-AddUserEmailUniqueConstraint.ts rename to server/libs/infra/src/db/migrations/1670633210032-AddUserEmailUniqueConstraint.ts diff --git a/server/libs/database/src/migrations/1672109862870-DropSaltColumn.ts b/server/libs/infra/src/db/migrations/1672109862870-DropSaltColumn.ts similarity index 100% rename from server/libs/database/src/migrations/1672109862870-DropSaltColumn.ts rename to server/libs/infra/src/db/migrations/1672109862870-DropSaltColumn.ts diff --git a/server/libs/database/src/migrations/1672502270115-AddAPIKeys.ts b/server/libs/infra/src/db/migrations/1672502270115-AddAPIKeys.ts similarity index 100% rename from server/libs/database/src/migrations/1672502270115-AddAPIKeys.ts rename to server/libs/infra/src/db/migrations/1672502270115-AddAPIKeys.ts diff --git a/server/libs/database/src/migrations/1673150490490-AddSharedLinkTable.ts b/server/libs/infra/src/db/migrations/1673150490490-AddSharedLinkTable.ts similarity index 100% rename from server/libs/database/src/migrations/1673150490490-AddSharedLinkTable.ts rename to server/libs/infra/src/db/migrations/1673150490490-AddSharedLinkTable.ts diff --git a/server/libs/infra/src/db/repository/index.ts b/server/libs/infra/src/db/repository/index.ts new file mode 100644 index 0000000000..9fb5d34d10 --- /dev/null +++ b/server/libs/infra/src/db/repository/index.ts @@ -0,0 +1 @@ +export * from './user.repository'; diff --git a/server/apps/immich/src/api-v1/user/user-repository.ts b/server/libs/infra/src/db/repository/user.repository.ts similarity index 71% rename from server/apps/immich/src/api-v1/user/user-repository.ts rename to server/libs/infra/src/db/repository/user.repository.ts index 6bae12b061..d0f9b99052 100644 --- a/server/apps/immich/src/api-v1/user/user-repository.ts +++ b/server/libs/infra/src/db/repository/user.repository.ts @@ -1,26 +1,10 @@ -import { UserEntity } from '@app/database'; -import { InternalServerErrorException } from '@nestjs/common'; +import { UserEntity } from '../entities'; +import { IUserRepository, UserListFilter } from '@app/domain'; +import { Injectable, InternalServerErrorException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Not, Repository } from 'typeorm'; -export interface IUserRepository { - get(id: string, withDeleted?: boolean): Promise; - getAdmin(): Promise; - getByEmail(email: string, withPassword?: boolean): Promise; - getByOAuthId(oauthId: string): Promise; - getList(filter?: UserListFilter): Promise; - create(user: Partial): Promise; - update(id: string, user: Partial): Promise; - delete(user: UserEntity): Promise; - restore(user: UserEntity): Promise; -} - -export interface UserListFilter { - excludeId?: string; -} - -export const IUserRepository = 'IUserRepository'; - +@Injectable() export class UserRepository implements IUserRepository { constructor( @InjectRepository(UserEntity) diff --git a/server/libs/infra/src/index.ts b/server/libs/infra/src/index.ts new file mode 100644 index 0000000000..debca9ed35 --- /dev/null +++ b/server/libs/infra/src/index.ts @@ -0,0 +1,2 @@ +export * from './db'; +export * from './infra.module'; diff --git a/server/libs/infra/src/infra.module.ts b/server/libs/infra/src/infra.module.ts new file mode 100644 index 0000000000..af3a4e0cd5 --- /dev/null +++ b/server/libs/infra/src/infra.module.ts @@ -0,0 +1,22 @@ +import { databaseConfig, UserEntity } from '@app/infra'; +import { IUserRepository } from '@app/domain'; +import { Global, Module, Provider } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { UserRepository } from './db'; + +const providers: Provider[] = [ + // + { provide: IUserRepository, useClass: UserRepository }, +]; + +@Global() +@Module({ + imports: [ + // + TypeOrmModule.forRoot(databaseConfig), + TypeOrmModule.forFeature([UserEntity]), + ], + providers: [...providers], + exports: [...providers], +}) +export class InfraModule {} diff --git a/server/libs/infra/tsconfig.lib.json b/server/libs/infra/tsconfig.lib.json new file mode 100644 index 0000000000..02f54211fb --- /dev/null +++ b/server/libs/infra/tsconfig.lib.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "../../dist/libs/infra" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/server/libs/job/src/interfaces/asset-uploaded.interface.ts b/server/libs/job/src/interfaces/asset-uploaded.interface.ts index ffa9186ad6..d21a552a8a 100644 --- a/server/libs/job/src/interfaces/asset-uploaded.interface.ts +++ b/server/libs/job/src/interfaces/asset-uploaded.interface.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; export interface IAssetUploadedJob { /** diff --git a/server/libs/job/src/interfaces/machine-learning.interface.ts b/server/libs/job/src/interfaces/machine-learning.interface.ts index 42c9cde23d..4a6d9078e3 100644 --- a/server/libs/job/src/interfaces/machine-learning.interface.ts +++ b/server/libs/job/src/interfaces/machine-learning.interface.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; export interface IMachineLearningJob { /** diff --git a/server/libs/job/src/interfaces/metadata-extraction.interface.ts b/server/libs/job/src/interfaces/metadata-extraction.interface.ts index 3f08fdc1d3..e90d60c067 100644 --- a/server/libs/job/src/interfaces/metadata-extraction.interface.ts +++ b/server/libs/job/src/interfaces/metadata-extraction.interface.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; export interface IExifExtractionProcessor { /** diff --git a/server/libs/job/src/interfaces/thumbnail-generation.interface.ts b/server/libs/job/src/interfaces/thumbnail-generation.interface.ts index 903abd99a8..8ea6976aa2 100644 --- a/server/libs/job/src/interfaces/thumbnail-generation.interface.ts +++ b/server/libs/job/src/interfaces/thumbnail-generation.interface.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; export interface JpegGeneratorProcessor { /** diff --git a/server/libs/job/src/interfaces/user-deletion.interface.ts b/server/libs/job/src/interfaces/user-deletion.interface.ts index e58a0a09f4..432334a76a 100644 --- a/server/libs/job/src/interfaces/user-deletion.interface.ts +++ b/server/libs/job/src/interfaces/user-deletion.interface.ts @@ -1,4 +1,4 @@ -import { UserEntity } from '@app/database'; +import { UserEntity } from '@app/infra'; export interface IUserDeletionJob { /** diff --git a/server/libs/job/src/interfaces/video-transcode.interface.ts b/server/libs/job/src/interfaces/video-transcode.interface.ts index ea50e69215..3dc20db277 100644 --- a/server/libs/job/src/interfaces/video-transcode.interface.ts +++ b/server/libs/job/src/interfaces/video-transcode.interface.ts @@ -1,4 +1,4 @@ -import { AssetEntity } from '@app/database'; +import { AssetEntity } from '@app/infra'; export interface IMp4ConversionProcessor { /** diff --git a/server/libs/storage/src/storage.module.ts b/server/libs/storage/src/storage.module.ts index 793633a3c7..b729d0db83 100644 --- a/server/libs/storage/src/storage.module.ts +++ b/server/libs/storage/src/storage.module.ts @@ -1,4 +1,4 @@ -import { AssetEntity, SystemConfigEntity } from '@app/database'; +import { AssetEntity, SystemConfigEntity } from '@app/infra'; import { ImmichConfigModule } from '@app/immich-config'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; diff --git a/server/libs/storage/src/storage.service.ts b/server/libs/storage/src/storage.service.ts index 6c572eae61..1f16ae5f1e 100644 --- a/server/libs/storage/src/storage.service.ts +++ b/server/libs/storage/src/storage.service.ts @@ -1,5 +1,5 @@ import { APP_UPLOAD_LOCATION } from '@app/common'; -import { AssetEntity, SystemConfig } from '@app/database'; +import { AssetEntity, SystemConfig } from '@app/infra'; import { ImmichConfigService, INITIAL_SYSTEM_CONFIG } from '@app/immich-config'; import { Inject, Injectable, Logger } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; diff --git a/server/nest-cli.json b/server/nest-cli.json index 03040b77ca..c0fad3013f 100644 --- a/server/nest-cli.json +++ b/server/nest-cli.json @@ -88,6 +88,24 @@ "compilerOptions": { "tsConfigPath": "libs/storage/tsconfig.lib.json" } + }, + "infra": { + "type": "library", + "root": "libs/infra", + "entryFile": "index", + "sourceRoot": "libs/infra/src", + "compilerOptions": { + "tsConfigPath": "libs/infra/tsconfig.lib.json" + } + }, + "domain": { + "type": "library", + "root": "libs/domain", + "entryFile": "index", + "sourceRoot": "libs/domain/src", + "compilerOptions": { + "tsConfigPath": "libs/domain/tsconfig.lib.json" + } } } } \ No newline at end of file diff --git a/server/package.json b/server/package.json index 9a0efc48ae..5844a74ad8 100644 --- a/server/package.json +++ b/server/package.json @@ -144,14 +144,13 @@ "/libs/" ], "moduleNameMapper": { - "^@app/database(|/.*)$": "/libs/database/src/$1", - "@app/database/config/(.*)": "/libs/database/src/config/$1", - "@app/database/config": "/libs/database/src/config", "@app/common": "/libs/common/src", "^@app/job(|/.*)$": "/libs/job/src/$1", "@app/job": "/libs/job/src", "^@app/immich-config(|/.*)$": "/libs/immich-config/src/$1", - "^@app/storage(|/.*)$": "/libs/storage/src/$1" + "^@app/storage(|/.*)$": "/libs/storage/src/$1", + "^@app/infra(|/.*)$": "/libs/infra/src/$1", + "^@app/domain(|/.*)$": "/libs/domain/src/$1" } } } diff --git a/server/tsconfig.json b/server/tsconfig.json index 530c06b340..3df0b52c7e 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -16,41 +16,21 @@ "esModuleInterop": true, "baseUrl": "./", "paths": { - "@app/common": [ - "libs/common/src" - ], - "@app/common/*": [ - "libs/common/src/*" - ], - "@app/database": [ - "libs/database/src" - ], - "@app/database/*": [ - "libs/database/src/*" - ], - "@app/job": [ - "libs/job/src" - ], - "@app/job/*": [ - "libs/job/src/*" - ], - "@app/immich-config": [ - "libs/immich-config/src" - ], - "@app/immich-config/*": [ - "libs/immich-config/src/*" - ], - "@app/storage": [ - "libs/storage/src" - ], - "@app/storage/*": [ - "libs/storage/src/*" - ] + "@app/common": ["libs/common/src"], + "@app/common/*": ["libs/common/src/*"], + "@app/infra": ["libs/database/src"], + "@app/infra/*": ["libs/database/src/*"], + "@app/job": ["libs/job/src"], + "@app/job/*": ["libs/job/src/*"], + "@app/immich-config": ["libs/immich-config/src"], + "@app/immich-config/*": ["libs/immich-config/src/*"], + "@app/storage": ["libs/storage/src"], + "@app/storage/*": ["libs/storage/src/*"], + "@app/infra": ["libs/infra/src"], + "@app/infra/*": ["libs/infra/src/*"], + "@app/domain": ["libs/domain/src"], + "@app/domain/*": ["libs/domain/src/*"] } }, - "exclude": [ - "dist", - "node_modules", - "upload" - ] -} \ No newline at end of file + "exclude": ["dist", "node_modules", "upload"] +}