relation mocks
This commit is contained in:
@@ -1,65 +1,66 @@
|
||||
import { UmbEntityData } from '../entity.data.js';
|
||||
import type { RelationResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export const data: Array<RelationResponseModel> = [
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'TEST Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '2',
|
||||
childName: 'Child 1',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 1',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '3',
|
||||
childName: 'Child 2',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 2',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '4',
|
||||
childName: 'Child 3',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 3',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '5',
|
||||
childName: 'Child 4',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 4',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '6',
|
||||
childName: 'Child 5',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 5',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '7',
|
||||
childName: 'Child 6',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 6',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '8',
|
||||
childName: 'Child 7',
|
||||
createDate: '2021-01-01',
|
||||
comment: 'Comment 7',
|
||||
},
|
||||
{
|
||||
parentId: '1',
|
||||
parentName: 'Parent 1',
|
||||
parentId: 'e0d39ff5-71d8-453f-b682-9d8d31ee5e06',
|
||||
parentName: 'Relate Document On Copy',
|
||||
childId: '9',
|
||||
childName: 'Child 8',
|
||||
createDate: '2021-01-01',
|
||||
@@ -74,6 +75,11 @@ class UmbRelationData extends UmbEntityData<RelationResponseModel> {
|
||||
constructor() {
|
||||
super(data);
|
||||
}
|
||||
|
||||
getRelationsByParentId(id: string) {
|
||||
const test = this.data.filter((relation) => relation.parentId === id);
|
||||
return { items: test, total: test.length };
|
||||
}
|
||||
}
|
||||
|
||||
export const umbRelationData = new UmbRelationData();
|
||||
|
||||
@@ -1,36 +1,15 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbRelationTypeData } from '../../../data/relations/relation-type.data.js';
|
||||
import { umbRelationData } from '../../../data/relations/relation.data.js';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const handlers = [
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/root`), (req, res, ctx) => {
|
||||
const rootItems = umbRelationTypeData.getTreeRoot();
|
||||
const response = {
|
||||
total: rootItems.length,
|
||||
items: rootItems,
|
||||
};
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
rest.get(umbracoPath(`${UMB_SLUG}/type/:id`), (req, res, ctx) => {
|
||||
const id = req.params.id as string;
|
||||
if (!id) return;
|
||||
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/children`), (req, res, ctx) => {
|
||||
const parentId = req.url.searchParams.get('parentId');
|
||||
if (!parentId) return;
|
||||
|
||||
const children = umbRelationTypeData.getTreeItemChildren(parentId);
|
||||
|
||||
const response = {
|
||||
total: children.length,
|
||||
items: children,
|
||||
};
|
||||
const response = umbRelationData.getRelationsByParentId(id);
|
||||
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/item`), (req, res, ctx) => {
|
||||
const ids = req.url.searchParams.getAll('id');
|
||||
if (!ids) return;
|
||||
const items = umbRelationTypeData.getTreeItem(ids);
|
||||
return res(ctx.status(200), ctx.json(items));
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user