refactor: migration tag repository to kysely (#16398)

This commit is contained in:
Jason Rasmussen
2025-03-03 13:41:19 -05:00
committed by GitHub
parent ff19502035
commit d1fd0076cc
12 changed files with 343 additions and 245 deletions

View File

@@ -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) {