feat(export-import): add yaml export/import with id upsert for credentials, snippets, and scenarios
- all entities export a kind field (credential/snippet/scenario) for safe type checking on import - import upserts by id: overwrites if id exists, creates with explicit id otherwise - scenario export now includes id and step ids; import deletes old steps before recreating - add GET /:id/export and POST /import endpoints to credential and snippet controllers - add UuidBadge ui component: shortens uuid to first+last 4 hex chars, tooltip, clipboard copy with animated ClipboardCheck icon pop - apply UuidBadge across all entity id display sites (detail pages, card footers, table columns) - add export/import buttons to CredentialsPage, SnippetsPage, CredentialDetailPage, SnippetDetailPage
This commit is contained in:
@@ -4,6 +4,7 @@ import { Repository } from "typeorm";
|
||||
import { CredentialEntity } from "./credential.entity";
|
||||
import { CreateCredentialDto } from "./dto/create-credential.dto";
|
||||
import { UpdateCredentialDto } from "./dto/update-credential.dto";
|
||||
import { CredentialExportDto } from "./dto/credential-export.dto";
|
||||
import {
|
||||
PaginationQueryDto,
|
||||
PaginatedResult,
|
||||
@@ -37,20 +38,40 @@ export class CredentialService {
|
||||
return { data, total, page, limit };
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<CredentialEntity> {
|
||||
async findOne(id: string): Promise<CredentialEntity> {
|
||||
const credential = await this.repo.findOneBy({ id });
|
||||
if (!credential) throw new NotFoundException(`Credential ${id} not found`);
|
||||
return credential;
|
||||
}
|
||||
|
||||
async update(id: number, dto: UpdateCredentialDto): Promise<CredentialEntity> {
|
||||
async update(id: string, dto: UpdateCredentialDto): Promise<CredentialEntity> {
|
||||
const credential = await this.findOne(id);
|
||||
Object.assign(credential, dto);
|
||||
return this.repo.save(credential);
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
async remove(id: string): Promise<void> {
|
||||
await this.findOne(id);
|
||||
await this.repo.delete(id);
|
||||
}
|
||||
|
||||
exportCredential(credential: CredentialEntity): CredentialExportDto {
|
||||
return { kind: "credential", id: credential.id, name: credential.name, data: credential.data };
|
||||
}
|
||||
|
||||
async importCredential(dto: CredentialExportDto): Promise<CredentialEntity> {
|
||||
if (dto.id) {
|
||||
const existing = await this.repo.findOneBy({ id: dto.id });
|
||||
if (existing) {
|
||||
Object.assign(existing, { name: dto.name, data: dto.data ?? null });
|
||||
return this.repo.save(existing);
|
||||
}
|
||||
return this.repo.save(
|
||||
this.repo.create({ id: dto.id, name: dto.name, data: dto.data ?? null }),
|
||||
);
|
||||
}
|
||||
return this.repo.save(
|
||||
this.repo.create({ name: dto.name, data: dto.data ?? null }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user