insomnia/packages/insomnia-app/app/models/helpers/workspace-operations.ts
Dimitri Mitropoulos 5f4c19da35
[TypeScript] Phase 1 & 2 (#3370)
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-12 18:35:00 +12:00

29 lines
773 B
TypeScript

import * as models from '../index';
import { database as db } from '../../common/database';
import { isDesign } from './is-model';
import type { Workspace } from '../workspace';
import type { ApiSpec } from '../api-spec';
export async function rename(w: Workspace, s: ApiSpec, name: string) {
if (isDesign(w)) {
await models.apiSpec.update(s, {
fileName: name,
});
} else {
await models.workspace.update(w, {
name,
});
}
}
export async function duplicate(w: Workspace, name: string) {
const newWorkspace = await db.duplicate(w, {
name,
});
await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
fileName: name,
});
models.stats.incrementCreatedRequestsForDescendents(newWorkspace);
return newWorkspace;
}