2021-05-12 06:35:00 +00:00
|
|
|
import { database as db } from '../../common/database';
|
2021-03-01 21:32:32 +00:00
|
|
|
import type { ApiSpec } from '../api-spec';
|
2021-07-22 23:04:56 +00:00
|
|
|
import * as models from '../index';
|
|
|
|
import { isDesign, Workspace } from '../workspace';
|
2021-03-01 21:32:32 +00:00
|
|
|
|
2021-10-07 12:38:11 +00:00
|
|
|
export async function rename(workspace: Workspace, apiSpec: ApiSpec, name: string) {
|
|
|
|
if (isDesign(workspace)) {
|
|
|
|
await models.apiSpec.update(apiSpec, {
|
2021-05-12 06:35:00 +00:00
|
|
|
fileName: name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
} else {
|
2021-10-07 12:38:11 +00:00
|
|
|
await models.workspace.update(workspace, {
|
2021-05-12 06:35:00 +00:00
|
|
|
name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 12:38:11 +00:00
|
|
|
export async function duplicate(
|
|
|
|
workspace: Workspace,
|
|
|
|
{ name, parentId }: Pick<Workspace, 'name' | 'parentId'>,
|
|
|
|
) {
|
|
|
|
const newWorkspace = await db.duplicate(workspace, {
|
2021-05-12 06:35:00 +00:00
|
|
|
name,
|
2021-07-28 21:49:02 +00:00
|
|
|
parentId,
|
2021-05-12 06:35:00 +00:00
|
|
|
});
|
|
|
|
await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
|
|
|
|
fileName: name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
models.stats.incrementCreatedRequestsForDescendents(newWorkspace);
|
|
|
|
return newWorkspace;
|
|
|
|
}
|