mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
5f4c19da35
Co-authored-by: Opender Singh <opender.singh@konghq.com>
29 lines
773 B
TypeScript
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;
|
|
}
|