RenaiApp/src/main/modules/entity-api/delete-controller.ts

93 lines
4.7 KiB
TypeScript

import type { EntityTarget } from 'typeorm';
import { getRepository } from '../../core/database';
import { Author } from '../../entities/library/author';
import { AuthorName } from '../../entities/library/author-name';
import { AuthorRole } from '../../entities/library/author-role';
import { AuthorRoleName } from '../../entities/library/author-role-name';
import { CharacterTag } from '../../entities/library/character-tag';
import { Collection } from '../../entities/library/collection';
import { CollectionName } from '../../entities/library/collection-name';
import { CollectionPart } from '../../entities/library/collection-part';
import { Copy } from '../../entities/library/copy';
import { InteractionTag } from '../../entities/library/interaction-tag';
import { Site } from '../../entities/library/site';
import { SiteName } from '../../entities/library/site-name';
import { Source } from '../../entities/library/source';
import { Tag } from '../../entities/library/tag';
import { TagName } from '../../entities/library/tag-name';
import { Transformation } from '../../entities/library/transformation';
import { TransformationType } from '../../entities/library/transformation-type';
import { TransformationTypeName } from '../../entities/library/transformation-type-name';
import { Work } from '../../entities/library/work';
import { WorkAuthor } from '../../entities/library/work-author';
import { WorkCharacter } from '../../entities/library/work-character';
import { WorkCharacterName } from '../../entities/library/work-character-name';
import { WorkName } from '../../entities/library/work-name';
import { WorkTag } from '../../entities/library/work-tag';
import { World } from '../../entities/library/world';
import { WorldCharacter } from '../../entities/library/world-character';
import { WorldCharacterName } from '../../entities/library/world-character-name';
import { WorldName } from '../../entities/library/world-name';
import { ipcServer } from '../ipc/ipc-server';
async function del(id: number, entityTarget: EntityTarget<unknown>): Promise<void> {
const repository = await getRepository(entityTarget);
await repository.delete(id);
}
ipcServer.answer(IpcChannel.ENTITY_DELETE_AUTHOR, async (id) => del(id, Author));
ipcServer.answer(IpcChannel.ENTITY_DELETE_AUTHOR_NAME, async (id) => del(id, AuthorName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_AUTHOR_ROLE, async (id) => del(id, AuthorRole));
ipcServer.answer(IpcChannel.ENTITY_DELETE_AUTHOR_ROLE_NAME, async (id) => del(id, AuthorRoleName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_CHARACTER_TAG, async (id) => del(id, CharacterTag));
ipcServer.answer(IpcChannel.ENTITY_DELETE_COLLECTION, async (id) => del(id, Collection));
ipcServer.answer(IpcChannel.ENTITY_DELETE_COLLECTION_NAME, async (id) => del(id, CollectionName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_COLLECTION_PART, async (id) => del(id, CollectionPart));
ipcServer.answer(IpcChannel.ENTITY_DELETE_COPY, async (id) => del(id, Copy));
ipcServer.answer(IpcChannel.ENTITY_DELETE_INTERACTION_TAG, async (id) => del(id, InteractionTag));
ipcServer.answer(IpcChannel.ENTITY_DELETE_SITE, async (id) => del(id, Site));
ipcServer.answer(IpcChannel.ENTITY_DELETE_SITE_NAME, async (id) => del(id, SiteName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_SOURCE, async (id) => del(id, Source));
ipcServer.answer(IpcChannel.ENTITY_DELETE_TAG, async (id) => del(id, Tag));
ipcServer.answer(IpcChannel.ENTITY_DELETE_TAG_NAME, async (id) => del(id, TagName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_TRANSFORMATION, async (id) => del(id, Transformation));
ipcServer.answer(IpcChannel.ENTITY_DELETE_TRANSFORMATION_TYPE, async (id) => del(id, TransformationType));
ipcServer.answer(IpcChannel.ENTITY_DELETE_TRANSFORMATION_TYPE_NAME, async (id) => del(id, TransformationTypeName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK_AUTHOR, async (id) => del(id, WorkAuthor));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK_CHARACTER, async (id) => del(id, WorkCharacter));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK_CHARACTER_NAME, async (id) => del(id, WorkCharacterName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK, async (id) => del(id, Work));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK_NAME, async (id) => del(id, WorkName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORK_TAG, async (id) => del(id, WorkTag));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORLD, async (id) => del(id, World));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORLD_NAME, async (id) => del(id, WorldName));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORLD_CHARACTER, async (id) => del(id, WorldCharacter));
ipcServer.answer(IpcChannel.ENTITY_DELETE_WORLD_CHARACTER_NAME, async (id) => del(id, WorldCharacterName));