mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor: migrate memory to kysely (#15314)
This commit is contained in:
parent
43b3181f45
commit
93e2545275
5 changed files with 177 additions and 89 deletions
|
|
@ -2,7 +2,6 @@ import { BadRequestException, Injectable } from '@nestjs/common';
|
|||
import { BulkIdResponseDto, BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { MemoryCreateDto, MemoryResponseDto, MemoryUpdateDto, mapMemory } from 'src/dtos/memory.dto';
|
||||
import { AssetEntity } from 'src/entities/asset.entity';
|
||||
import { Permission } from 'src/enum';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { addAssets, removeAssets } from 'src/utils/asset.util';
|
||||
|
|
@ -29,15 +28,17 @@ export class MemoryService extends BaseService {
|
|||
permission: Permission.ASSET_SHARE,
|
||||
ids: assetIds,
|
||||
});
|
||||
const memory = await this.memoryRepository.create({
|
||||
ownerId: auth.user.id,
|
||||
type: dto.type,
|
||||
data: dto.data,
|
||||
isSaved: dto.isSaved,
|
||||
memoryAt: dto.memoryAt,
|
||||
seenAt: dto.seenAt,
|
||||
assets: [...allowedAssetIds].map((id) => ({ id }) as AssetEntity),
|
||||
});
|
||||
const memory = await this.memoryRepository.create(
|
||||
{
|
||||
ownerId: auth.user.id,
|
||||
type: dto.type,
|
||||
data: dto.data,
|
||||
isSaved: dto.isSaved,
|
||||
memoryAt: dto.memoryAt,
|
||||
seenAt: dto.seenAt,
|
||||
},
|
||||
allowedAssetIds,
|
||||
);
|
||||
|
||||
return mapMemory(memory);
|
||||
}
|
||||
|
|
@ -45,8 +46,7 @@ export class MemoryService extends BaseService {
|
|||
async update(auth: AuthDto, id: string, dto: MemoryUpdateDto): Promise<MemoryResponseDto> {
|
||||
await this.requireAccess({ auth, permission: Permission.MEMORY_UPDATE, ids: [id] });
|
||||
|
||||
const memory = await this.memoryRepository.update({
|
||||
id,
|
||||
const memory = await this.memoryRepository.update(id, {
|
||||
isSaved: dto.isSaved,
|
||||
memoryAt: dto.memoryAt,
|
||||
seenAt: dto.seenAt,
|
||||
|
|
@ -68,7 +68,7 @@ export class MemoryService extends BaseService {
|
|||
|
||||
const hasSuccess = results.find(({ success }) => success);
|
||||
if (hasSuccess) {
|
||||
await this.memoryRepository.update({ id, updatedAt: new Date() });
|
||||
await this.memoryRepository.update(id, { updatedAt: new Date() });
|
||||
}
|
||||
|
||||
return results;
|
||||
|
|
@ -86,7 +86,7 @@ export class MemoryService extends BaseService {
|
|||
|
||||
const hasSuccess = results.find(({ success }) => success);
|
||||
if (hasSuccess) {
|
||||
await this.memoryRepository.update({ id, updatedAt: new Date() });
|
||||
await this.memoryRepository.update(id, { id, updatedAt: new Date() });
|
||||
}
|
||||
|
||||
return results;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue