save mock data
This commit is contained in:
@@ -66,11 +66,7 @@ export class UmbDocumentTypeServerDataSource implements UmbDataSource<any, any,
|
||||
* @memberof UmbDocumentTypeServerDataSource
|
||||
*/
|
||||
async insert(document: DocumentTypeResponseModel) {
|
||||
if (!document.id) {
|
||||
//const error: ProblemDetails = { title: 'Document id is missing' };
|
||||
return Promise.reject();
|
||||
}
|
||||
//const payload = { id: document.id, requestBody: document };
|
||||
if (!document.id) throw new Error('ID is missing');
|
||||
|
||||
let body: string;
|
||||
|
||||
|
||||
@@ -90,26 +90,7 @@ export class UmbDocumentServerDataSource
|
||||
async insert(document: CreateDocumentRequestModel & { id: string }) {
|
||||
if (!document.id) throw new Error('Id is missing');
|
||||
|
||||
let body: string;
|
||||
|
||||
try {
|
||||
body = JSON.stringify(document);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Promise.reject();
|
||||
}
|
||||
//return tryExecuteAndNotify(this.#host, DocumentResource.postDocument(payload));
|
||||
// TODO: use resources when end point is ready:
|
||||
return tryExecuteAndNotify<string>(
|
||||
this.#host,
|
||||
fetch('/umbraco/management/api/v1/document/save', {
|
||||
method: 'POST',
|
||||
body: body,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}) as any
|
||||
);
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.postDocument({ requestBody: document }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,33 +99,10 @@ export class UmbDocumentServerDataSource
|
||||
* @return {*}
|
||||
* @memberof UmbDocumentServerDataSource
|
||||
*/
|
||||
async update(id: string, document: DocumentResponseModel) {
|
||||
if (!document.id) {
|
||||
const error: ProblemDetailsModel = { title: 'Document id is missing' };
|
||||
return { error };
|
||||
}
|
||||
//const payload = { id: document.id, requestBody: document };
|
||||
async update(id: string, document: UpdateDocumentRequestModel) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
|
||||
let body: string;
|
||||
|
||||
try {
|
||||
body = JSON.stringify(document);
|
||||
} catch (error) {
|
||||
const myError: ProblemDetailsModel = { title: 'JSON could not parse' };
|
||||
return { error: myError };
|
||||
}
|
||||
|
||||
// TODO: use resources when end point is ready:
|
||||
return tryExecuteAndNotify<DocumentResponseModel>(
|
||||
this.#host,
|
||||
fetch('/umbraco/management/api/v1/document/save', {
|
||||
method: 'POST',
|
||||
body: body,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}) as any
|
||||
);
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.putDocumentById({ id, requestBody: document }));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
import { rest } from 'msw';
|
||||
import { umbDocumentTypeData } from '../data/document-type.data';
|
||||
import type { DocumentTypeResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
// TODO: add schema
|
||||
export const handlers = [
|
||||
rest.post<DocumentTypeResponseModel>('/umbraco/management/api/v1/document-type/:id', (req, res, ctx) => {
|
||||
const data = req.body;
|
||||
rest.post(umbracoPath(`/document-type`), async (req, res, ctx) => {
|
||||
const data = await req.json();
|
||||
if (!data) return;
|
||||
|
||||
umbDocumentTypeData.insert(data);
|
||||
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.put(umbracoPath(`/document-type/:id`), async (req, res, ctx) => {
|
||||
const data = await req.json();
|
||||
if (!data) return;
|
||||
|
||||
const saved = umbDocumentTypeData.save(data);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { rest } from 'msw';
|
||||
import { umbDocumentData } from '../data/document.data';
|
||||
import type { DocumentResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
// TODO: add schema
|
||||
@@ -35,7 +34,16 @@ export const handlers = [
|
||||
return res(ctx.status(200), ctx.json(items));
|
||||
}),
|
||||
|
||||
rest.post<DocumentResponseModel[]>('/umbraco/management/api/v1/document/:id', async (req, res, ctx) => {
|
||||
rest.post(umbracoPath(`/document`), async (req, res, ctx) => {
|
||||
const data = await req.json();
|
||||
if (!data) return;
|
||||
|
||||
umbDocumentData.insert(data);
|
||||
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.put(umbracoPath(`/document/:id`), async (req, res, ctx) => {
|
||||
const data = await req.json();
|
||||
if (!data) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user