update folder mocks and handlers to new endpoints
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import { UmbFileSystemMockDbBase } from './file-system-base.js';
|
import { UmbFileSystemMockDbBase } from './file-system-base.js';
|
||||||
import { CreatePathFolderRequestModel, PathFolderModelBaseModel } from '@umbraco-cms/backoffice/backend-api';
|
import {
|
||||||
|
FileSystemCreateRequestModelBaseModel,
|
||||||
|
FileSystemResponseModelBaseModel,
|
||||||
|
} from '@umbraco-cms/backoffice/backend-api';
|
||||||
|
|
||||||
export class UmbMockFileSystemFolderManager<
|
export class UmbMockFileSystemFolderManager<
|
||||||
MockItemType extends PathFolderModelBaseModel & { path: string; isFolder: boolean },
|
MockItemType extends FileSystemResponseModelBaseModel & { isFolder: boolean },
|
||||||
> {
|
> {
|
||||||
#db: UmbFileSystemMockDbBase<MockItemType>;
|
#db: UmbFileSystemMockDbBase<MockItemType>;
|
||||||
|
|
||||||
@@ -10,17 +13,21 @@ export class UmbMockFileSystemFolderManager<
|
|||||||
this.#db = db;
|
this.#db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
create(request: CreatePathFolderRequestModel) {
|
create(request: FileSystemCreateRequestModelBaseModel) {
|
||||||
const newFolder: MockItemType = {
|
const path = request.parentPath ? `${request.parentPath}/${request.name}` : request.name;
|
||||||
path: request.parentPath ? `${request.parentPath}/${request.name}` : request.name,
|
|
||||||
parenPath: request.parentPath || null,
|
const newFolder = {
|
||||||
|
path,
|
||||||
|
parent: request.parentPath ? { path: request.parentPath } : null,
|
||||||
name: request.name,
|
name: request.name,
|
||||||
hasChildren: false,
|
hasChildren: false,
|
||||||
isFolder: true,
|
isFolder: true,
|
||||||
content: '',
|
content: '',
|
||||||
};
|
} as unknown as MockItemType;
|
||||||
|
|
||||||
this.#db.create(newFolder);
|
this.#db.create(newFolder);
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(path: string) {
|
read(path: string) {
|
||||||
@@ -39,10 +46,11 @@ export class UmbMockFileSystemFolderManager<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#defaultReadMapper = (item: MockItemType): PathFolderModelBaseModel & { path: string } => {
|
#defaultReadMapper = (item: MockItemType): FileSystemResponseModelBaseModel => {
|
||||||
return {
|
return {
|
||||||
name: item.name,
|
|
||||||
path: item.path,
|
path: item.path,
|
||||||
|
name: item.name,
|
||||||
|
parent: item.parent,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const detailHandlers = [
|
|||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
const path = umbPartialViewMockDB.file.create(requestBody);
|
const path = umbPartialViewMockDB.file.create(requestBody);
|
||||||
return res(
|
return res(
|
||||||
ctx.status(200),
|
ctx.status(201),
|
||||||
ctx.set({
|
ctx.set({
|
||||||
Location: path,
|
Location: path,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,26 +1,32 @@
|
|||||||
const { rest } = window.MockServiceWorker;
|
const { rest } = window.MockServiceWorker;
|
||||||
import { umbPartialViewMockDB } from '../../data/partial-view/partial-view.db.js';
|
import { umbPartialViewMockDB } from '../../data/partial-view/partial-view.db.js';
|
||||||
import { UMB_SLUG } from './slug.js';
|
import { UMB_SLUG } from './slug.js';
|
||||||
import { CreatePathFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
import { CreatePartialViewFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
||||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||||
|
|
||||||
export const folderHandlers = [
|
export const folderHandlers = [
|
||||||
rest.get(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
||||||
const path = req.url.searchParams.get('path');
|
const requestBody = (await req.json()) as CreatePartialViewFolderRequestModel;
|
||||||
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
|
const path = umbPartialViewMockDB.folder.create(requestBody);
|
||||||
|
|
||||||
|
return res(
|
||||||
|
ctx.status(201),
|
||||||
|
ctx.set({
|
||||||
|
Location: path,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
|
||||||
|
rest.get(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
|
const path = req.params.path as string;
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
const response = umbPartialViewMockDB.folder.read(path);
|
const response = umbPartialViewMockDB.folder.read(path);
|
||||||
return res(ctx.status(200), ctx.json(response));
|
return res(ctx.status(200), ctx.json(response));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
rest.delete(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
const requestBody = (await req.json()) as CreatePathFolderRequestModel;
|
const path = req.params.path as string;
|
||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
|
||||||
umbPartialViewMockDB.folder.create(requestBody);
|
|
||||||
return res(ctx.status(200));
|
|
||||||
}),
|
|
||||||
|
|
||||||
rest.delete(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
|
||||||
const path = req.url.searchParams.get('path');
|
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
umbPartialViewMockDB.folder.delete(path);
|
umbPartialViewMockDB.folder.delete(path);
|
||||||
return res(ctx.status(200));
|
return res(ctx.status(200));
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const detailHandlers: RestHandler<MockedRequest<DefaultBodyType>>[] = [
|
|||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
const path = umbPartialViewMockDB.file.create(requestBody);
|
const path = umbPartialViewMockDB.file.create(requestBody);
|
||||||
return res(
|
return res(
|
||||||
ctx.status(200),
|
ctx.status(201),
|
||||||
ctx.set({
|
ctx.set({
|
||||||
Location: path,
|
Location: path,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const detailHandlers = [
|
|||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
const path = umbScriptMockDb.file.create(requestBody);
|
const path = umbScriptMockDb.file.create(requestBody);
|
||||||
return res(
|
return res(
|
||||||
ctx.status(200),
|
ctx.status(201),
|
||||||
ctx.set({
|
ctx.set({
|
||||||
Location: path,
|
Location: path,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,26 +1,32 @@
|
|||||||
const { rest } = window.MockServiceWorker;
|
const { rest } = window.MockServiceWorker;
|
||||||
import { umbScriptMockDb } from '../../data/script/script.db.js';
|
import { umbScriptMockDb } from '../../data/script/script.db.js';
|
||||||
import { UMB_SLUG } from './slug.js';
|
import { UMB_SLUG } from './slug.js';
|
||||||
import { CreatePathFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
import { CreateScriptFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
||||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||||
|
|
||||||
export const folderHandlers = [
|
export const folderHandlers = [
|
||||||
rest.get(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
||||||
const path = req.url.searchParams.get('path');
|
const requestBody = (await req.json()) as CreateScriptFolderRequestModel;
|
||||||
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
|
const path = umbScriptMockDb.folder.create(requestBody);
|
||||||
|
|
||||||
|
return res(
|
||||||
|
ctx.status(201),
|
||||||
|
ctx.set({
|
||||||
|
Location: path,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
|
||||||
|
rest.get(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
|
const path = req.params.path as string;
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
const response = umbScriptMockDb.folder.read(path);
|
const response = umbScriptMockDb.folder.read(path);
|
||||||
return res(ctx.status(200), ctx.json(response));
|
return res(ctx.status(200), ctx.json(response));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
rest.delete(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
const requestBody = (await req.json()) as CreatePathFolderRequestModel;
|
const path = req.params.path as string;
|
||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
|
||||||
umbScriptMockDb.folder.create(requestBody);
|
|
||||||
return res(ctx.status(200));
|
|
||||||
}),
|
|
||||||
|
|
||||||
rest.delete(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
|
||||||
const path = req.url.searchParams.get('path');
|
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
umbScriptMockDb.folder.delete(path);
|
umbScriptMockDb.folder.delete(path);
|
||||||
return res(ctx.status(200));
|
return res(ctx.status(200));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const detailHandlers = [
|
|||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
const path = umbStylesheetData.file.create(requestBody);
|
const path = umbStylesheetData.file.create(requestBody);
|
||||||
return res(
|
return res(
|
||||||
ctx.status(200),
|
ctx.status(201),
|
||||||
ctx.set({
|
ctx.set({
|
||||||
Location: path,
|
Location: path,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
const { rest } = window.MockServiceWorker;
|
const { rest } = window.MockServiceWorker;
|
||||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||||
import { UMB_SLUG } from './slug.js';
|
import { UMB_SLUG } from './slug.js';
|
||||||
import { CreatePathFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
import { CreateStylesheetFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
||||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||||
|
|
||||||
export const folderHandlers = [
|
export const folderHandlers = [
|
||||||
rest.get(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
||||||
const path = req.url.searchParams.get('path');
|
const requestBody = (await req.json()) as CreateStylesheetFolderRequestModel;
|
||||||
|
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||||
|
|
||||||
|
const path = umbStylesheetData.folder.create(requestBody);
|
||||||
|
|
||||||
|
return res(
|
||||||
|
ctx.status(201),
|
||||||
|
ctx.set({
|
||||||
|
Location: path,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
|
||||||
|
rest.get(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
|
const path = req.params.path as string;
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
const response = umbStylesheetData.folder.read(path);
|
const response = umbStylesheetData.folder.read(path);
|
||||||
return res(ctx.status(200), ctx.json(response));
|
return res(ctx.status(200), ctx.json(response));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
rest.delete(umbracoPath(`${UMB_SLUG}/folder/:path`), (req, res, ctx) => {
|
||||||
const requestBody = (await req.json()) as CreatePathFolderRequestModel;
|
const path = req.params.path as string;
|
||||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
|
||||||
umbStylesheetData.folder.create(requestBody);
|
|
||||||
return res(ctx.status(200));
|
|
||||||
}),
|
|
||||||
|
|
||||||
rest.delete(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
|
||||||
const path = req.url.searchParams.get('path');
|
|
||||||
if (!path) return res(ctx.status(400));
|
if (!path) return res(ctx.status(400));
|
||||||
umbStylesheetData.folder.delete(path);
|
umbStylesheetData.folder.delete(path);
|
||||||
return res(ctx.status(200));
|
return res(ctx.status(200));
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class UmbScriptFolderServerDataSource implements UmbFolderDataSource {
|
|||||||
|
|
||||||
const { data, error } = await tryExecuteAndNotify(
|
const { data, error } = await tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
ScriptResource.getScriptFolder({
|
ScriptResource.getScriptFolderByPath({
|
||||||
path,
|
path,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -44,7 +44,7 @@ export class UmbScriptFolderServerDataSource implements UmbFolderDataSource {
|
|||||||
if (data) {
|
if (data) {
|
||||||
const mappedData = {
|
const mappedData = {
|
||||||
unique: this.#serverPathUniqueSerializer.toUnique(data.path),
|
unique: this.#serverPathUniqueSerializer.toUnique(data.path),
|
||||||
parentUnique: this.#serverPathUniqueSerializer.toParentUnique(data.path),
|
parentUnique: data.parent ? this.#serverPathUniqueSerializer.toUnique(data.parent.path) : null,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,17 +71,15 @@ export class UmbScriptFolderServerDataSource implements UmbFolderDataSource {
|
|||||||
name: args.name,
|
name: args.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error } = await tryExecuteAndNotify(
|
const { data, error } = await tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
ScriptResource.postScriptFolder({
|
ScriptResource.postScriptFolder({
|
||||||
requestBody,
|
requestBody,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!error) {
|
if (data) {
|
||||||
/* TODO: investigate why we don't get the location header as part of data,
|
const newPath = this.#serverPathUniqueSerializer.toUnique(data);
|
||||||
so we don't have to construct the path ourselves */
|
|
||||||
const newPath = parentPath ? `${parentPath}/${args.name}` : args.name;
|
|
||||||
return this.read(newPath);
|
return this.read(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +99,7 @@ export class UmbScriptFolderServerDataSource implements UmbFolderDataSource {
|
|||||||
|
|
||||||
return tryExecuteAndNotify(
|
return tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
ScriptResource.deleteScriptFolder({
|
ScriptResource.deleteScriptFolderByPath({
|
||||||
path,
|
path,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class UmbStylesheetFolderServerDataSource implements UmbFolderDataSource
|
|||||||
|
|
||||||
const { data, error } = await tryExecuteAndNotify(
|
const { data, error } = await tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
StylesheetResource.getStylesheetFolder({
|
StylesheetResource.getStylesheetFolderByPath({
|
||||||
path,
|
path,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -44,7 +44,7 @@ export class UmbStylesheetFolderServerDataSource implements UmbFolderDataSource
|
|||||||
if (data) {
|
if (data) {
|
||||||
const mappedData = {
|
const mappedData = {
|
||||||
unique: this.#serverPathUniqueSerializer.toUnique(data.path),
|
unique: this.#serverPathUniqueSerializer.toUnique(data.path),
|
||||||
parentUnique: this.#serverPathUniqueSerializer.toParentUnique(data.path),
|
parentUnique: data.parent ? this.#serverPathUniqueSerializer.toUnique(data.parent.path) : null,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,17 +71,15 @@ export class UmbStylesheetFolderServerDataSource implements UmbFolderDataSource
|
|||||||
name: args.name,
|
name: args.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error } = await tryExecuteAndNotify(
|
const { data, error } = await tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
StylesheetResource.postStylesheetFolder({
|
StylesheetResource.postStylesheetFolder({
|
||||||
requestBody,
|
requestBody,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!error) {
|
if (data) {
|
||||||
/* TODO: investigate why we don't get the location header as part of data,
|
const newPath = this.#serverPathUniqueSerializer.toUnique(data);
|
||||||
so we don't have to construct the path ourselves */
|
|
||||||
const newPath = parentPath ? `${parentPath}/${args.name}` : args.name;
|
|
||||||
return this.read(newPath);
|
return this.read(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +99,7 @@ export class UmbStylesheetFolderServerDataSource implements UmbFolderDataSource
|
|||||||
|
|
||||||
return tryExecuteAndNotify(
|
return tryExecuteAndNotify(
|
||||||
this.#host,
|
this.#host,
|
||||||
StylesheetResource.deleteStylesheetFolder({
|
StylesheetResource.deleteStylesheetFolderByPath({
|
||||||
path,
|
path,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user