Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to create default content #4

Open
nikolajlauridsen opened this issue Jun 24, 2022 · 2 comments
Open

Make it easier to create default content #4

nikolajlauridsen opened this issue Jun 24, 2022 · 2 comments

Comments

@nikolajlauridsen
Copy link
Contributor

In many cases, all you need for your test is a completely empty content, with some name.

Currently this is a bit of pain to do:

Create doctype:

const rootDocType = new DocumentTypeBuilder()
      .withName(rootDocTypeName)
      .withAllowAsRoot(true)
      .build()
const createdRootDocType = await umbracoApi.documentTypes.save(rootDocType);

Then create content:

const rootContentNode = new ContentBuilder()
      .withContentTypeAlias(createdRootDocType.alias)
      .withAction("saveNew")
      .addVariant()
        .withName(firstRootNodeName)
        .withSave(true)
      .done()
      .build();
const savedRootNode = await umbracoApi.content.save(rootContentNode);

This seems like a lot of code for empty content which you mostly need, instead I propose we use some helper methods like CreateBasicContentType, so it could look something like this:

// Create doctype
const rootDocType = new DocumentTypeBuilder().CreateBasicContentType("MyBasicContentType");
const createdRootDocType = await umbracoApi.documentTypes.save(rootDocType);

// Create content
const rootContentNode = new ContentBuilder().CreateBasicContent("MyBasicContent", createdRootDocType.alias);
const savedRootNode = await umbracoApi.content.save(rootContentNode);
@emma-hq
Copy link
Contributor

emma-hq commented Oct 22, 2022

Am I right in thinking this is already done now? I was going to have a go but seems like ContentApiHelper.ts covers the task

@Zeegaan
Copy link
Member

Zeegaan commented Oct 24, 2022

@emma-hq It's not done yet, this is basically we want methods in the DocumentTypeBuilder & ContentBuilder😄
So we would be able to call const rootDocType = new DocumentTypeBuilder().CreateBasicContentType("MyBasicContentType"); To maybe create a content type with a text-string property named Title & a text area property named Body.
This way contributors wouldn't even need to know how the builder pattern worked, to create a default document type, hope that makes sense 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants