mirror of
https://github.com/immich-app/immich.git
synced 2025-12-24 09:14:58 +03:00
refactor: migration tag repository to kysely (#16398)
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { TagEntity } from 'src/entities/tag.entity';
|
||||
import { TagRepository } from 'src/repositories/tag.repository';
|
||||
import { TagItem } from 'src/types';
|
||||
|
||||
type UpsertRequest = { userId: string; tags: string[] };
|
||||
export const upsertTags = async (repository: TagRepository, { userId, tags }: UpsertRequest) => {
|
||||
tags = [...new Set(tags)];
|
||||
|
||||
const results: TagEntity[] = [];
|
||||
const results: TagItem[] = [];
|
||||
|
||||
for (const tag of tags) {
|
||||
const parts = tag.split('/').filter(Boolean);
|
||||
let parent: TagEntity | undefined;
|
||||
let parent: TagItem | undefined;
|
||||
|
||||
for (const part of parts) {
|
||||
const value = parent ? `${parent.value}/${part}` : part;
|
||||
parent = await repository.upsertValue({ userId, value, parent });
|
||||
parent = await repository.upsertValue({ userId, value, parentId: parent?.id });
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
|
||||
Reference in New Issue
Block a user