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-05-12 06:35:00 +00:00
|
|
|
export async function rename(w: Workspace, s: ApiSpec, name: string) {
|
2021-03-17 22:37:32 +00:00
|
|
|
if (isDesign(w)) {
|
2021-05-12 06:35:00 +00:00
|
|
|
await models.apiSpec.update(s, {
|
|
|
|
fileName: name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
} else {
|
2021-05-12 06:35:00 +00:00
|
|
|
await models.workspace.update(w, {
|
|
|
|
name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export async function duplicate(w: Workspace, name: string) {
|
|
|
|
const newWorkspace = await db.duplicate(w, {
|
|
|
|
name,
|
|
|
|
});
|
|
|
|
await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
|
|
|
|
fileName: name,
|
|
|
|
});
|
2021-03-01 21:32:32 +00:00
|
|
|
models.stats.incrementCreatedRequestsForDescendents(newWorkspace);
|
|
|
|
return newWorkspace;
|
|
|
|
}
|