2021-03-01 21:32:32 +00:00
|
|
|
// @flow
|
|
|
|
import * as models from '../index';
|
|
|
|
import * as db from '../../common/database';
|
|
|
|
|
2021-03-17 22:37:32 +00:00
|
|
|
import { isDesign } from './is-model';
|
2021-03-01 21:32:32 +00:00
|
|
|
import type { Workspace } from '../workspace';
|
|
|
|
import type { ApiSpec } from '../api-spec';
|
|
|
|
|
|
|
|
export async function rename(w: Workspace, s: ApiSpec, name: string): Promise<void> {
|
2021-03-17 22:37:32 +00:00
|
|
|
if (isDesign(w)) {
|
2021-03-01 21:32:32 +00:00
|
|
|
await models.apiSpec.update(s, { fileName: name });
|
|
|
|
} else {
|
|
|
|
await models.workspace.update(w, { name });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function duplicate(w: Workspace, name: string): Promise<Workspace> {
|
|
|
|
const newWorkspace = await db.duplicate(w, { name });
|
|
|
|
await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, { fileName: name });
|
|
|
|
models.stats.incrementCreatedRequestsForDescendents(newWorkspace);
|
|
|
|
|
|
|
|
return newWorkspace;
|
|
|
|
}
|